Programming with IBM MQ classes for JMS with a Liberty JVM server

To use JMS in your CICS Java application to exchange messages with IBM MQ, you have two options. You can either use a message-driven bean (MDB) that receives incoming messages from an IBM MQ queue manager or a servlet that uses a JMS connection factory to send and receive JMS messages.

Using a JMS connection factory

For a tutorial that shows how to develop this type of application, see CICS Developer Center: Developing an MQ JMS application for CICS Liberty. It includes links to a sample servlet and supporting code that you can download.

Figure 1. Accessing IBM MQ through a Java application that uses JMS connection factory
Diagram showing access to MQ through a java application that uses a JMS connection factory

Using message-driven beans (MDBs)

In this form of programming, the onMessage() method in the MDB is invoked when a message arrives on the queue that is associated with the MDB. A javax.jms.Message object is then passed as input to the MDB for further processing. An MDB is a type of EJB, so it can use either container-managed or bean-managed Java transactions

CICS Developer Center: Developing an MQ JMS application for CICS Liberty in the CICS developerCenter is a tutorial of how to develop this kind of application. It includes links to a sample servlet and supporting code that you can download.

Figure 2. Accessing IBM MQ through a Java application that uses MDBs
Diagram showing access to MQ through a java application that uses MDBs

JMS programming considerations (Liberty JVM server)

  • Any work submitted to the CICSExecutorService using the runAsCICS() method that work must not include any JMS requests.
  • The CICS transaction ID under which the MDB request runs defaults to CJSU, which is the JVM server unclassified request processor. This can be modified per JVM server using the system property com.ibm.cics.jvmserver.unclassified.tranid.
  • When you use JMS in a Liberty JVM server, messages sent and received by the IBM MQ classes for JMS are coordinated using the Liberty Transaction Manager. For updates to recoverable resources that are managed by CICS to be coordinated in the same unit-of-work, the application must use the Java Transaction API (JTA), either explicitly through the UserTransaction.begin() method or implicitly using an EJB container-managed transaction. To complete a UOW, use the UserTransaction commit() or rollback() methods. Using the EXEC CICS SYNCPOINT command (in a mixed-language application), or the commit() and rollback() methods on the following objects to commit or roll back the UOW is not supported:
    • javax.jms.Session (JMS 1.1 API)
    • javax.jms.JmsContext (JMS 2.0 API)
    • com.ibm.cics.server.Task
    For more information about JTA, see Java Transaction API (JTA).