【问题标题】:Spring bus rabbit amqp client drops connection on idle for long timeSpring bus rabbit amqp客户端长时间空闲时断开连接
【发布时间】:2018-11-01 13:39:34
【问题描述】:
**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 设置了带有 Spring Boot 服务的 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。

【问题讨论】:

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


    【解决方案1】:

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

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

    (springCloudBus.anonymous.eV7zCVLlSNiW8BAjOWTiVA) 持久性:假,

    自动删除:真,独占:真。如果broker会重新声明

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

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

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

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

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

    似乎存在竞争条件 - Rabbit 管理员未能重新声明匿名、自动删除、独占队列,因为旧队列暂时仍然存在。

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

    我认为我们需要向 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();
                        }
                    }
                }
            }
    
        };
    }
    

    【讨论】:

      猜你喜欢
      • 2015-07-28
      • 2019-07-14
      • 2012-10-20
      • 1970-01-01
      • 2018-07-15
      • 1970-01-01
      • 2022-09-30
      • 1970-01-01
      • 2021-07-15
      相关资源
      最近更新 更多