我正在将代码从 Spring Boot 1.5.x 迁移到 2.0.3.RELEASE。
它使用 RabbitMQ 使用 convertSendAndReceive(...)
方法对一组远程引擎进行 RPC 样式调用。
在 1.5 中一切正常,但在迁移的代码中失败。
日志记录最初显示
SimpleConsumer [queue=amq.rabbitmq.reply-to, consumerTag=amq.ctag-39fo5C1y6q8J9OevWDN3_A identity=6ffebba9] started
消息到达引擎并被正确处理。
但是,返回值为空,并且记录以下内容
ERROR o.s.amqp.rabbit.core.RabbitTemplate No correlation header in reply
在 1.5 中,我们没有向调用者添加关联 ID。我们现在需要这样做还是还需要做其他事情?
TIA。
最佳答案
With versions earlier than verion 2.0, the RabbitTemplate created a new consumer for each request and canceled the consumer when the reply was received (or timed out). Now, the template uses a DirectReplyToMessageListenerContainer instead, allowing the consumers to be reused; the template still takes care of correlating the replies so there is no danger of a late reply going to a different sender. If you want to revert to the previous behavior, set property useDirectReplyToContainer (direct-reply-to-container when using XML configuration) to false.
例如...
rabbitTemplate.setUseDirectReplyToContainer(false);
关于spring-boot - AMQP ConvertSendAndReceive 无法从 Spring Boot 1.5 迁移到 2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52328210/