Re: What is the difference between using receive() method of TopicSubscriber and using a MessageListener to read the messages?
Wednesday, July 24, 2002 05:47 AM
You are correct. A TopicSubscriber can receive messages synchronously while implementations of MessageListener (like MDB) will receive messages asynchronously. Their usage is pretty clear - it depends on how you want your message consumer to behave or its lifetime. If you want to receive messages synchronously (block till a message comes along/timeout if dos not come within certain time) use TopicSubscriber OR asynchronously (do something with the message whenever it comes along) use MessageListener. Rule of thumb is that if you are not sure how soon or when a message may come along, use MessageListener. Otherwise if you are sure a message will come along (request/response kind of scenario) use TopicSubscriber