Use the IBM MQ classes for JMS sample applications
The IBM MQ classes for JMS sample applications provide an overview of the common features of the JMS API. You can use them to verify your installation and messaging server set up and to help you build your own applications.
For help to create your own applications, we can use the sample applications as a starting point. Both the source and a compiled version are provided for each application. Review the sample source code and identify the key steps to create each required object for the application (ConnectionFactory, Connection, Session, Destination, and a Producer, or a Consumer, or both), and to set any specific properties that are needed to specify how we want the application to work. For more information, see Writing IBM MQ classes for JMS applications. The samples might be subject to change in future releases of IBM MQ.
Table 1 shows where the IBM MQ classes for JMS sample applications are installed on each platform:Platform | Directory |
---|---|
UNIX Linux |
MQ_INSTALLATION_PATH/samp/jms/samples |
Windows | MQ_INSTALLATION_PATH\tools\jms\samples |
IBM i | /qibm/proddata/mqm/java/samples/jms/samples |
z/OS | MQ_INSTALLATION_PATH/java/samples/jms |
Name of sample | Description |
---|---|
JmsBrowser.java | A JMS queue browser application that looks at all available messages on the named queue, without removing them, in the order they would be received by a consumer application. |
JmsConsumer.java | A JMS queue browser application that looks at all available messages on the named queue, without removing them, in the order they would be received by a consumer application, by looking up the connection factory instance and the destination instance in an initial context (This sample supports file system context only). |
JmsJndiConsumer.java | A JMS consumer (receiver or subscriber) application that receives a message from the named destination (queue or topic) by looking up the connection factory instance and the destination instance in an initial context (This sample supports file system context only). |
JmsJndiProducer.java | A JMS producer (sender or publisher) application that sends a simple message to the named destination (queue or topic) by looking up the connection factory instance and the destination instance in an initial context (This sample supports file system context only). |
JmsProducer.java | A JMS producer (sender or publisher) application that sends a simple message to the named destination (queue or topic). |
/interactive/ | |
SampleConsumerJava.java | Receive message(s) from a topic/queue. |
SampleProducerJava.java | Send message(s) to a topic/queue. |
/interactive/helper/ | |
BaseOptions.java | An abstract class that can be extended to provide user option(s) functionality. |
IsValidType.java | Abstract class for validity checker classes. |
JmsApp.java | An abstract class that can be extended to provide consumer/producer functionality. |
Keys.java | A set of keys that define options for the sample applications. |
Literals.java | A set of constant literals. |
MyContext.java | The context in which options are presented. |
Options.java | Provides functionality for user option(s). |
OptionsPresenter.java | Context in which current options are presented. |
/simple/ | |
SimpleAsyncPutPTP.java | A simple application for point-to-point messaging; message is sent asynchronously (also known as fire-and-forget messaging). No messages are received. |
SimpleDurableSub.java | A simple application that demonstrates durable subscription facility. |
SimpleJNDILookup.java | A minimal and simple application that demonstrates lookup of JMS objects using the initial context. No connection to the queue manager is made and no messages are sent or received. |
SimpleMQMDRead.java | A simple application that demonstrates how a JMS application may avail MQ Message Descriptor (MQMD) fields as JMS message properties. No messages are sent; it is assumed that the queue in use is populated with some messages. |
SimpleMQMDWrite.java | A simple application that demonstrates how a JMS application may write MQ Message Descriptor (MQMD) fields. No messages are received. |
SimplePTP.java | A minimal and simple application for point-to-point messaging. |
SimplePubSub.java | A minimal and simple application for publish-subscribe messaging. |
SimpleReadAheadPTP.java | A simple application for point-to-point messaging; messages are streamed from the queue manager (also known as the read-ahead facility). No messages are sent; it is assumed that the queue in use is populated with some messages. |
SimpleRequestor.java | A simple application that uses a requestor to send a request message and then wait for, and receive, the reply. Note: It is assumed that some other application will process the request message and send the reply message. |
SimpleResponder.java | A simple application that listens on a destination for a message and then sends a reply to the message's replyTo destination. The application is written to operate in conjunction with the SimpleRequestor sample. |
SimpleRetainedPub.java | A simple application that demonstrates a retained publication. No messages are received. |
SimpleWMQJMSPTP.java | A minimal and simple application for point-to-point messaging. |
SimpleWMQJMSPubSub.java | A minimal and simple application for publish/subscribe messaging. |
The IBM MQ classes for JMS provide a script called runjms that can be used to run the sample applications. This script sets up the IBM MQ environment to allow you to run the IBM MQ classes for JMS sample applications.
Table 3 shows the location of the script on each platform:Platform | Directory |
---|---|
UNIX Linux |
MQ_INSTALLATION_PATH/java/bin/runjms |
Windows | MQ_INSTALLATION_PATH\java\bin\runjms.bat |
IBM i |
/qibm/proddata/mqm/java/bin/runjms or /qibm/proddata/mqm/java/bin/runjms64 |
z/OS | MQ_INSTALLATION_PATHjava/bin/runjms |
To use the runjms script to invoke a sample application, complete the following steps:
Procedure
- Bring up a command prompt and navigate to the directory containing the sample application that we want to run.
- Enter the following command:
Path to the runjms script/runjms sample_application_name
The sample application displays a list of parameters that it needs. - Enter the following command to run the sample with these parameters:
Path to the runjms script/runjms sample_application_name parameters
Example
For example, to run the JmsBrowser sample on Linux, enter the following commands:cd /opt/mqm/samp/jms/samples /opt/mqm/java/bin/runjms JmsBrowser -m QM1 -d LQ1Parent topic: Installing and configuring IBM MQ classes for JMS
Related concepts