带有弹簧靴的rabbitmq中的异常

Posted

技术标签:

【中文标题】带有弹簧靴的rabbitmq中的异常【英文标题】:Exceptions in rabbitmq with spring boot 【发布时间】:2015-09-27 03:00:25 【问题描述】:

当我使用 rabbitmq 启动我的 Spring Boot 应用程序时,我反复收到以下异常。即使有以下例外,整个流程也可以正常工作。是不是跟自动删除方式有关?

    08 Jul 2015 16:20:17,652 [ERROR] [SimpleAsyncTaskExecutor-2] SimpleMessageListenerContainer| Failed to check/redeclare auto-delete queue(s).
    java.util.concurrent.TimeoutException
        at com.rabbitmq.utility.BlockingCell.get(BlockingCell.java:77)
        at com.rabbitmq.utility.BlockingCell.uninterruptibleGet(BlockingCell.java:111)
        at com.rabbitmq.utility.BlockingValueOrException.uninterruptibleGetValue(BlockingValueOrException.java:37)
        at com.rabbitmq.client.impl.AMQChannel$BlockingRpcContinuation.getReply(AMQChannel.java:367)
        at com.rabbitmq.client.impl.AMQConnection.start(AMQConnection.java:293)
        at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:621)
        at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:665)
        at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:208)
        at org.springframework.amqp.rabbit.connection.CachingConnectionFactory.createConnection(CachingConnectionFactory.java:444)
        at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils$1.createConnection(ConnectionFactoryUtils.java:80)
        at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils.doGetTransactionalResourceHolder(ConnectionFactoryUtils.java:130)
        at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils.getTransactionalResourceHolder(ConnectionFactoryUtils.java:67)
        at org.springframework.amqp.rabbit.core.RabbitTemplate.doExecute(RabbitTemplate.java:1035)
        at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:1028)
        at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:1004)
        at org.springframework.amqp.rabbit.core.RabbitAdmin.getQueueProperties(RabbitAdmin.java:254)
        at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.redeclareElementsIfNecessary(SimpleMessageListenerContainer.java:963)
        at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.access$300(SimpleMessageListenerContainer.java:83)
        at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1081)
        at java.lang.Thread.run(Thread.java:745)

08 Jul 2015 16:52:47,148 [WARN ] [SimpleAsyncTaskExecutor-1] SimpleMessageListenerContainer| Consumer raised exception, processing can restart if the connection factory supports it
java.util.concurrent.TimeoutException
    at com.rabbitmq.utility.BlockingCell.get(BlockingCell.java:77)
    at com.rabbitmq.utility.BlockingCell.uninterruptibleGet(BlockingCell.java:111)
    at com.rabbitmq.utility.BlockingValueOrException.uninterruptibleGetValue(BlockingValueOrException.java:37)
    at com.rabbitmq.client.impl.AMQChannel$BlockingRpcContinuation.getReply(AMQChannel.java:367)
    at com.rabbitmq.client.impl.AMQConnection.start(AMQConnection.java:293)
    at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:621)
    at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:665)
    at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:208)
    at org.springframework.amqp.rabbit.connection.CachingConnectionFactory.createConnection(CachingConnectionFactory.java:444)
    at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils$1.createConnection(ConnectionFactoryUtils.java:80)
    at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils.doGetTransactionalResourceHolder(ConnectionFactoryUtils.java:130)
    at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils.getTransactionalResourceHolder(ConnectionFactoryUtils.java:67)
    at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.start(BlockingQueueConsumer.java:434)
    at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1083)
    at java.lang.Thread.run(Thread.java:745)

以下是我的豆子

 <rabbit:queue id="reportQueue" name="reportQueue" durable="true" auto-delete="false" exclusive="false"/>


 <rabbit:direct-exchange id="reportExchange" durable="true" name="reportExchange">
     <rabbit:bindings>
        <rabbit:binding queue="reportQueue" key="reportBind"></rabbit:binding>
     </rabbit:bindings>
 </rabbit:direct-exchange>


  <bean id="aListener" class="com.sample.ReportMessageListener" autowire="byName"/>
  <bean id="reportMessageConverter" class="com.sample.ReportMessageConverter"/>
 <rabbit:listener-container id="myListenerContainer" connection-factory="connectionFactory" acknowledge="auto" prefetch="5" concurrency="1" message-converter="reportMessageConverter" >
    <rabbit:listener ref="aListener" queues="reportQueue"/>
</rabbit:listener-container>

更新:

启用调试的消息是

09 Jul 2015 14:46:35,284 [DEBUG] [main] SimpleMessageListenerContainer| Starting Rabbit listener container.
09 Jul 2015 14:46:38,601 [DEBUG] [elasticsearch[local_jvm_node][clusterService#updateTask][T#1]] service                  | [local_jvm_node] processing [routing-table-updater]: execute
09 Jul 2015 14:46:38,602 [DEBUG] [elasticsearch[local_jvm_node][clusterService#updateTask][T#1]] service                  | [local_jvm_node] processing [routing-table-updater]: no change in cluster_state
09 Jul 2015 14:46:40,324 [ERROR] [SimpleAsyncTaskExecutor-1] SimpleMessageListenerContainer| Failed to check/redeclare auto-delete queue(s).
java.util.concurrent.TimeoutException
    at com.rabbitmq.utility.BlockingCell.get(BlockingCell.java:77)
    at com.rabbitmq.utility.BlockingCell.uninterruptibleGet(BlockingCell.java:111)
    at com.rabbitmq.utility.BlockingValueOrException.uninterruptibleGetValue(BlockingValueOrException.java:37)
    at com.rabbitmq.client.impl.AMQChannel$BlockingRpcContinuation.getReply(AMQChannel.java:367)
    at com.rabbitmq.client.impl.AMQConnection.start(AMQConnection.java:293)
    at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:621)
    at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:665)
    at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:208)
    at org.springframework.amqp.rabbit.connection.CachingConnectionFactory.createConnection(CachingConnectionFactory.java:444)
    at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils$1.createConnection(ConnectionFactoryUtils.java:80)
    at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils.doGetTransactionalResourceHolder(ConnectionFactoryUtils.java:130)
    at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils.getTransactionalResourceHolder(ConnectionFactoryUtils.java:67)
    at org.springframework.amqp.rabbit.core.RabbitTemplate.doExecute(RabbitTemplate.java:1035)
    at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:1028)
    at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:1004)
    at org.springframework.amqp.rabbit.core.RabbitAdmin.getQueueProperties(RabbitAdmin.java:254)
    at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.redeclareElementsIfNecessary(SimpleMessageListenerContainer.java:963)
    at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.access$300(SimpleMessageListenerContainer.java:83)
    at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1081)
    at java.lang.Thread.run(Thread.java:745)
09 Jul 2015 14:46:40,328 [DEBUG] [SimpleAsyncTaskExecutor-1] BlockingQueueConsumer    | Starting consumer Consumer: tags=[], channel=null, acknowledgeMode=MANUAL local queue size=0
09 Jul 2015 14:46:45,333 [DEBUG] [SimpleAsyncTaskExecutor-1] SimpleMessageListenerContainer| Recovering consumer in 5000 ms.

09 Jul 2015 14:46:50,402 [WARN ] [SimpleAsyncTaskExecutor-1] SimpleMessageListenerContainer| Consumer raised exception, processing can restart if the connection factory supports it
java.util.concurrent.TimeoutException
    at com.rabbitmq.utility.BlockingCell.get(BlockingCell.java:77)
    at com.rabbitmq.utility.BlockingCell.uninterruptibleGet(BlockingCell.java:111)
    at com.rabbitmq.utility.BlockingValueOrException.uninterruptibleGetValue(BlockingValueOrException.java:37)
    at com.rabbitmq.client.impl.AMQChannel$BlockingRpcContinuation.getReply(AMQChannel.java:367)
    at com.rabbitmq.client.impl.AMQConnection.start(AMQConnection.java:293)
    at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:621)
    at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:665)
    at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:208)
    at org.springframework.amqp.rabbit.connection.CachingConnectionFactory.createConnection(CachingConnectionFactory.java:444)
    at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils$1.createConnection(ConnectionFactoryUtils.java:80)
    at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils.doGetTransactionalResourceHolder(ConnectionFactoryUtils.java:130)
    at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils.getTransactionalResourceHolder(ConnectionFactoryUtils.java:67)
    at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.start(BlockingQueueConsumer.java:434)
    at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1083)
    at java.lang.Thread.run(Thread.java:745)
09 Jul 2015 14:46:50,403 [INFO ] [SimpleAsyncTaskExecutor-1] SimpleMessageListenerContainer| Restarting Consumer: tags=[], channel=null, acknowledgeMode=MANUAL local queue size=0
09 Jul 2015 14:46:50,403 [DEBUG] [SimpleAsyncTaskExecutor-1] BlockingQueueConsumer    | Closing Rabbit Channel: null

【问题讨论】:

看看这是否可以帮助***.com/questions/24373588/… 您解决了这个问题吗?解决方案是什么。 【参考方案1】:

重新启动 RabbitMQ 为我解决了这个问题 (Mac)。

cd /usr/local/sbin 
./rabbitmqctl stop_app
./rabbitmqctl start_app

【讨论】:

rabbitMQ 是否有问题,导致该问题?【参考方案2】:

它与自动删除队列无关(除了你有一些手段容器在其生命周期的这个特定点初始化连接)。

您似乎遇到了一些网络问题...

java.util.concurrent.TimeoutException
....
    at com.rabbitmq.client.impl.AMQConnection.start(AMQConnection.java:293)

rabbitmq 客户端库在等待连接启动命令响应且服务器没有及时回复时,有一个硬编码的 5 秒超时。

【讨论】:

我在同一台机器上运行客户端和rabbitmq。即使有这些错误消息(这些消息是连续的,而不是一次性的)生产者和消费者也可以很好地传递消息。如果这是一个连接问题,我相信整个事情都不应该正常工作。如果我错了,请纠正我。 也许问题是暂时的?如果您打开调试日志记录,您应该会获得更多信息。我知道超时的东西最近才被添加到 Spring AMQP 使用的 rabbit 客户端中,所以那里可能存在一些新问题;调试日志应该会有所帮助。如果它太大,无法在此处发布,请尝试使用 pastebin 或 github gist。 是的,问题是暂时的。但是我在开始申请的 10 次中得到了这 8 次。在问题中添加了启用调试的消息。如果您需要任何东西,请告诉我。同时,我正在尝试通过尝试其他一些属性来对此进行调查。 从日志中看不出什么。看看rabbitmq日志里有没有什么。 我希望看到更完整的日志 - 包括应用程序何时开始工作。【参考方案3】:

我认为这与您的弹簧兔版本有关。 我遇到了和你一样的问题。但我不知道要修复它。 但在我的另一个项目中,它运行良好。然后我比较了两个项目。 我发现 spring-rabbit 版本不一样。

<dependency>
  <groupId>org.springframework.amqp</groupId>
  <artifactId>spring-rabbit</artifactId>
  <version>1.6.5.RELEASE</version>
</dependency>

这个新版本抛出 TimeoutException。 但是

<dependency>
  <groupId>org.springframework.amqp</groupId>
  <artifactId>spring-rabbit</artifactId>
  <version>1.4.5.RELEASE</version>
</dependency>

这个版本运行良好。 我的 spring-boot 版本是“Camden.SR2”。默认 spring-rabbit 1.6.5.RELEASE。

希望对你有帮助

【讨论】:

【参考方案4】:

我认为你可以尝试将端口更改为 5672,它对我有用

【讨论】:

【参考方案5】:

也许你可以尝试通过定义 bean 来覆盖默认的握手超时

com.rabbitmq.client.ConnectionFactory#setHandshakeTimeout 

如下所示:

<bean id="myConnectionFactory" class="com.rabbitmq.client.ConnectionFactory"
      p:automaticRecoveryEnabled="false" p:handshakeTimeout="$rabbit.handshakeTimeout:10000">
 ....
</bean>

【讨论】:

以上是关于带有弹簧靴的rabbitmq中的异常的主要内容,如果未能解决你的问题,请参考以下文章

如何通过带有弹簧靴的邮递员操作数据

带有弹簧靴的keycloak openid单次注销

在某些机器上构建时,带有弹簧靴的 Swagger 可以工作,但在其他机器上则不行

带弹簧靴的执行器

用于弹簧靴的 CORS 过滤器不起作用

text 弹簧靴的Gradle模板。展示如何使用集成测试