Creating JMS-Administered Objects
JMS defines a generic interface for sending and receiving messages with any JMS-compliant messaging provider. The JMS interfaces for point-to-point messaging are:
- javax.jms.QueueConnection: This interface provides a connection to a JMS provider and is used to create session objects.
- javax.jms.QueueSession: This interface provides context for producing and consuming messages, including the methods used to create QueueSender and QueueReceiver.
- javax.jms.QueueSender: This interface is used to send messages to a queue.
javax.jms.QueueReceiver: This interface is used to receive messages from a queue.
To make your code portable across different messaging providers, you must write your applications to the standard JMS interfaces in javax.jms. All vendor-specific information is encapsulated in implementations of javax.jms.QueueConnectionFactory and javax.jms.Queue. These administered objects can be built using a vendor-supplied administration tool and stored in a JNDI namespace. A JMS application can retrieve these objects from the namespace and use them without needing to know which vendor provided the implementation.
Follow these steps to use Websphere MQ Explorer to create the administered objects and store them in a file-based directory:
- Right-click JMS-Administered Objects → Add Initial Context.
- On Screen 1:
- Select "File System" for "Where is the JNDI located."
- For the Bindings directory, browse to C:\JNDI-Directory (The directory has to exist).
- Keep note of the factory class and provider URL; you will use it in the Java code (see Figure 5).
|Figure 5. Add Initial Context Wizard: You will use the factory class and provider URL in the sample code.|
- Click Finish.
- Your Explorer now should look like Figure 6.
|Figure 6. MQ Explorer After Adding Initial Context: You can easily create JMS-administered objects in MQ Explorer.|
Under the new initial context, create a Connection Factory:
- Right-click Connection Factories → New → Connection Factory. On the first screen, enter "TestQM_QCF" in the name field and click Next. You will use TestQM_QCF in the JNDI lookup.
- Set the type to "Queue Connection Factory" (see Figure 7) and click Next.
|Figure 7. New Connection Factory Wizard, Page 2: The Queue Connection Factory is used in point-to-point messaging.|
- Keep the transport type as Bindings and click Next. Binding transport works when WMQ and the application are on the same machine.
- Click Next on the next page (no changes).
- On the last page, select the connection tab (on the right), and then click the "select" button to select TestQM as "Base queue manager" (see Figure 8).
|Figure 8. New Connection Factory Wizard, Last Step: The Connection Factory is a wrapper TestQM.|
- Click "Finish".
Next, you create Destinations, JMS-administered objects corresponding to WMQ queues:
- Right-click destinations, and select New → Destination.
- On the first page, enter INInputTestQueue in the name field and make sure the type is set to queue (see Figure 9). Click Next.
|Figure 9. New Destination Wizard, Page1: You will use InputTestQueue to look up IN.QUEUE.|
- Keep the second wizard page as is and click Next.
- On the last page:
- In the Queue manager field, click the "select" button to select TestQM.
- In the Queue field, click the "select" button to select IN.QUEUE.
- Click Finish.
Repeat the above steps to create another destination: OutputTestQueue, which corresponds to OUT.QUEUE.