Bootstrap

springboot集成RabbitMq异常 Channel shutdown: channel error; protocol method: #method<channel.close>

在使用 rabbitMq 中间件对消息进行发送、接受的时候,使用 TopicExchange 交换机出现了下面的问题,报了以下错误。

Channel shutdown: channel error; protocol method: 
#method<channel.close>(reply-code=406, reply-text=PRECONDITION_FAILED 
- inequivalent arg 'type' for exchange 'itcast.topic' in vhost '/': 
received 'topic' but current is 'direct', class-id=40, method-id=10)

字面意思:我理解的是错误使用了交换机,上面写着应给received的是“topic”,但是目前的话,是“direct”交换机。

问题分析:

@RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "topic.queue2"),
            exchange = @Exchange(name = "itcast.direct", type = ExchangeTypes.TOPIC),
            key = "#.news"
    ))

在一开始声明交换机的时候,由于直接复制上面的代码。所以交换机一开始声明的是direct。

解决方法:
将交换机移除掉,重新启动项目即可。

;