Reputation: 578
How the jmstemplate receive() method is synchronized? Sender send message to a broker and on the other side consumer consumes message from broker queue or a topic. For receive, it will be some polling thread waiting for some data on a broker. How the synchronization then gets maintained?
Upvotes: 1
Views: 5813
Reputation: 33111
JmsTemplate
uses the JMS API behind the scene and in particular the MessageConsumer
. That service can either attempt to receive a Message
without waiting (receiveNoWait
) or it can wait a configurable amount of time (receive(long timeout)
). When it's being invoked with a timeout of 0, the receive method blocks until a message arrives. There's nothing in JmsTemplate
that deals with all this (i.e. it is provided by the client broker implementation).
A more regular way of receiving messages is to use a listener container. With Spring, the DefaultMessageListenerContainer
allows you to use a thread poll to process incoming messages. Check the jms documentation of the Spring framework for more information.
Upvotes: 3