




![[image]](http://mowser.com/img?url=http%3A%2F%2Fi.cmpnet.com%2Fddj%2Fblank.gif)
![[image]](http://mowser.com/img?url=http%3A%2F%2Fi.cmpnet.com%2Fddj%2Fddj%2Fimages%2Fdotted_line3.gif)
Del.icio.us
Digg
Google
Furl
Slashdot
Y! MyWeb
BlinkThe reader application performs many of the same steps as the sender in terms of initializing its JMS connection and session. The differences are:
Once initialized, the application is free to continue with its own processing. In the case of an actual e-mail client application, this may involve letting users compose new e-mail messages, organize existing e-mail into folders, and so on. The provider eventually calls back on the application's MessageListener object when a new message arrives. This is the way JMS implements asynchronous messaging, which lets the client application perform other tasks while waiting for messages to arrive.
JMS also supports synchronous messaging, which requires the client application (or one of its child threads) to block until a message arrives. This type of an application is strictly an event-driven application, meaning it cannot do anything unless certain events occur; a JMS message arrival, in this case. This type of application can be developed to respond differently to different messages received, and can in effect be driven remotely by sending it the proper messages in the proper order.
Again, the setMessageListener method was called with a reference to an object that implements the MessageListener interface. Because of this, once the JMS connection is started, the provider asynchronously calls the client application's onMessage method when a message arrives for the destination the consumer is listening to; see the EmailReader class's implementation of onMessage (available electronically). The javax.jms.Message object is provided as a parameter to the onMessage method, representing the received JMS message. Once the message is cast to a javax.jms.ObjectMessage object, the Email POJO is then extracted via a call to getObject. For illustrative purposes, the remainder of the code simply prints out the e-mail's subject and body (see Figure 5).
When this application is executed, it receives all of the messages, one by one, that were placed on the queue earlier by the e-mail sender application. Once all of the messages have been received, the application simply waits to be notified that another message has been placed on the queue.
Writing JMS client applications is straightforward once you understand the basics. The power of JMS is in the ability to leverage built-in transaction management, and reliable message delivery, without knowing much more than the basics.
Previous Page | 1 What Is Messaging? | 2 JMS Message Paradigms | 3 Sample E-mail Sender Application | 4 Sample E-mail Reader Application
![[image]](http://mowser.com/img?url=http%3A%2F%2Fi.cmpnet.com%2Fddj%2Fblank.gif)
![[image]](http://mowser.com/img?url=http%3A%2F%2Fi.cmpnet.com%2Fddj%2Fimages%2Fblank.gif)
![[image]](http://mowser.com/img?url=http%3A%2F%2Fi.cmpnet.com%2Fddj%2Fimages%2Fblank.gif)
![[image]](http://mowser.com/img?url=http%3A%2F%2Fi.cmpnet.com%2Fddj%2Fimages%2Fblank.gif)
![[image]](http://mowser.com/img?url=http%3A%2F%2Fi.cmpnet.com%2Fddj%2Fimages%2Fblank.gif)
![[image]](http://mowser.com/img?url=http%3A%2F%2Fi.cmpnet.com%2Fddj%2Fimages%2Fblank.gif)
![[image]](http://mowser.com/img?url=http%3A%2F%2Fi.cmpnet.com%2Fddj%2Fimages%2Fblank.gif)
![[image]](http://mowser.com/img?url=http%3A%2F%2Fi.cmpnet.com%2Fddj%2Fimages%2Fblank.gif)
![[image]](http://mowser.com/img?url=http%3A%2F%2Fi.cmpnet.com%2Fddj%2Fimages%2Fblank.gif)
![[image]](http://mowser.com/img?url=http%3A%2F%2Fi.cmpnet.com%2Fddj%2Fimages%2Fblank.gif)
![[image]](http://mowser.com/img?url=http%3A%2F%2Fi.cmpnet.com%2Fddj%2Fimages%2Fblank.gif)
![[image]](http://mowser.com/img?url=http%3A%2F%2Fi.cmpnet.com%2Fddj%2Fimages%2Fblank.gif)
![[image]](http://mowser.com/img?url=http%3A%2F%2Fi.cmpnet.com%2Fddj%2Fimages%2Fblank.gif)
![[image]](http://mowser.com/img?url=http%3A%2F%2Fi.cmpnet.com%2Fddj%2Fimages%2Fblank.gif)




You are viewing a mobilized version of this site...
View original page here