Spring bus Rabbit amqp客户端长时间闲置连接

时间:2018-05-22 17:37:39

标签: spring-boot rabbitmq spring-amqp spring-cloud-bus

**Versions**
RabbitMQ 3.6.14. (using docker image rabbitmq:3.6.14-management-alpine)

Java 1.8

spring-cloud-starter-bus-amqp => 1.3.1.RELEASE


 Spring boot parent => 1.5.9.RELEASE

我使用amqp mvn设置了带弹簧启动服务的rabbitmq  框架,以便我可以远程刷新配置。事情很好  最初然后连接下降。

错误堆栈 还链接:https://docs.google.com/document/d/1Hk3DnA7dMIMevjvoew2Shy5OQsShizrPKRys_U2lghM/edit?usp=sharing

2018-05-22 17:10:49.647 ERROR 9 --- [.X.X.228:5671] c.r.c.impl.ForgivingExceptionHandler     : An unexpected connection driver error occured

com.rabbitmq.client.MissedHeartbeatException: Heartbeat missing with heartbeat = 10 seconds     at com.rabbitmq.client.impl.AMQConnection.handleSocketTimeout(AMQConnection.java:723)   at com.rabbitmq.client.impl.AMQConnection.readFrame(AMQConnection.java:642)     at com.rabbitmq.client.impl.AMQConnection.access$300(AMQConnection.java:47)     at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:572)  at java.lang.Thread.run(Thread.java:745)

2018-05-22 17:10:49.652 ERROR 9 --- [.X.X.228:5671] o.s.a.r.c.CachingConnectionFactory       : Channel shutdown: connection error 2018-05-22 17:10:49.652 ERROR 9 --- [.X.X.228:5671] o.s.a.r.c.CachingConnectionFactory       : Channel shutdown: connection error 2018-05-22 17:10:50.581  INFO 9 --- [NiW8BAjOWTiVA-1] o.s.a.r.l.SimpleMessageListenerContainer : Restarting Consumer@574b7f4a: tags=[{amq.ctag-m35NYazOB0vmhjJHwayDMg=springCloudBus.anonymous.eV7zCVLlSNiW8BAjOWTiVA}], channel=Cached Rabbit Channel: AMQChannel(amqp://admin@10.X.X.228:5671/,1), conn: Proxy@76ad6715 Shared Rabbit Connection: SimpleConnection@5a1c3cb4 [delegate=amqp://admin@10.X.X.228:5671/, localPort= 43472], acknowledgeMode=AUTO local queue size=0 2018-05-22 17:10:50.609  INFO 9 --- [NiW8BAjOWTiVA-2] o.s.a.r.c.CachingConnectionFactory       : Created new connection: rabbitConnectionFactory#934b52f:1/SimpleConnection@3cd111c6 [delegate=amqp://admin@10.X.X.78:5671/, localPort= 50792] 2018-05-22 17:10:50.613  INFO 9 --- [NiW8BAjOWTiVA-2] o.s.amqp.rabbit.core.RabbitAdmin         : Auto-declaring a non-durable, auto-delete, or exclusive Queue (springCloudBus.anonymous.eV7zCVLlSNiW8BAjOWTiVA) durable:false, auto-delete:true, exclusive:true. It will be redeclared if the broker stops and is restarted while the connection factory is alive, but all messages will be lost. 2018-05-22 17:10:50.617 ERROR 9 --- [0.X.X.78:5671] o.s.a.r.c.CachingConnectionFactory       : Channel shutdown: channel error; protocol method:
#method<channel.close>(reply-code=405, reply-text=RESOURCE_LOCKED - cannot obtain exclusive access to locked queue 'springCloudBus.anonymous.eV7zCVLlSNiW8BAjOWTiVA' in vhost '/', class-id=50, method-id=10) 2018-05-22 17:10:50.619  WARN 9 --- [NiW8BAjOWTiVA-2] o.s.amqp.rabbit.core.RabbitAdmin         : Failed to declare queue: Queue [name=springCloudBus.anonymous.eV7zCVLlSNiW8BAjOWTiVA, durable=false, autoDelete=true, exclusive=true, arguments={}], continuing... com.rabbitmq.client.ShutdownSignalException: channel error; protocol method: #method<channel.close>(reply-code=405, reply-text=RESOURCE_LOCKED - cannot obtain exclusive access to locked queue 'springCloudBus.anonymous.eV7zCVLlSNiW8BAjOWTiVA' in vhost '/', class-id=50, method-id=10) 2018-05-22 17:10:50.621 ERROR 9 --- [0.X.X.78:5671] o.s.a.r.c.CachingConnectionFactory       : Channel shutdown: channel error; protocol method:
#method<channel.close>(reply-code=405, reply-text=RESOURCE_LOCKED - cannot obtain exclusive access to locked queue 'springCloudBus.anonymous.eV7zCVLlSNiW8BAjOWTiVA' in vhost '/', class-id=50, method-id=20) 2018-05-22 17:10:50.623  WARN 9 --- [NiW8BAjOWTiVA-2] o.s.amqp.rabbit.core.RabbitAdmin         : Failed to declare binding: Binding [destination=springCloudBus.anonymous.eV7zCVLlSNiW8BAjOWTiVA, exchange=springCloudBus, routingKey=#], continuing... com.rabbitmq.client.ShutdownSignalException: channel error; protocol method: #method<channel.close>(reply-code=405, reply-text=RESOURCE_LOCKED - cannot obtain exclusive access to locked queue 'springCloudBus.anonymous.eV7zCVLlSNiW8BAjOWTiVA' in vhost '/', class-id=50, method-id=20) 2018-05-22 17:10:50.629 ERROR 9 --- [0.X.X.78:5671] o.s.a.r.c.CachingConnectionFactory       : Channel shutdown: channel error; protocol method:
#method<channel.close>(reply-code=405, reply-text=RESOURCE_LOCKED - cannot obtain exclusive access to locked queue 'springCloudBus.anonymous.eV7zCVLlSNiW8BAjOWTiVA' in vhost '/', class-id=50, method-id=10) 2018-05-22 17:10:50.630  WARN 9 --- [NiW8BAjOWTiVA-2] o.s.a.r.listener.BlockingQueueConsumer   : Failed to declare queue: springCloudBus.anonymous.eV7zCVLlSNiW8BAjOWTiVA 2018-05-22 17:10:50.631  WARN 9 --- [NiW8BAjOWTiVA-2] o.s.a.r.listener.BlockingQueueConsumer   : Queue declaration failed; retries left=3

org.springframework.amqp.rabbit.listener.BlockingQueueConsumer$DeclarationException: Failed to declare queue(s):[springCloudBus.anonymous.eV7zCVLlSNiW8BAjOWTiVA]   at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.attemptPassiveDeclarations(BlockingQueueConsumer.java:672)    at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.start(BlockingQueueConsumer.java:571)     at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1424)     at java.lang.Thread.run(Thread.java:745) Caused by: java.io.IOException: null   at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:105)    at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:101)    at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:123)  at com.rabbitmq.client.impl.ChannelN.queueDeclarePassive(ChannelN.java:992)     at com.rabbitmq.client.impl.ChannelN.queueDeclarePassive(ChannelN.java:50)  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)    at java.lang.reflect.Method.invoke(Method.java:498)     at org.springframework.amqp.rabbit.connection.CachingConnectionFactory$CachedChannelInvocationHandler.invoke(CachingConnectionFactory.java:980)     at com.sun.proxy.$Proxy155.queueDeclarePassive(Unknown Source)  at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.attemptPassiveDeclarations(BlockingQueueConsumer.java:651)    ... 3 common frames omitted Caused by: com.rabbitmq.client.ShutdownSignalException: channel error; protocol method: #method<channel.close>(reply-code=405, reply-text=RESOURCE_LOCKED - cannot obtain exclusive access to locked queue 'springCloudBus.anonymous.eV7zCVLlSNiW8BAjOWTiVA' in vhost '/', class-id=50, method-id=10)   at com.rabbitmq.utility.ValueOrException.getValue(ValueOrException.java:66)     at com.rabbitmq.utility.BlockingValueOrException.uninterruptibleGetValue(BlockingValueOrException.java:32)  at com.rabbitmq.client.impl.AMQChannel$BlockingRpcContinuation.getReply(AMQChannel.java:366)    at com.rabbitmq.client.impl.AMQChannel.privateRpc(AMQChannel.java:229)  at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:117)  ... 12 common frames omitted Caused by: com.rabbitmq.client.ShutdownSignalException: channel error; protocol method: #method<channel.close>(reply-code=405, reply-text=RESOURCE_LOCKED - cannot obtain exclusive access to locked queue 'springCloudBus.anonymous.eV7zCVLlSNiW8BAjOWTiVA' in vhost '/', class-id=50, method-id=10)  at com.rabbitmq.client.impl.ChannelN.asyncShutdown(ChannelN.java:505)   at com.rabbitmq.client.impl.ChannelN.processAsync(ChannelN.java:336)    at com.rabbitmq.client.impl.AMQChannel.handleCompleteInboundCommand(AMQChannel.java:143)    at com.rabbitmq.client.impl.AMQChannel.handleFrame(AMQChannel.java:90)  at com.rabbitmq.client.impl.AMQConnection.readFrame(AMQConnection.java:634)     at com.rabbitmq.client.impl.AMQConnection.access$300(AMQConnection.java:47)     at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:572)  ... 1 common frames omitted

2018-05-22 17:10:55.635  WARN 9 --- [NiW8BAjOWTiVA-2] o.s.a.r.listener.BlockingQueueConsumer   : Failed to declare queue: springCloudBus.anonymous.eV7zCVLlSNiW8BAjOWTiVA 2018-05-22 17:10:55.636  WARN 9 --- [NiW8BAjOWTiVA-2] o.s.a.r.listener.BlockingQueueConsumer   : Queue declaration failed; retries left=2

org.springframework.amqp.rabbit.listener.BlockingQueueConsumer$DeclarationException: Failed to declare queue(s):[springCloudBus.anonymous.eV7zCVLlSNiW8BAjOWTiVA]   at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.attemptPassiveDeclarations(BlockingQueueConsumer.java:672)    at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.start(BlockingQueueConsumer.java:571)     at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1424)     at java.lang.Thread.run(Thread.java:745) Caused by: java.io.IOException: null   at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:105)    at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:101)    at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:123)  at com.rabbitmq.client.impl.ChannelN.queueDeclarePassive(ChannelN.java:992)     at com.rabbitmq.client.impl.ChannelN.queueDeclarePassive(ChannelN.java:50)  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)    at java.lang.reflect.Method.invoke(Method.java:498)     at org.springframework.amqp.rabbit.connection.CachingConnectionFactory$CachedChannelInvocationHandler.invoke(CachingConnectionFactory.java:980)     at com.sun.proxy.$Proxy155.queueDeclarePassive(Unknown Source)  at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.attemptPassiveDeclarations(BlockingQueueConsumer.java:651)    ... 3 common frames omitted Caused by: com.rabbitmq.client.ShutdownSignalException: channel error; protocol method: #method<channel.close>(reply-code=404, reply-text=NOT_FOUND - no queue 'springCloudBus.anonymous.eV7zCVLlSNiW8BAjOWTiVA' in vhost '/', class-id=50, method-id=10)   at com.rabbitmq.utility.ValueOrException.getValue(ValueOrException.java:66)     at com.rabbitmq.utility.BlockingValueOrException.uninterruptibleGetValue(BlockingValueOrException.java:32)  at com.rabbitmq.client.impl.AMQChannel$BlockingRpcContinuation.getReply(AMQChannel.java:366)    at com.rabbitmq.client.impl.AMQChannel.privateRpc(AMQChannel.java:229)  at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:117)  ... 12 common frames omitted Caused by: com.rabbitmq.client.ShutdownSignalException: channel error; protocol method: #method<channel.close>(reply-code=404, reply-text=NOT_FOUND - no queue 'springCloudBus.anonymous.eV7zCVLlSNiW8BAjOWTiVA' in vhost '/', class-id=50, method-id=10)  at com.rabbitmq.client.impl.ChannelN.asyncShutdown(ChannelN.java:505)   at com.rabbitmq.client.impl.ChannelN.processAsync(ChannelN.java:336)    at com.rabbitmq.client.impl.AMQChannel.handleCompleteInboundCommand(AMQChannel.java:143)    at com.rabbitmq.client.impl.AMQChannel.handleFrame(AMQChannel.java:90)  at com.rabbitmq.client.impl.AMQConnection.readFrame(AMQConnection.java:634)     at com.rabbitmq.client.impl.AMQConnection.access$300(AMQConnection.java:47)     at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:572)  ... 1 common frames omitted

2018-05-22 17:11:00.656  WARN 9 --- [NiW8BAjOWTiVA-2] o.s.a.r.listener.BlockingQueueConsumer   : Failed to declare queue: springCloudBus.anonymous.eV7zCVLlSNiW8BAjOWTiVA 2018-05-22 17:11:00.657  WARN 9 --- [NiW8BAjOWTiVA-2] o.s.a.r.listener.BlockingQueueConsumer   : Queue declaration failed; retries left=1

org.springframework.amqp.rabbit.listener.BlockingQueueConsumer$DeclarationException: Failed to declare queue(s):[springCloudBus.anonymous.eV7zCVLlSNiW8BAjOWTiVA]   at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.attemptPassiveDeclarations(BlockingQueueConsumer.java:672)    at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.start(BlockingQueueConsumer.java:571)     at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1424)     at java.lang.Thread.run(Thread.java:745) Caused by: java.io.IOException: null   at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:105)    at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:101)    at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:123)  at com.rabbitmq.client.impl.ChannelN.queueDeclarePassive(ChannelN.java:992)     at com.rabbitmq.client.impl.ChannelN.queueDeclarePassive(ChannelN.java:50)  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)    at java.lang.reflect.Method.invoke(Method.java:498)     at org.springframework.amqp.rabbit.connection.CachingConnectionFactory$CachedChannelInvocationHandler.invoke(CachingConnectionFactory.java:980)     at com.sun.proxy.$Proxy155.queueDeclarePassive(Unknown Source)  at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.attemptPassiveDeclarations(BlockingQueueConsumer.java:651)    ... 3 common frames omitted Caused by: com.rabbitmq.client.ShutdownSignalException: channel error; protocol method: #method<channel.close>(reply-code=404, reply-text=NOT_FOUND - no queue 'springCloudBus.anonymous.eV7zCVLlSNiW8BAjOWTiVA' in vhost '/', class-id=50, method-id=10)   at com.rabbitmq.utility.ValueOrException.getValue(ValueOrException.java:66)     at com.rabbitmq.utility.BlockingValueOrException.uninterruptibleGetValue(BlockingValueOrException.java:32)  at com.rabbitmq.client.impl.AMQChannel$BlockingRpcContinuation.getReply(AMQChannel.java:366)    at com.rabbitmq.client.impl.AMQChannel.privateRpc(AMQChannel.java:229)  at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:117)  ... 12 common frames omitted Caused by: com.rabbitmq.client.ShutdownSignalException: channel error; protocol method: #method<channel.close>(reply-code=404, reply-text=NOT_FOUND - no queue 'springCloudBus.anonymous.eV7zCVLlSNiW8BAjOWTiVA' in vhost '/', class-id=50, method-id=10)  at com.rabbitmq.client.impl.ChannelN.asyncShutdown(ChannelN.java:505)   at com.rabbitmq.client.impl.ChannelN.processAsync(ChannelN.java:336)    at com.rabbitmq.client.impl.AMQChannel.handleCompleteInboundCommand(AMQChannel.java:143)    at com.rabbitmq.client.impl.AMQChannel.handleFrame(AMQChannel.java:90)  at com.rabbitmq.client.impl.AMQConnection.readFrame(AMQConnection.java:634)     at com.rabbitmq.client.impl.AMQConnection.access$300(AMQConnection.java:47)     at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:572)  ... 1 common frames omitted

2018-05-22 17:11:05.662  WARN 9 --- [NiW8BAjOWTiVA-2] o.s.a.r.listener.BlockingQueueConsumer   : Failed to declare queue: springCloudBus.anonymous.eV7zCVLlSNiW8BAjOWTiVA 2018-05-22 17:11:05.664 ERROR 9 --- [NiW8BAjOWTiVA-2] o.s.a.r.l.SimpleMessageListenerContainer : Consumer received fatal=false exception on startup

org.springframework.amqp.rabbit.listener.QueuesNotAvailableException: Cannot prepare queue for listener. Either the queue doesn't exist or the broker will not allow us to use it.  at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.start(BlockingQueueConsumer.java:599)     at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1424)     at java.lang.Thread.run(Thread.java:745) Caused by: org.springframework.amqp.rabbit.listener.BlockingQueueConsumer$DeclarationException: Failed to declare queue(s):[springCloudBus.anonymous.eV7zCVLlSNiW8BAjOWTiVA]   at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.attemptPassiveDeclarations(BlockingQueueConsumer.java:672)    at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.start(BlockingQueueConsumer.java:571)     ... 2 common frames omitted Caused by: java.io.IOException: null    at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:105)    at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:101)    at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:123)  at com.rabbitmq.client.impl.ChannelN.queueDeclarePassive(ChannelN.java:992)     at com.rabbitmq.client.impl.ChannelN.queueDeclarePassive(ChannelN.java:50)  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)    at java.lang.reflect.Method.invoke(Method.java:498)     at org.springframework.amqp.rabbit.connection.CachingConnectionFactory$CachedChannelInvocationHandler.invoke(CachingConnectionFactory.java:980)     at com.sun.proxy.$Proxy155.queueDeclarePassive(Unknown Source)  at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.attemptPassiveDeclarations(BlockingQueueConsumer.java:651)    ... 3 common frames omitted Caused by: com.rabbitmq.client.ShutdownSignalException: channel error; protocol method: #method<channel.close>(reply-code=404, reply-text=NOT_FOUND - no queue 'springCloudBus.anonymous.eV7zCVLlSNiW8BAjOWTiVA' in vhost '/', class-id=50, method-id=10)   at com.rabbitmq.utility.ValueOrException.getValue(ValueOrException.java:66)     at com.rabbitmq.utility.BlockingValueOrException.uninterruptibleGetValue(BlockingValueOrException.java:32)  at com.rabbitmq.client.impl.AMQChannel$BlockingRpcContinuation.getReply(AMQChannel.java:366)    at com.rabbitmq.client.impl.AMQChannel.privateRpc(AMQChannel.java:229)  at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:117)  ... 12 common frames omitted Caused by: com.rabbitmq.client.ShutdownSignalException: channel error; protocol method: #method<channel.close>(reply-code=404, reply-text=NOT_FOUND - no queue 'springCloudBus.anonymous.eV7zCVLlSNiW8BAjOWTiVA' in vhost '/', class-id=50, method-id=10)  at com.rabbitmq.client.impl.ChannelN.asyncShutdown(ChannelN.java:505)   at com.rabbitmq.client.impl.ChannelN.processAsync(ChannelN.java:336)    at com.rabbitmq.client.impl.AMQChannel.handleCompleteInboundCommand(AMQChannel.java:143)    at com.rabbitmq.client.impl.AMQChannel.handleFrame(AMQChannel.java:90)  at com.rabbitmq.client.impl.AMQConnection.readFrame(AMQConnection.java:634)     at com.rabbitmq.client.impl.AMQConnection.access$300(AMQConnection.java:47)     at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:572)  ... 1 common frames omitted

2018-05-22 17:11:05.664 ERROR 9 --- [NiW8BAjOWTiVA-2] o.s.a.r.l.SimpleMessageListenerContainer : Consumer received fatal exception on startup

org.springframework.amqp.rabbit.listener.QueuesNotAvailableException: Cannot prepare queue for listener. Either the queue doesn't exist or the broker will not allow us to use it.  at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.start(BlockingQueueConsumer.java:599)     at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1424)     at java.lang.Thread.run(Thread.java:745) Caused by: org.springframework.amqp.rabbit.listener.BlockingQueueConsumer$DeclarationException: Failed to declare queue(s):[springCloudBus.anonymous.eV7zCVLlSNiW8BAjOWTiVA]   at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.attemptPassiveDeclarations(BlockingQueueConsumer.java:672)    at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.start(BlockingQueueConsumer.java:571)     ... 2 common frames omitted Caused by: java.io.IOException: null    at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:105)    at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:101)    at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:123)  at com.rabbitmq.client.impl.ChannelN.queueDeclarePassive(ChannelN.java:992)     at com.rabbitmq.client.impl.ChannelN.queueDeclarePassive(ChannelN.java:50)  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)    at java.lang.reflect.Method.invoke(Method.java:498)     at org.springframework.amqp.rabbit.connection.CachingConnectionFactory$CachedChannelInvocationHandler.invoke(CachingConnectionFactory.java:980)     at com.sun.proxy.$Proxy155.queueDeclarePassive(Unknown Source)  at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.attemptPassiveDeclarations(BlockingQueueConsumer.java:651)    ... 3 common frames omitted Caused by: com.rabbitmq.client.ShutdownSignalException: channel error; protocol method: #method<channel.close>(reply-code=404, reply-text=NOT_FOUND - no queue 'springCloudBus.anonymous.eV7zCVLlSNiW8BAjOWTiVA' in vhost '/', class-id=50, method-id=10)   at com.rabbitmq.utility.ValueOrException.getValue(ValueOrException.java:66)     at com.rabbitmq.utility.BlockingValueOrException.uninterruptibleGetValue(BlockingValueOrException.java:32)  at com.rabbitmq.client.impl.AMQChannel$BlockingRpcContinuation.getReply(AMQChannel.java:366)    at com.rabbitmq.client.impl.AMQChannel.privateRpc(AMQChannel.java:229)  at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:117)  ... 12 common frames omitted Caused by: com.rabbitmq.client.ShutdownSignalException: channel error; protocol method: #method<channel.close>(reply-code=404, reply-text=NOT_FOUND - no queue 'springCloudBus.anonymous.eV7zCVLlSNiW8BAjOWTiVA' in vhost '/', class-id=50, method-id=10)  at com.rabbitmq.client.impl.ChannelN.asyncShutdown(ChannelN.java:505)   at com.rabbitmq.client.impl.ChannelN.processAsync(ChannelN.java:336)    at com.rabbitmq.client.impl.AMQChannel.handleCompleteInboundCommand(AMQChannel.java:143)    at com.rabbitmq.client.impl.AMQChannel.handleFrame(AMQChannel.java:90)  at com.rabbitmq.client.impl.AMQConnection.readFrame(AMQConnection.java:634)     at com.rabbitmq.client.impl.AMQConnection.access$300(AMQConnection.java:47)     at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:572)  ... 1 common frames omitted

2018-05-22 17:11:05.666 ERROR 9 --- [NiW8BAjOWTiVA-2] o.s.a.r.l.SimpleMessageListenerContainer : Stopping container from aborted consumer 2018-05-22 17:11:05.666  INFO 9 --- [NiW8BAjOWTiVA-2] o.s.a.r.l.SimpleMessageListenerContainer : Waiting for workers to finish. 2018-05-22 17:11:05.666  INFO 9 --- [NiW8BAjOWTiVA-2] o.s.a.r.l.SimpleMessageListenerContainer : Successfully waited for workers to finish.

知道为什么空闲连接会丢失。 心跳设置为10秒。 Rabbitmq已启用ssl。

1 个答案:

答案 0 :(得分:1)

  

o.s.amqp.rabbit.core.RabbitAdmin:自动声明

     

非持久,自动删除或独占队列

     

(springCloudBus.anonymous.eV7zCVLlSNiW8BAjOWTiVA)持久:false,

     

自动删除:true,exclusive:true。如果经纪人

,将重新申报      

在连接工厂处于活动状态时停止并重新启动,但所有

     

消息将丢失。 2018-05-22 17:10:50.617错误9 ---

     

[0.X.X.78:5671] o.s.a.r.c.CachingConnectionFactory:Channel

     

关机:渠道错误;协议方法:

     

方法(reply-code = 405,reply-text = RESOURCE_LOCKED - 无法获得对锁定队列的独占访问

似乎存在竞争条件 - Rabbit Admin无法重新声明匿名的自动删除独占队列,因为旧的队列仍然暂时存在。

随后,容器尝试进行被动声明,到那时,队列不存在。

我认为我们需要为RabbitAdmin添加一些重试功能。我打开了JIRA issue

修改

这有点粗糙,但这是一个解决方法......

@Bean
public static Object addDelayOnReconnect(CachingConnectionFactory connectionFactory) {
    connectionFactory.addConnectionListener(new ConnectionListener() {

        private final AtomicBoolean initialConnection = new AtomicBoolean(true);

        @Override
        public void onCreate(Connection connection) {
            if (!this.initialConnection.compareAndSet(true, false)) {
                try {
                    System.out.println("Waiting a while for auto-delete queues to be deleted...");
                    Thread.sleep(5_000);
                    System.out.println("Continuing...");
                }
                catch (InterruptedException e) {
                    Thread.currentThread().interrupt();
                }
            }
        }

        @Override
        public void onClose(Connection connection) {
            // empty
        }
    });
    return new Object();
}

2018-05-22 17:16:45.599  ... : Created new connection: rabbitConnectionFactory#787e4357:1/SimpleConnection@37c0e81b [delegate=amqp://guest@127.0.0.1:5672/, localPort= 50201]
Waiting a while for auto-delete queues to be deleted...
Continuing...
2018-05-22 17:16:50.605 ... : Auto-declaring a non-durable, auto-delete, or exclusive Queue (springCloudBus.anonymous.RQp18TX0SpObVqJSEr64hQ) durable:false, auto-delete:true, exclusive:true. It will be redeclared if the broker stops and is restarted while the connection factory is alive, but all messages will be lost.

请注意,我将它设为static bean,因为我们希望在RabbitAdmin之前添加此侦听器;没有static而是YMMV,它对我有用。如果您发现管理员首先被添加,您可以恢复使用setConnectionListeners替换侦听器列表 - 但请务必将RabbitAdmin添加到列表中,以便它执行声明。

你可以通过在循环中调用RabbitAdmin.getQueueProperties()来使它变得更复杂,直到队列不再存在(尽管找到队列名称可能并不容易)。

<强> EDIT2

这是一个更好的解决方法 - 覆盖Boot的AmqpAdmin bean ...

@Bean
public AmqpAdmin amqpAdmin(ConnectionFactory connectionFactory) {
    return new RabbitAdmin(connectionFactory) {

        @Override
        public void initialize() {
            while (true) { // might want to give up after some number of tries
                try {
                    super.initialize();
                    break;
                }
                catch (Exception e) {
                    System.out.println("Failed to declare elements: " + e.getCause().getCause().getMessage());
                    try {
                        Thread.sleep(1_000);
                    }
                    catch (InterruptedException e1) {
                        Thread.currentThread().interrupt();
                    }
                }
            }
        }

    };
}