Rabbit Template退出策略,禁用自动恢复

时间:2017-12-04 09:29:01

标签: spring-rabbit spring-rabbitmq

我已将启用了自动恢复功能的CachingConnectionFactory配置为false,并将其分配给兔子模板初步设置回退策略。然而,当我在向兔子发布消息之前打破兔子连接似乎退出政策不起作用并且异常立即被抛出。为什么它没有像预期的那样工作而没有5秒延迟抛出。

还有一件事是可以将关闭策略应用于连接工厂本身以启用自动恢复策略而不必担心日志中的每个5都会出错吗?

  Caused by: java.net.SocketException: Broken pipe (Write failed)

    @Bean
    public CachingConnectionFactory connectionFactory() {

        ConnectionFactory factory = new ConnectionFactory();

        factory.setPassword(password);
        factory.setRequestedHeartbeat(requestedHeartbeat);
        factory.setAutomaticRecoveryEnabled(false);

        CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory(factory);
        cachingConnectionFactory.setAddress(address1 + ", " + address2);

        return cachingConnectionFactory;
    }

    @Bean
    public RabbitTemplate rabbitTemplate() {

        ExponentialBackOffPolicy backOffPolicy = new ExponentialBackOffPolicy();
        backOffPolicy.setInitialInterval(500);
        backOffPolicy.setMultiplier(10);
        backOffPolicy.setMaxInterval(10000);

        RetryTemplate retryTemplate = new RetryTemplate();
        retryTemplate.setBackOffPolicy(backOffPolicy);

        RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory());
        rabbitTemplate.setRetryTemplate(retryTemplate);
        return rabbitTemplate;
}

0 个答案:

没有答案