Set Up Your Own Publish/Subscribe Use Case
In this section, you will create a publish/subscribe setup resembling part of the use case in Figure 3
. You will create a publisher for the news topic and two subscriptions for the email and SMS applications using the following procedure:
- Create a queue manager.
- Create a news topic.
- Create subscription queues.
- Create subscriptions.
- Create Java Messaging Services (JMS)-administered objects.
- Write publisher and subscriber classes.
- Run the classes.
This tutorial uses MQ Version 7 on Windows XP. (Download a trial version from the IBM web site.) Installation on Windows is straightforward. Just keep all the default values as you go through the installation wizard, but be sure to perform the installation as a user from the administrators group.
Don't worry if you haven't used WMQ before. You will use the Eclipse-based WebSphere MQ Explorer, an easy GUI for administering WMQ, to perform basic definitions.
Start WebSphere MQ Explorer as follows: Start > All Programs > IBM WebSphere MQ > WebSphere MQ Explorer. If this is the first time you are starting MQ Explorer, a welcome screen will appear. Just close the welcome screen.
Create a Queue Manager
- In MQ Explorer's Navigator view, right-click Queue Managers and then select New > Queue Manager. This starts the "Create Queue Manager" wizard.
- On Step 1, enter TestQM as the queue manager name and then click Next (see Figure 4).
- Click Next on the wizard screens for Steps 2 and 3. At Step 4, make sure "Create listener configured for TCP/IP" is checked and the entered port number is free (see Figure 5), and then click Finish.
Figure 4. Create Queue Manager Wizard, Step 1: Enter the queue manager name.
Figure 5. Create Queue Manager Wizard, Step 4: Check the port number for the queue manager's listener.
Create a News Topic
- Under TestQM, right-click Topics and then select New > Topic to start the "New Topic" wizard.
- Type News.Topic as the topic name (see Figure 6). This represents the WMQ administrative object used to manage the topic. Click Next.
- On the topic properties page, type News in the "Topic string" field (see Figure 7). This string is used when creating JMS administered objects to refer to the News topic. Click Finish.
Figure 6. Create Topic, Step 1: Enter the topic's administrative object name.
Figure 7. Create Topic, Step 2: Enter the topic's string name.
Create Subscription Queues
Next, you will set up news publications to be delivered to Subscription queues. Create two queues for the email and SMS applications:
- Under TestQM, right-click Queues then select New > Local Queue to start the "New Local Queue" wizard.
- In the name field, type Email.Queue and click Finish.
- Repeat the above steps to create another queue called SMS.Queue.
In order to receive a topic's publications, subscribers have to register interest in the topic. They use subscriptions to accomplish this. You can can create subscriptions programmatically or through MQ Explorer. Through the following steps, you will create two subscriptions using MQ Explorer:
- Under TestQM, right-click Subscriptions and then select New > Subscription to start the "New Subscription" wizard.
In the name field, type EmailSubscription and click Next (see Figure 8).
- In the "Change properties" page, press the Select button next to the "Topic name" and then select News.Topic from the displayed topics list. Press OK. On the same page, type Email.Queue in the destination name field (see Figure 9). Click Finish.
Figure 8. Create Subscription, Step 1: Enter the subscription name.
Figure 9. Create Subscription, Step 2: Select topic and enter subscription queue.
- Repeat the above steps to create another subscription called SMSSubscription with the topic set to News.Topic and the destination name set to SMS.Queue.