Writing IBM MQ classes for JMS applications
After a brief introduction to the JMS model, this topic provides detailed guidance on how to write IBM MQ classes for JMS applications.
- The JMS model
The JMS model defines a set of interfaces that Java applications can use to perform messaging operations. IBM MQ classes for JMS, as a JMS provider, defines how JMS objects are related to IBM MQ concepts. The JMS specification expects certain JMS objects to be administered objects. JMS 2.0 introduces a simplified API, while also retaining the classic API, from JMS 1.1. - JMS messages
JMS messages are composed of a header, properties, and a body. JMS defines five types of message body. - Create and configure connection factories and destinations in an IBM MQ classes for JMS application
An IBM MQ classes for JMS application can create connection factories and destinations by retrieving them as administered objects from a Java Naming and Directory Interface (JNDI) namespace, by using the IBM JMS extensions, or by using the IBM MQ JMS extensions. An application can also use the IBM JMS extensions or IBM MQ JMS extensions to set the properties of connection factories and destinations. - Building a connection in a JMS application
To build a connection, a JMS application uses a ConnectionFactory object to create a Connection object and then starts the connection. - Create a session in a JMS application
To create a session, a JMS application uses the createSession() method of a Connection object. - Create destinations in a JMS application
Instead of retrieving destinations as administered objects from a Java Naming and Directory Interface (JNDI) namespace, a JMS application can use a session to create destinations dynamically at run time. An application can use a uniform resource identifier (URI) to identify an IBM MQ queue or a topic and, optionally, to specify one or more properties of a Queue or Topic object. - Send messages in a JMS application
Before a JMS application can send messages to a destination, it must first create a MessageProducer object for the destination. To send a message to the destination, the application creates a Message object and then calls the send() method of the MessageProducer object. - Receive messages in a JMS application
An application uses a message consumer to receive messages. A durable topic subscriber is a message consumer that receives all messages sent to a destination, including those sent while the consumer is inactive. An application can select which messages it wants to receive by using a message selector, and can receive messages asynchronously by using a message listener. - Retrieval of subscription user data
If the messages that an IBM MQ classes for JMS application is consuming from a queue are put by an administratively defined durable subscription, the application needs to access the user data information that is associated with the subscription. This information is added to the message as a property. - Closing down an IBM MQ classes for JMS application
It is important for an IBM MQ classes for JMS application to close certain JMS objects explicitly before stopping. Finalizers might not be called, so do not rely on them to free resources. Do not allow an application to terminate with compressed trace active. - Handling poison messages in IBM MQ classes for JMS
A poison message is one which cannot be processed by a receiving application. If a poison message is delivered to an application and rolled back a specified number of times, the IBM MQ classes for JMS can move it to a backout queue. - Logging errors in IBM MQ classes for JMS
Information about runtime problems that might require corrective action by the user is written to the IBM MQ classes for JMS log. - Exceptions in IBM MQ classes for JMS
An IBM MQ classes for JMS application must handle exceptions that are thrown by JMS API calls or that are delivered to an exception handler. - Accessing IBM MQ features from an IBM MQ classes for JMS application
IBM MQ classes for JMS provides facilities to exploit a number of features of IBM MQ. - XA support in IBM MQ classes for JMS
JMS supports XA-compliant transactions in bindings and client modes with a supported transaction manager within a JEE container. - Use JMS 2.0 functionality
JMS 2.0 introduces several new areas of functionality to the IBM MQ classes for JMS.
Parent topic: Use IBM MQ classes for JMS