JMS and Message Driven Beans
With message driven beans the appserver is now responsible for delivering the message to the application. The PingServletToMDBQueue servlet places a message on a queue associated to the JNDI name jms/TradeBrokerQueue. Within the default configuration that comes with Trade3, a listener port has been defined that monitors this queue. Any messages that arrive on the queue are passed to the TradeBrokerMDB that then processes them.
Components include Generic JMS usage:
- JNDI Name service
- Queue connection factory (QCF)
- Queue destination
- Queue manager
- A message queue
- Message listener service
The process within each WAS that is responsible for all its listener ports.
- Listener port
Method for linking an MDB with the correct connection factory and destination. The information in a listener port definition will be used to monitor a message queue. The JMS provider will then pass any messages that arrive on the queue to the MDB that is associated to the listener port.
- Message Driven Bean (MDB)
When a message arrives on a queue that is being monitored by a listener port, the onMessage method of its associated MDB is called and the MDB will consume that message.
Component interactions
1.
The MDB is associated to a listener port that is in turn associated to the correct queue. Upon initialisation the listener port performs a JNDI lookup for the QCF that is specified in the listener port configuration. The QCF object is returned, it will be used to get a connection to the queue manager that is responsible for the target queue.2.
The listener port will also do a JNDI lookup for the queue destination that it has been configured with. This will be used to locate the required queue from the queue manager.3.
Using the QCF, the listener port connects to the queue manager through a QueueConnection. 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.While the listener port is running, the QueueConnection it is using will not be available to any other application or listener port running with the appserver. It is only when the listener port is stopped that the QueueConnection it was using will be returned to the connection pool on the QCF.
4.
The listener port uses the QueueConnection to create a ConnectionConsumer object, which is used by the JMS provider to handle incoming messages. The listener port session calls the MDB, passing it the message.Upon startup of the listener port, one listener port session will be run. At the point a listener port session is created, a QueueSession is established to point at the queue the listener port is responsible for.
There is only one listener port session and therefore one QueueSession object in use in this example. You can change the maximum sessions.
This is the stage where a physical connection will be established to the queue manager which is used to monitor for the arrival of messages on the queue. WAS maintains a pool of QueueSession objects for each established QueueConnection. Each 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.
5.
The QueueSession is now established and is pointing at the correct queue. The listener port is initialized. Any messages arriving on the message queue will be picked up one at a time and processed by the correct MDB.6.
A message arrives on the queue.7.
As the listener port is ready to accept messages, it will take delivery of the message off the queue The listener port will then pass the message on to an instance of the MDB that it is associated with. The onMessage method is called on the MDB passing it the message.Using MDBs requires an understanding of many different areas. The application can be designed to use MDBs, but the way in which those MDBs behave can be significantly affected by the way in which its controlling components are configured - the message listener service and listener ports. Those are in turn affected by the underlying communication mechanisms to reach the messaging system, for example the number of QueueConnections and QueueSessions available on a QCF.
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.