Generic JMS usage

 

Putting a message onto a message queue using JMS requires a number of components. The figure below depicts how the PingServletToMDBQueue servlet places a message on a queue.

For this example the following are needed:

  1. JNDI Name service

  2. Queue Connection Factory (QCF)

    Encapsulates the settings necessary to connect to a queue-based messaging system.

  3. Queue destination

    A reference to the point-to-point messaging queue.

  4. Queue manager

    A queue manager is a WebSphere MQ term. It refers to the component that is responsible for looking after a number of queues within one install of WebSphere MQ server.

  5. A message queue

    The actual queue where messages are held until removed by an application.

 

Component interactions to send a message using JMS



  1. The servlet is invoked by the user and the doGet method is called by the Web container.

  2. The application needs to locate the correct queue to place the message on. The JNDI namespace is used to house a link to the Java objects that will perform communication with the messaging system. The PingServletToMDBQueue servlet uses resource references within the code. These are linked at application deployment time to the JNDI entries that can be used to communicate with the messaging system.

  3. The code performs a JNDI lookup for the queue connection factory using the resource reference.

  4. The resource reference is matched to the JNDI entry that contains the queue connection factory. The queue connection factory (QCF) object is returned, it will be used to get a connection to the queue manager that is responsible for the target queue.

  5. A second JNDI lookup is performed and resolved to the correct JNDI entry . This time it is for the queue destination, this will be used to locate the required queue from the queue manager.

  6. To be able to communicate with the queue in the messaging system, the application must first create a QueueConnection from the QCF object. WAS maintains a pool of QueueConnection objects per QCF for use by any application in the appserver. This request to create a new QueueConnection will obtain an existing QueueConnection from this pool if there are any available, otherwise one will be created and added to the pool.

  7. When using the Embedded JMS server or WebSphere MQ as the underlying messaging system, the creation of the QueueConnection will attempt a physical connection with the queue manager to verify that it is available.

  8. The next step is to create a QueueSession object using the QueueConnection method - createQueueSession. This is the stage where a physical connection will be established to the queue manager which will eventually be used to transmit the message to the queue. WAS maintains a pool of QueueSession objects for each established QueueConnection on the QCF. This request to create a new QueueSession will obtain an existing QueueSession from this pool if there are any available, otherwise one will be created and added to the pool.

  9. With a connection now established to the messaging system through the QueueSession object, the application now specifies what sort of action is going to be performed, in this case it is to send a message. The queue definition that was taken from the JNDI name service is passed to the QueueSession object and this tells the queue manager the specific queue on to which the message will be placed.

  10. The message is constructed and sent to the message queue.

 Prev | Next

 

WebSphere is a trademark of the IBM Corporation in the United States, other countries, or both.

 

IBM is a trademark of the IBM Corporation in the United States, other countries, or both.