【发布时间】:2021-03-04 08:53:32
【问题描述】:
我正在使用带有 Spring Boot 2.0.3 的 rabbitMQ。
目前我正在使用:
@Bean
public SimpleRabbitListenerContainerFactory simpleRabbitListenerContainerFactory()
{
SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
factory.setConnectionFactory(cachingConnectionFactory);
...
return factory;
}
当我尝试 rabbitTemplate.convertAndSend(exchange, routingKey, payload) 与不存在的交换时,
错误只显示一次,这是可取的。
2021-03-04 16:20:15.746 ERROR CachingConnectionFactory:1302 [AMQP Connection ip:5672] - Channel shutdown: channel error; protocol method: #method<channel.close>(reply-code=404, reply-text=NOT_FOUND - no exchange 'exchange' in vhost 'vhost', class-id=60, method-id=40)
但是,当我使用 @SendTo 和 @RabbitListener 时,例如
@RabbitListener(queues = "test_mq_queue")
@SendTo("exchange/routingKey")
如果交换不存在,将显示错误无穷大。例如
2021-03-04 16:45:23.079 ERROR CachingConnectionFactory:1302 [AMQP Connection ip:5672] - Channel shutdown: channel error; protocol method: #method<channel.close>(reply-code=404, reply-text=NOT_FOUND - no exchange 'exchange' in vhost 'vhost', class-id=60, method-id=40)
2021-03-04 16:45:24.100 ERROR CachingConnectionFactory:1302 [AMQP Connection ip:5672] - Channel shutdown: channel error; protocol method: #method<channel.close>(reply-code=404, reply-text=NOT_FOUND - no exchange 'exchange' in vhost 'vhost', class-id=60, method-id=40)
2021-03-04 16:45:25.125 ERROR CachingConnectionFactory:1302 [AMQP Connection ip:5672] - Channel shutdown: channel error; protocol method: #method<channel.close>(reply-code=404, reply-text=NOT_FOUND - no exchange 'exchange' in vhost 'vhost', class-id=60, method-id=40)
2021-03-04 16:45:26.149 ERROR CachingConnectionFactory:1302 [AMQP Connection ip:5672] - Channel shutdown: channel error; protocol method: #method<channel.close>(reply-code=404, reply-text=NOT_FOUND - no exchange 'exchange' in vhost 'vhost', class-id=60, method-id=40)
2021-03-04 16:45:27.181 ERROR CachingConnectionFactory:1302 [AMQP Connection ip:5672] - Channel shutdown: channel error; protocol method: #method<channel.close>(reply-code=404, reply-text=NOT_FOUND - no exchange 'exchange' in vhost 'vhost', class-id=60, method-id=40)
...
我错过了什么吗?如果需要更多信息,请告诉我。
【问题讨论】:
-
您是否验证过您的交换和队列是否存在?您介意发布您的配置吗?
-
我的exchange是不存在的,特意看看
@SendTo注解能否完全替代我在Listener中的rabbitTemplate.convertAndSend
标签: java spring spring-boot rabbitmq spring-amqp