Using the IBM MQ JMS extensions
IBM® MQ classes for JMS contains a set of extensions to the JMS API called the IBM MQ JMS extensions. An application can use these extensions to create connection factories and destinations dynamically at run time, and to set the properties of connection factories and destinations.
import com.ibm.jms.*;
import com.ibm.mq.jms.*;
- Create connection factories and destinations dynamically at run time, instead of retrieving them as administered objects from a Java Naming and Directory Interface (JNDI) namespace
- Set the properties of connection factories and destinations
Creating connection factories
MQConnectionFactory factory = new MQConnectionFactory();
This
statement creates an MQConnectionFactory object with the default values
for all its properties, which means that the application connects
to the default queue manager in bindings mode. If you want an application
to connect in client mode, or connect to a queue manager other than
the default queue manager, the application must set the appropriate
properties of the MQConnectionFactory object before creating the connection.
For information about how to do this, see Setting the properties of connection factories.
- MQQueueConnectionFactory
- MQTopicConnectionFactory
- MQXAConnectionFactory
- MQXAQueueConnectionFactory
- MQXATopicConnectionFactory
Setting the properties of connection factories
An application can set the properties of a connection factory by calling the appropriate methods of the connection factory. The connection factory can either be an administered object or an object created dynamically at run time.
MQConnectionFactory factory = new MQConnectionFactory();
.
factory.setTransportType(WMQConstants.WMQ_CM_CLIENT);
factory.setQueueManager("QM1");
factory.setHostName("HOST1");
factory.setPort(1415);
factory.setChannel("QM1.SVR");
This code creates an MQConnectionFactory
object and then sets five properties of the object. The effect of
setting these properties is that the application connects to queue
manager QM1 in client mode using an MQI channel called QM1.SVR. The
queue manager is running on a system with host name HOST1, and the
listener for the queue manager is listening in port number 1415.
MQConnectionFactory factory = new MQConnectionFactory();
.
factory.setTransportType(WMQConstants.WMQ_CM_DIRECT);
factory.setHostName("HOST2");
factory.setPort(1507);
This code assumes that the broker
is running on a system with host name HOST2 and listening on port
number 1507.
An application that uses a real-time connection to a broker can use only the publish/subscribe style of messaging. It cannot use the point-to-point style of messaging.
Only certain combinations of properties of a connection factory are valid. For information about which combinations are valid, see Dependencies between properties of IBM MQ classes for JMS objects.
For more information about the properties of a connection factory, and the methods used to set its properties, see Properties of IBM MQ classes for JMS objects.
Creating destinations
MQQueue q1 = new MQQueue("Q1");
This
statement creates an MQQueue object with the default values for all
its properties. The object represents an IBM MQ queue called Q1 that belongs to the local queue manager. This queue can be a local queue, an alias queue, or a remote queue definition.
MQQueue q2 = new MQQueue("QM2", "Q2");
The
MQQueue object created by this statement represents an IBM MQ queue called Q2 that is owned by queue manager QM2. The queue manager identified in this way can be the local queue manager or a remote queue manager. If it is a remote queue manager, IBM MQ must be configured so that, when the application sends a message to this destination, Websphere MQ can route the message from the local queue manager to the remote queue manager.
MQQueue q3 = new MQQueue("queue://QM3/Q3?persistence=2&priority=5");
The
MQQueue object created by this statement represents an IBM MQ queue called Q3 that is owned by queue manager QM3, and all messages sent to this destination are persistent and have a priority of 5. For more information about queue URIs, see Uniform resource identifiers (URIs). For an alternative way of setting the properties of an MQQueue object, see Setting the properties of destinations.
MQTopic t1 = new MQTopic("Sport/Football/Results");
This
statement creates an MQTopic object with the default values for all
its properties. The object represents a topic called Sport/Football/Results.
MQTopic t2 = new MQTopic("topic://Sport/Tennis/Results?persistence=1&priority=0");
The
MQTopic object created by this statement represents a topic called
Sport/Tennis/Results, and all messages sent to this destination are
nonpersistent and have a priority of 0. For more information about
topic URIs, see Uniform resource identifiers (URIs). For an alternative way of setting the properties of an MQTopic object, see Setting the properties of destinations.
Setting the properties of destinations
An application can set the properties of a destination by calling the appropriate methods of the destination. The destination can either be an administered object or an object created dynamically at run time.
MQQueue q1 = new MQQueue("Q1");
.
q1.setPersistence(WMQConstants.WMQ_PER_PER);
q1.setPriority(5);
This code creates an MQQueue object
and then sets two properties of the object. The effect of setting
these properties is that all messages sent to the destination are
persistent and have a priority of 5.
MQTopic t1 = new MQTopic("Sport/Football/Results");
.
t1.setPersistence(WMQConstants.WMQ_PER_NON);
t1.setPriority(0);
This code creates an MQTopic object
and then sets two properties of the object. The effect of setting
these properties is that all messages sent to the destination are
nonpersistent and have a priority of 0.
For more information about the properties of a destination, and the methods used to set its properties, see Properties of IBM MQ classes for JMS objects.