Publish/Subscribe Messaging Can Be Simple with WebSphere MQ : Page 3
Combine publish/subscribe messaging, JMS, and WebSphere MQ to build powerful message-oriented applications simply.
by Tareq Shaheen
May 29, 2009
Page 3 of 4
A Quick Test for Your Publish/Subscribe Setup
Perform the following to verify you have correctly completed the setup for the News topic:
Under TestQM, click Topics.
In the right pane, right click News.Topic and select "Test Publication" to open the test window.
In the message data field, type "publish/subscribe test" (or any other text), click the "Publish message" button, and then click the Close button. This should distribute the message to the subscriber queues Email.Queue and SMS.Queue.
Under TestQM, click Queues.
In the right pane, right click Email.Queue and select "Browse Messages." When the browse messages window opens, search the "Message Data" column for the text you entered. You should also see the same message in SMS.Queue.
Right click Email.Queue and select "Clear Messages." Click the Clear button in the "Clear queue" window. Do the same for SMS.Queue.
Create JMS-Administered Objects
JMS applications require you to wrap vendor-specific objects in JMS-administered objects. To store JMS-administered objects, create a file-based Java Naming and Directory Interface (JNDI) namespace. Start by adding a new initial context:
Right-click JMS-Administered Objects and then select Add Initial Context.
On Screen 1:
Select "File System" for "Where is the JNDI located."
For the Bindings directory, browse to C:\JNDI-Directory (This directory has to exist).
Keep note of the factory class and provider URL; you will use them in the Java code (see Figure 10).
Figure 10. Add Initial Context Wizard: You will use the factory class and provider URL in the sample class.
Next, create a JMS Connection factory and destinations under the Initial Context.
Create a Connection Factory
Right-click Connection Factories and then select New > Connection Factory. On the first screen, type TestQMConnectionFactory in the name field and click Next (see Figure 11). You will use TestQMConnectionFactory in the JNDI lookup.
Click Next on Step 2, Step 3, and Step 4.
On the last page, select the connection tab (on the left) and then click the Select button to select TestQM as "Base queue manager" (See Figure 12). Click Finish.
Figure 11. Create Connection Factory, Step1: Type a factory name.
Figure 12. Create Connection Factory, Final Step: Select TestQM as the base queue manager.
JMS destinations wrap WMQ topics and queues. Create a destination corresponding to the News topic:
Right-click destinations and select New > Destination to start the "New Destination" wizard.
In the first step, enter NewsTopic in the Name field and change the Type field to Topic (See Figure 13). Click Next.
Click Next on the second screen.
On the last page (Change properties), type News in the Topic field and then click Finish (See Figure 14). This is the topic string you defined when you created the News topic.
Figure 13. Create Topic Destination, First Step: Make sure you change the Type field to Topic.
Figure 14. Create Topic Destination, Final Step: Make sure you type News (not News.Topic).
Create two destinations corresponding to the subscriber queues:
Right-click destinations and then select New > Destination to start the new "Destination wizard."
In the first step, type EmailQueue in the Name field and then click Next.
Click Next on the second screen.
On the last page, click the Select button next to the "Queue Manager" field and select TestQM from the list.
Click the Select button next to the Queue field and select Email (See Figure 15). Queue from the list. Click Finish.
Repeat the above steps to create another Destination called SMSQueue for SMS.Queue. Your destinations should look like the ones in Figure 16.
Figure 15. Create Queue Destination, Last Step: Select queue manager and queue.
Figure 16. A Third Destination Called SMSQueue for SMS.Queue: You have created three destinations.