控制台报错提示:
Channel shutdown: channel error; protocol method: #method<channel.close>(reply-code=406, reply-text=PRECONDITION_FAILED - inequivalent arg 'type' for exchange 'topic' in vhost '/': received 'topic' but current is 'direct', class-id=40, method-id=10)
翻译过来就是 收到'topic',但当前是'direct
解决办法:
错误代码 :
@RabbitListener(bindings = @QueueBinding(
value = @Queue("tiopic.queueq1"),
exchange = @Exchange(value = "topic", type = ExchangeTypes.TOPIC),
key = "www.#"
))
public void listenTopicQueue1(String msg){
System.out.println("消费者接收到topic.queue1的消息:【" + msg + "】");
}
正确代码: 重新换一个交换机的名称就好了
@RabbitListener(bindings = @QueueBinding(
value = @Queue(name = "tiopic.queue2"),
exchange = @Exchange(name = "topic1", type = ExchangeTypes.TOPIC),
key = "#.baidu"
))
public void listenTopicQueue2(String msg){
System.out.println("消费者接收到topic.queue1的消息:【" + msg + "】");
}