Life Cycle of a JMS Application

Now you will look at the life cycle of a typical JMS sender or receiver application:

  1. Look up the Queue and QueueConnectionFactory objects registered in the naming service. Initialize the InitialContext object and connect to the JMS provider in order to obtain the Queue and QueueConnectionFactory objects.

  2. After obtaining the QueueConnectionFactory object, both the JMS sender and receiver create a QueueConnection object.

  3. Both the sender and receiver applications create a session. The QueueSession object is the primary class that will be used in the remaining steps of the life cycle of JMS sender and receiver applications.

Now the implementations of the sender and receiver applications start diverging. The sender's steps are introduced first and then the client's steps.

  1. A sender application must create a QueueSender object from the QueueSession object. The sender must be created using the createSender() method of the QueueSession object. The createSender() method takes the Queue object to which the message is to be sent by the sender. This Queue object is the one that was retrieved in the first stage.

  2. The sender application creates a message to be sent using createXYZMessage(), where XYZ stands for the type of message (for example, a text message or a binary message).

  3. After creating the message and packaging the data using the setXXX() methods of the Message object, the sender application sends the message using the send() method of the QueueSender object. The send() method takes the message object created in the previous step and sends the message to the queue. The final step for the queue sender application is to close the queue connection and free up resources by calling the close() method of the QueueConnection object.

Now look at the steps the queue client application has to take after creating the QueueSession object:

  1. A receiver application must create a QueueReceiver object from the QueueSession object. The receiver must be created using the createReceiver() method of the QueueSession object. The createReceiver() method takes the Queue object to which the message is to be sent by the sender. This Queue object is the one that was retrieved in the first stage.

  2. Before receiving messages, the receiver must invoke the start() method of the QueueConnection object.

  3. Read the messages from the queue. Depending on the type of message that is to be received, the receiver application uses the receive() method of the QueueReceiver object. The receive() method returns a Message object, which is then typecast to its correct type after verifying the message type using the instanceof operator. The data within the message is extracted using the getXXX() methods of the Message object. Finally, the queue receiver application frees up the resources held by the queue connection by invoking the close() method of the QueueConnection object.

In the next section, you will study how to configure destinations in WebLogic Server.



Sams Teach Yourself BEA WebLogic Server 7. 0 in 21 Days
Sams Teach Yourself BEA WebLogic Server 7.0 in 21 Days
ISBN: 0672324334
EAN: 2147483647
Year: 2002
Pages: 339

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