Synchronous Versus Asynchronous Messaging

   

A client can be set up to synchronously or asynchronously receive messages. With synchronous delivery, a client can request the next message from a MessageConsumer by using one of the receive methods . Three different receive methods can be used:

  • receive ” Receive the next message for this consumer

  • receive(long timeout) ” Receive the next message that arrives within the timeout interval

  • receiveNoWait ” Receive the next message if one is immediately available

A JMS consumer can also receive messages asynchronously. The client registers an object that implements the MessageListener interface with the JMS server. When messages arrive for a particular MessageConsumer that has a MessageListener registered, the messages are delivered to the onMessage method. This is the example that you saw in Listing 10.2.

Note

The JMS specification is very clear about the fact that the client that implements the onMessage method defined in the MessageListener interface should never throw a RuntimeException . If the onMessage method does happen to throw a RuntimeException , it's very unpredictable how the JMS server will react . It might consider the MessageListener to be confused and stop delivering messages to it. You should catch such exceptions and attempt to divert the message to some type of error handler instead.




Special Edition Using Enterprise JavaBeans 2.0
Special Edition Using Enterprise JavaBeans 2.0
ISBN: 0789725673
EAN: 2147483647
Year: 2000
Pages: 223

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net