1. 程式人生 > >rabbitmq連線amqp.rabbit.connection.CachingConnectionFactory]

rabbitmq連線amqp.rabbit.connection.CachingConnectionFactory]

在windows伺服器裝了一個rabbitmq訊息中介軟體,在專案中進行遠端連線時,當一段時間沒有使用,專案中一直出現如下異常,一旦你進行訊息傳送又不能夠正常工作,這個異常不影響使用,但是具體存在什麼隱患我也不清楚:

[SimpleAsyncTaskExecutor-9] WARN  [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer] - Consumer raised exception, processing can restart if the connection factory supports it. Exception summary: org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection timed out: connect

[SimpleAsyncTaskExecutor-9] INFO  [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer] - Restarting Consumer: tags=[[]], channel=null, acknowledgeMode=AUTO local queue size=0

ERROR [org.springframework.amqp.rabbit.connection.CachingConnectionFactory] - Channel shutdown: connection error; protocol method: #method<connection.close>(reply-code=320, reply-text=CONNECTION_FORCED - broker forced connection closure with reason 'shutdown', class-id=0, method-id=0)

ERROR [org.springframework.amqp.rabbit.connection.CachingConnectionFactory] - Channel shutdown: connection error; protocol method: #method<connection.close>(reply-code=320, reply-text=CONNECTION_FORCED - broker forced connection closure with reason 'shutdown', class-id=0, method-id=0)

[SimpleAsyncTaskExecutor-10] WARN  [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer] - Consumer raised exception, processing can restart if the connection factory supports it
com.rabbitmq.client.ShutdownSignalException: connection error; protocol method: #method<connection.close>(reply-code=320, reply-text=CONNECTION_FORCED - broker forced connection closure with reason 'shutdown', class-id=0, method-id=0)
    at com.rabbitmq.client.impl.AMQConnection.startShutdown(AMQConnection.java:715)
    at com.rabbitmq.client.impl.AMQConnection.shutdown(AMQConnection.java:705)
    at com.rabbitmq.client.impl.AMQConnection.handleConnectionClose(AMQConnection.java:660)
    at com.rabbitmq.client.impl.AMQConnection.processControlCommand(AMQConnection.java:615)
    at com.rabbitmq.client.impl.AMQConnection$1.processAsync(AMQConnection.java:107)
    at com.rabbitmq.client.impl.AMQChannel.handleCompleteInboundCommand(AMQChannel.java:144)
    at com.rabbitmq.client.impl.AMQChannel.handleFrame(AMQChannel.java:91)
    at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:540)
    at java.lang.Thread.run(Thread.java:745)

在遠端連線時出現此問題,查詢網上資料說rabbitmq在單機情況下都是長連線,我這也並沒有使用叢集,考慮會不會是新建使用者並授權後,但是遠端連線有限制一定時間後對於不活動的客戶端連線會自動斷開連線,抱著試試的心態,找到rabbitmq.config,設定{loopback_users, ["username"]} 引號內是使用者名稱,如果是對所有使用者就置空就行

 %% The default "guest" user is only permitted to access the server
   %% via a loopback interface (e.g. localhost).
   %% {loopback_users, [<<"guest">>]},
   %%
   %% Uncomment the following line if you want to allow access to the
   %% guest user from anywhere on the network.
   %% {loopback_users, []},  --注意下面沒有元素是逗號不要

然後通過命令stop停止rabbitmq伺服器並install重灌服務,再start啟動,客戶端再沒有出現這個異常問題了,特此記錄一下備忘