문제

I have code using Spring AMQP for synchronous messaging as below. My scenario is when producer sends messages it is expecting response. So, can any one help on how to send response back in case of synchronous messages.

Producer end - rabbitTemplate.convertAndSend(object);
Consumer end - rabbitTemplate.receiveAndconvert();

and I came know that we can use handleMessage() in case of asynchronous messaging. But, using above API how to send response back in case of synchronous messaging? Can you please help me on this?

Thanks in advance.

도움이 되었습니까?

해결책

How about to use this one convertSendAndReceive? In this case the RabbitTemplate takes care about synchronius send request and receive a reply. Try it, please and let us know

다른 팁

See the reference documentation for options.

The convertSendAndReceive on the producer side adds a replyTo header (default is a new temporary queue but you can configure a fixed reply queue).

On the consumer side, the simplest solution is to a message listener container and the MessageListenerAdapter will call your simple POJO and take care of sending the reply for you.

If you must use a rabbit template on the consumer side, you would need to use a lower level receive to get access to the message properties, so you can access the replyTo information in order to send the reply.

Take a look at the source code for the MessageListenerAdapter to see how he does it.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top