使用默认交换声明第二个队列会产生错误

时间:2018-08-29 13:25:50

标签: spring-boot rabbitmq spring-amqp

Spring Boot 1.5.15

当我声明一个队列时,该队列即被声明并且发送/接收工作正常。 如果我添加第二个(和后续)队列,则会记录错误,重新声明队列5次,最后应用程序无法启动。

Spring Boot RabbitMQ配置:

    @Configuration
    public class RabbitConfig implements RabbitListenerConfigurer {

        @Autowired
        private ObjectMapper mapper;

        @Bean
        Queue crmAppealQueue(@Value("${app.queues.portalAppeal}") String queueName) {
            return new Queue(queueName, false);
        }

        @Bean
        Queue portalUserQueue(@Value("${app.queues.portalUser}") String queueName) {
            return new Queue(queueName, false);
        }

        @Override
        public void configureRabbitListeners(RabbitListenerEndpointRegistrar registrar) {
            registrar.setMessageHandlerMethodFactory(messageHandlerMethodFactory());
        }

        @Bean
        MessageHandlerMethodFactory messageHandlerMethodFactory() {
            DefaultMessageHandlerMethodFactory messageHandlerMethodFactory = new DefaultMessageHandlerMethodFactory();
            messageHandlerMethodFactory.setMessageConverter(consumerJackson2MessageConverter());
            return messageHandlerMethodFactory;
        }

        @Bean
        public MappingJackson2MessageConverter consumerJackson2MessageConverter() {
            return new MappingJackson2MessageConverter();
        }

        @Bean
        public RabbitTemplate rabbitTemplate(final ConnectionFactory connectionFactory) {
            final RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);
            rabbitTemplate.setMessageConverter(producerJackson2MessageConverter());
            return rabbitTemplate;
        }

        @Bean
        public Jackson2JsonMessageConverter producerJackson2MessageConverter() {
            return new Jackson2JsonMessageConverter(mapper);
        }
}

错误日志:

2018-29-08 15:04:52,075  INFO (RabbitAdmin.java:566) - Auto-declaring a non-durable, auto-delete, or exclusive Queue (portal.appeal) durable:false, auto-delete:false, exclusive:false. It will be redeclared if the broker stops and is restarted while the connection factory is alive, but all messages will be lost.
2018-29-08 15:04:52,075  INFO (RabbitAdmin.java:566) - Auto-declaring a non-durable, auto-delete, or exclusive Queue (portal.user) durable:false, auto-delete:false, exclusive:false. It will be redeclared if the broker stops and is restarted while the connection factory is alive, but all messages will be lost.
2018-29-08 15:04:52,122 ERROR (CachingConnectionFactory.java:1327) - Channel shutdown: channel error; protocol method: #method<channel.close>(reply-code=406, reply-text=PRECONDITION_FAILED - inequivalent arg 'durable' for queue 'portal.user' in vhost '/': received 'false' but current is 'true', class-id=50, method-id=10)

如果注释了一个队列声明,则日志显示仅声明了一个队列,并且应用程序继续启动(也就是说,其他地方未声明另一个队列)

2018-29-08 17:21:49,435  INFO (AbstractConnectionFactory.java:379) - Created new connection: rabbitConnectionFactory#74ba4614:0/SimpleConnection@2a6c087d [delegate=amqp://precrm@192.168.82.177:5672/, localPort= 63501]
2018-29-08 17:21:49,435  INFO (RabbitAdmin.java:566) - Auto-declaring a non-durable, auto-delete, or exclusive Queue (portal.appeal) durable:false, auto-delete:false, exclusive:false. It will be redeclared if the broker stops and is restarted while the connection factory is alive, but all messages will be lost.
2018-29-08 17:21:49,529  INFO (StartupInfoLogger.java:57) - Started PortalAppealMessageHandlerTest in 5.317 seconds (JVM running for 6.599)

1 个答案:

答案 0 :(得分:1)

好吧,那真是个愚蠢的家伙(很可能是这样)。

我假设每次声明队列都是从头开始创建的,这与我的配置不同。

实际上,它存在一个不同的耐用性参数-正是msg试图告诉我的错误。

解决方案:我使用AmqAdmin.deleteQueue()

删除了它
相关问题