2016-10-10 123 views
0

我的消費約一週工作正常,那麼消費者線程死亡,記錄了以下錯誤:驗證失敗彈簧AMQP超時

It seems the Authentication failure is caused by BufferedInputStream.read timeout, and I want to know if there is a way to treat the Authentication failure as a non-fatal and do not kill the consumer thread. and I think the timeout issue is just caused by network issue not the Authentication failure, since this consumer already worked for one week.

org.springframework.amqp.rabbit.listener.exception.FatalListenerStartupException: Authentication failure 
at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.start(BlockingQueueConsumer.java:460) 
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1171) 
at java.lang.Thread.run(Thread.java:745) 
Caused by: org.springframework.amqp.AmqpAuthenticationException: com.rabbitmq.client.PossibleAuthenticationFailureException: Possibly caused by authentication failure 
at org.springframework.amqp.rabbit.support.RabbitExceptionTranslator.convertRabbitAccessException(RabbitExceptionTranslator.java:61) 
at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:296) 
at org.springframework.amqp.rabbit.connection.CachingConnectionFactory.createConnection(CachingConnectionFactory.java:524) 
at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils$1.createConnection(ConnectionFactoryUtils.java:85) 
at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils.doGetTransactionalResourceHolder(ConnectionFactoryUtils.java:135) 
at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils.getTransactionalResourceHolder(ConnectionFactoryUtils.java:71) 
at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.start(BlockingQueueConsumer.java:456) 
... 2 more 
Caused by: com.rabbitmq.client.PossibleAuthenticationFailureException: Possibly caused by authentication failure 
at com.rabbitmq.client.impl.AMQConnection.start(AMQConnection.java:341) 
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:824) 
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:736) 
at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:283) 
... 7 more 
Caused by: com.rabbitmq.client.ShutdownSignalException: connection error at com.rabbitmq.utility.ValueOrException.getValue(ValueOrExcept‌​ion.java:66) at com.rabbitmq.utility.BlockingValueOrException.uninterruptibl‌​eGetValue(BlockingVa‌​lueOrException.java:‌​36) at com.rabbitmq.client.impl.AMQChannel$BlockingRpcContinuation.‌​getReply(AMQChannel.‌​java:366) at com.rabbitmq.client.impl.AMQChannel.privateRpc(AMQChannel.ja‌​va:233) at com.rabbitmq.client.impl.AMQChannel.rpc(AMQChannel.java:211) at com.rabbitmq.client.impl.AMQConnection.start(AMQConnection.j‌​ava:326) 
+0

產生的原因:在com.rabbitmq.utility.BlockingValueOrException.uninterruptibleGetValue(BlockingValueOrException.java在com.rabbitmq.utility.ValueOrException.getValue(ValueOrException.java:66) 連接錯誤 :com.rabbitmq.client.ShutdownSignalException: 36) 在com.rabbitmq.client.impl.AMQChannel $ BlockingRpcContinuation.getReply(AMQChannel.java:366) 在com.rabbitmq.client.impl.AMQChannel.privateRpc(AMQChannel.java:233) 在com.rabbitmq。 client.impl.AMQChannel.rpc(AMQChannel.java:211) at com.rabbitmq.client.impl.AMQConnection.start(AMQConnection.java:326) –

+0

導致:java.net.SocketException:連接超時 在java .net.SocketInputStream.socketRead0(本地方法) at java.net.SocketInputStream.read(SocketInputStream.java:152) at java.net.SocketInputStream.read(SocketInputStream.java:122) at java.io.BufferedInputStream.fill(BufferedInputStream.java:235 ) at java.io.BufferedInputStream.read(BufferedInputStream.java:254) at java.io.DataInputStream.readUnsignedByte(DataInputStream.java:288) at com.rabbitmq.client.impl.Frame.readFrom(Frame.java :94) at com.rabbitmq.client.impl.SocketFrameHandler.readFrame(SocketFrameHandler.java:138) –

+0

第一次問這裏的問題,並總是得到您的文章似乎包含沒有正確格式化爲代碼的代碼。請使用代碼工具欄按鈕或CTRL + K鍵盤快捷鍵將所有代碼縮進4個空格。要獲得更多編輯幫助,請單擊[?]工具欄圖標。所以我添加一些意見來發布我的問題 –

回答

0

目標代碼如下:

} catch (ShutdownSignalException e) { 
... 
    throw new PossibleAuthenticationFailureException(e); 
} 

所以,連接的問題的確並非必須與認證有關。

還有ShutdownSignalExceptionConnection timed out原因。

因此,您應該嘗試增加連接超時,默認爲60000

但是,由於我們無法連接,所以代理上的資源可能存在一些問題。

我們不能將這種錯誤(ShutdownSignalException)視爲非致命的,因爲您的問題恰好發生在start()上。

EDIT

在致命故障的情況下,容器發射ListenerContainerConsumerFailedEventhttp://docs.spring.io/spring-amqp/reference/html/_reference.html#consumer-events。您可以處理它並故意重新啓動容器。

+0

但這個錯誤沒有發生在我啓動應用程序,它發生在運行一個星期在線的項目,它在錯誤之前正常工作。以及我應該設置什麼樣的超時時間?回覆,接收或連接超時?如果我設置爲-1,它永遠不會超時,對嗎?並且超時將影響java.io.BufferedInputStream.read方法?因爲我看到錯誤是由它引起的。 –

+0

連接超時,因爲您無法連接到代理。 BufferedInputStream.read只是低層的連接等待來自套接字服務器的回覆。正如我所說的:看起來經紀人存在資源泄漏。所以,一週之後就無法爲你打開新的連接。也許你不會關閉舊的連接...或者你的目標消費者被永久阻止,Listener Container被迫啓動新的和新的連接以趕上隊列中的消息... –

+0

感謝您的回覆!所以增加超時並不是解決我的問題的方法,我應該找到mq服務器泄露資源的原因。和我只使用sping amqp消耗來連接到該服務器,我應該關閉我的代碼中的一些連接?我有一個消費者服務器連接到該服務器在不同的虛擬主機,它工作正常,並沒有encouter超時問題。 –