Spring AMQP 發送消息到 RabbitMQ 收到 x-queue-type 錯誤

在使用 Spring AMQP 發送消息到 RabbitMQ 的時候收到錯誤信息:html

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=10java


上面的錯誤信息已經很明顯了,說明的是發送消息的隊列參數中少了 x-queue-type 這個參數。git

在代碼中,咱們建立隊列的參數爲:github

return new Queue(MY_QUEUE_NAME, NON_DURABLE);

這直接建立隊列的參數少了 args.put("x-queue-type", "classic");spring

所以,咱們須要在建立隊列的時候添加上面的參數。ide

修改代碼爲:ui

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 中的代碼:code

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

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

相關文章
相關標籤/搜索