SpringAMQP发送消息到RabbitMQ收到x-queue-type错误

在使用 Spring AMQP 发送消息到 RabbitMQ 的时候收到错误信息:

创新互联长期为1000多家客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为宁德企业提供专业的成都网站设计、网站制作,宁德网站改版等技术服务。拥有十多年丰富建站经验和众多成功案例,为您定制开发。

inequivalent arg 'x-queue-type' for queue 'com.ossez.real.estate' in vhost '/': received none but current is the value 'classic' of type 'longstr', class-id=50, method-id=10

上面的错误信息已经很明显了,说明的是发送消息的队列参数中少了 x-queue-type 这个参数。

在代码中,我们创建队列的参数为:

return new Queue(MY_QUEUE_NAME, NON_DURABLE);

这直接创建队列的参数少了 args.put("x-queue-type", "classic");

因此,我们需要在创建队列的时候添加上面的参数。

修改代码为:

Map args = new HashMap<>();
// // set the queue with a dead letter feature
args.put("x-queue-type", "classic");

return new Queue(MY_QUEUE_NAME, NON_DURABLE, false, false, args);

请参考 GitHub 中的代码:

https://github.com/cwiki-us-demo/tutorials/blob/master/spring-amqp/src/main/java/com/baeldung/springamqp/simple/HelloWorldMessageApp.java

https://blog.ossez.com/archives/3050


文章名称:SpringAMQP发送消息到RabbitMQ收到x-queue-type错误
URL分享:http://ybzwz.com/article/jpgccc.html