【问题标题】:How to establish connection after connection error for RabbitMQ with a SpringBoot app如何在使用 SpringBoot 应用程序的 RabbitMQ 连接错误后建立连接
【发布时间】:2021-05-18 09:40:32
【问题描述】:

将我的 SpringBoot 应用程序重新部署到 TomcatServer 9 后,我遇到了一些奇怪的异常:

MyApplication: 2021-05-17 09:54:39,306 错误 [AMQP 连接 主机:端口]

o.s.a.r.c.CachingConnectionFactory:1576 - 通道关闭:连接错误 从那以后,我无法从 RabbitMQ 收到任何消息。

如果我重新启动我的应用程序,那么也不例外。

是否需要在我的 SpringBoot 应用中更改某些内容以在这些错误后自动重新连接?

或者我错过了什么?

这是我的 SimpleRabbitListenerContainerFactory 设置:

@Bean
public SimpleRabbitListenerContainerFactory poxStatusFeedbackInterceptContainerFactory(final SimpleRabbitListenerContainerFactoryConfigurer configurer,
                                                                                       final ConnectionFactory connectionFactory) {
    SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory() {
        @Override
        protected void initializeContainer(SimpleMessageListenerContainer instance, RabbitListenerEndpoint endpoint) {
            instance.setAfterReceivePostProcessors(new MyPostProcessor()); // this does some prevalidation of messages
            super.initializeContainer(instance, endpoint);
        }
    };
    configurer.configure(factory, connectionFactory);
    return factory;
}

这是 application.yml 设置:

spring:
  rabbitmq:
    host: .......
    port: ....
    virtual-host: myhost
    username: sa
    password: sa
    listener:
      simple:
        retry:
          enabled: true
          initial-interval: 3s
          max-interval: 10s
          multiplier: 2
          max-attempts: 3

【问题讨论】:

    标签: spring-boot tomcat rabbitmq connection amqp


    【解决方案1】:

    这样就可以解决问题了:

    ((CachingConnectionFactory) connectionFactory).setRequestedHeartBeat(60);
    

    在这里找到: https://www.rabbitmq.com/heartbeats.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-21
      • 2020-12-29
      • 1970-01-01
      • 2018-11-22
      • 2019-05-22
      • 2020-04-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多