0
votes

I have created on replyQ and done biniding with one direct exchange. Created the message by setting replyto property to "replyQ" And sending the message on rabbit to the other service. The service at other end getting the message and sending reply on given replyTo queue.

and now I am trying to read from a replyQ queue using

    template.receiveAndConvert(replyQueue));

But getting null response and i can see the message in the replyQ. That is the service is able to send the reply but am not able to read it from the given queue

Please help what is going wrong.

2

2 Answers

0
votes

template.receiveAndConvert() is sync, blocked for some time one time function, where default timeout is:

private static final long DEFAULT_REPLY_TIMEOUT = 5000;

Maybe this one is your problem.

Consider to switch to ListenerContainer for continuous queue polling. Another option is RabbitTemplate.sendAndReceive(), but yeah, with fixed reply queue you still get deal with ListenerContainer. See Spring AMQP Reference Manual for more info.

0
votes

I don't know if this could help anyone, but I found out that declaring the expected Object as a parameter of a method listener did the work

@RabbitListener(queues = QUEUE_PRODUCT_NEW)
public void onNewProductListener(ProductDTO productDTO) {
    // messagingTemplate.receiveAndConvert(QUEUE_PRODUCT_NEW) this returns null
    log.info("A new product was created {}", productDTO);
}