Message-Driven Beans (MDBs)
Contents
Overview
WAS supports asynchronous messaging using MDBs, which are used to delegate incoming messages to enterprise beans.
The message listener service uses MDBs, with one MDB roughly equivalent to one listener port session, where each session represents a connection to a queue destination or a topic destination.
For example, for each message arriving on an MQ queue, the listener port session passes the message to a new instance of a user-developed MDB for processing. The listener gets the next message without waiting for the MDB to return.
A connection factory is used to create connections with the JMS provider for a specific queue or topic destination.
If you are using the WebSphere MQ JMS, any messages posted to MQ queues are automatically read in by the listeners, with no polling required by the application or container.
Messages arriving at a destination being processed by a listener have no client credentials associated with them; the messages are anonymous. Security depends on the role specified by the RunAs Identity for the MDB.
Each listener completes several steps for the JMS destination that it is to monitor, including...
- Creating a session pool, and allocating sessions and session threads for incoming messages.
- Interfacing with JMS ASF to create connection consumers to listen for incoming messages.
- If specified, starting a transaction and requesting that it is committed (or rolled back) when the EJB method has completed.
- Processing incoming messages by invoking the onMessage() method of the specified enterprise bean.
Transaction support
If transaction handling is specified for a JMS destination, the listener starts a global transaction before it reads any incoming message from that destination. When the MDB processing has finished, the JMS listener commits or rolls back the transaction. See JTA transaction control for more information.
If the processing of a message causes the transaction to be rolled back, then the message that caused the bean instance to be invoked is left on the JMS destination. Configure Maximum retries and backout queues to prevent the listener port from stopping due to bad messages.
Configure the message listener service to use MDBs
To configure resources needed by the message listener service to support MDBs...
- Configure the message listener service
- Add a new listener port
- Configure a listener port
- For each MDB, configure deployment attributes to match the listener port definitions
- Configure security for MDBs
- Install the app.
Deploy an enterprise application to use MDBs
To deploy an enterprise application to use MDBs, complete the following steps...
- Add a new listener port.
- For each MDB in the application, configure the deployment attributes to match the listener port definitions
- Install the application.
Important files for MDBs and extended messaging
The following files in the WAS_HOME/temp directory are important for the operation of the WAS messaging service, so should not be deleted. If you do need to delete the WAS_HOME/temp directory or other files in it, ensure that you preserve the following files.
server-durableSubscriptions.ser If you uninstall an application that contains a MDB, this file is used to unsubscribe the durable subscription.
server-AsyncMessageRequestLog.ser Used to keep track of late responses that need to be delivered to the late response message handler for the extended messaging provider.
Troubleshoot
- Check for messages about MDBs in...
$WAS_HOME/logs/server/SystemOut.log- Check that listener ports are turned on.
- Check for problems with the WebSphere Messaging functions.
- Enable Diagnostic trace for the "Messaging" group.
- Configure applications to generate MQ JMS Linked Exceptions
We need to get the underlying MQ return code that caused the MQJMS exception to be thrown. This is called the "linked exception." For example, if the comp code is 2, reason code 2059, then we know that the JMS exception was thrown as a result of the "Queue manager unavailable" reason code.
In order to have this output produced in the stack trace, implement the following code in JMS application.
catch (JMSException jmse) { System.out.println(jmse); Exception le = jmse.getLinkedException(); if (le != null) le.printStackTrace(); }- Check the Release Notes
- Configure MQ JMS Trace
To configure MQ JMS Trace go to...
Servers | Application Servers | Server_Name | Process Definition | Java Virtual Machine | Custom Properties...and set...
java -DMQJMS_TRACE_LEVEL=base myJMSAppIf the JMS application is started as servlet the above will not work. In this case you can invoke trace from within the source code. For example...
com.ibm.mq.jms.services.ConfigEnvironment.start(); com.ibm.mq.jms.services.ConfigEnvironment.start(String level); com.ibm.mq.jms.services.ConfigEnvironment.stop(); java.util.Properties.props = System.getProperties(); props.put("MQJMS_TRACE_DIR", "path/to/trace/directory"; System.setProperties(props);The filename is fixed to mqjms.trc - only the directory can be modified in this manner.
- Configure MQ trace
- ps -ef > pid1.out
- ipcs -a > ipcs1.out
- strmqtrc -t all -t detail -m QmgrName
- Recreate the error
- ipcs -a > ipcs2.out
- endmqtrc -a
- ps -ef > pid2.out
Trace files are written to...
/var/mqm/trace/AMQXXXXX.TRCTo read, the trace files need to be formatted...
dspmqtrc filename
Configure security for MDBs
Messages arriving at a listener port have no client credentials associated with them. The messages are anonymous. To call secure enterprise beans from an MDB, configure the RunAs Identity.
JMS connections used by MDBs can benefit from the added security of using J2C container-managed authentication defined on the connection factory definition. To set...
- Display the listener port settings...
Servers | application_server | Message Listener Service | Listener Ports | listener_port- Get the name of the connection factory by looking at the Connection factory JNDI name property.
- Display the JMS connection factory properties....
Resources | WebSphere MQ JMS Provider | WebSphere Queue Connection Factories | connection_factory- Set the Container-managed Authentication Alias property.
- Click OK