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

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

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<String, Object> 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

猜你喜欢

转载自www.cnblogs.com/huyuchengus/p/11666277.html