AMQP convertSendAndReceive fails moving from Spring Boot 1.5 to 2

Viewed 654

I'm migrating code from Spring Boot 1.5.x to 2.0.3.RELEASE.

It uses RabbitMQ to make an RPC style call to a set of remote engines using the convertSendAndReceive(...) method.

All works fine in 1.5, but fails in the migrated code.

The logging initially shows

SimpleConsumer [queue=amq.rabbitmq.reply-to, consumerTag=amq.ctag-39fo5C1y6q8J9OevWDN3_A identity=6ffebba9] started 

The message reaches the engine and is handled correctly.

However, the return value is empty and the following is logged

ERROR o.s.amqp.rabbit.core.RabbitTemplate No correlation header in reply

In 1.5 we didn't add a correlation Id to the caller. Do we now need to or is there something else we need to do?

TIA.

1 Answers

From the the Spring amqp docs

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.

So for example...

    rabbitTemplate.setUseDirectReplyToContainer(false);
Related