RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Tap Into WebSphere MQ Messaging Using the JMS Interfaces You Already Know : Page 3

Utilize the power of IBM WebSphere MQ messaging middleware by writing your applications to the Java Messaging Services open interface.


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:
  1. javax.jms.QueueConnection: This interface provides a connection to a JMS provider and is used to create session objects.
  2. javax.jms.QueueSession: This interface provides context for producing and consuming messages, including the methods used to create QueueSender and QueueReceiver.
  3. javax.jms.QueueSender: This interface is used to send messages to a queue.
  4. 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:

  1. Right-click JMS-Administered Objects → Add Initial Context.
  2. 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).

      Click to enlarge
      Figure 5. Add Initial Context Wizard: You will use the factory class and provider URL in the sample code.
    • Click Finish.
  3. Your Explorer now should look like Figure 6.

    Click to enlarge
    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:

  1. 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.
  2. Set the type to "Queue Connection Factory" (see Figure 7) and click Next.

    Click to enlarge
    Figure 7. New Connection Factory Wizard, Page 2: The Queue Connection Factory is used in point-to-point messaging.
  3. Keep the transport type as Bindings and click Next. Binding transport works when WMQ and the application are on the same machine.
  4. Click Next on the next page (no changes).
  5. 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).

    Click to enlarge
    Figure 8. New Connection Factory Wizard, Last Step: The Connection Factory is a wrapper TestQM.
  6. Click "Finish".

Next, you create Destinations, JMS-administered objects corresponding to WMQ queues:

  1. Right-click destinations, and select New → Destination.
  2. On the first page, enter INInputTestQueue in the name field and make sure the type is set to queue (see Figure 9). Click Next.

    Click to enlarge
    Figure 9. New Destination Wizard, Page1: You will use InputTestQueue to look up IN.QUEUE.
  3. Keep the second wizard page as is and click Next.
  4. 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.
  5. Click Finish.

Repeat the above steps to create another destination: OutputTestQueue, which corresponds to OUT.QUEUE.

Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date