You can use any number of synchronization techniques; for example have the listener put
the replies in a LinkedBlockingQueue
and have the sender take
(or poll
with timeout) from the queue until all the replies are received.
Or, don't use a listener at all and simply use the same RabbitTemplate
to receive()
from the reply queue until all the replies are received.
However, receive()
returns null
if the queue is empty so you'll have to sleep between receives to avoid spinning the CPU.