Publish/Subscribe Messaging Overview
Publish/subscribe is the messaging oriented equivalent of the object-oriented observer design pattern. In publish/subscribe messaging, a sender application creates a message containing the information it wants to send and assigns it a topic that denotes the subject of the information. This message is called a publication. WMQ receives the publication, recognizes the topic, and then distributes the publication to interested applications.
Publisher (information producer)
In this component generates messages (publications) under a certain subject (topic) and sends the publications to a WMQ queue manager. A publisher knows nothing about the recipient(s) of the information.
Subscriber (information consumer/receiver)
In this component registers interest in a certain topic(s) with a WMQ queue manager. It also specifies its subscription queue name; that is, the queue where it wants to receive the messages related to this topic. The subscriber knows nothing about the information publishers(s). A publications router: In this component passes messages from publishers to topic subscribers. Earlier WMQ versions required a broker component on top of a queue manager to enable publish/subscribe. The broker maintained topics and subscriptions, and it routed publications. The queue manager is now responsible for topics, subscriptions, and routing publications.
Publish/subscribe access controls
A publish/subscribe system can have many publishers and many subscribers, and often, two or more queue managers communicating with one another. Also, an application can be both a publisher and a subscriber.
Publish/Subscribe using MQ Explorer
1.Create a Queue Manager:
2.Create the Queue manager name as ‘QM’.
3.Create a pub sub topic called ‘NEWS’ with topic string: NEWS, using WebSphere MQ Explorer.
Create a New Topic
1.Right-click on Topics and then select New –> Topic to start the “News” wizard.
2. Type “News” as the topic name. This represents the WMQ administrative object used to manage the topic.
3. Click Next.
4. On the topic properties page, type “News” in the Topic string field. This string is used to refer News topic.
5. Click on Finish.
6. Follow the below steps to create some more “Topics name” and “Topic Strings”.
- Right-click Topics and then select topic name NEWS.BUSINESS and topic string NEWS/BUSINES
- Right-click Topics and then select topic name NEWS.POLITICAL and topic string NEWS/POLITICAL.
- Right-click Topics and then select topic name NEWS.SPORTS and topic string NEWS/SPORTS
- Right-click Topics and then select topic name NEWS.SPORTS.CRICKET and topic string NEWS/SPORTS/CRICKET
- Right-click Topics and then select topic name NEWS.SPORTS.FOOTBALL and topic string NEWS/SPORTS/FOOTBALL
- Right-click Topics and then select topic name NEWS.SPORTS.FOOTBALL.CLUB NEWS/SPORTS/FOOTBALL/CLUB
Creating a Subscription Queue
Set up NEWS publications to be delivered to Subscription queues. Create two queues for the ‘NewsQ’ and ‘SportsQ’ applications.
Create a Subscription
In order to receive a topic’s publications, subscribers have to register interest in the topic. They use subscriptions to accomplish this.To create subscriptions pro-grammatically or through MQ Explorer follow the below steps.
In Queue manager “QM”, right click on Subscriptions—->New—> Subscription and name it as “Sub”.
Click on Next.
Click on ‘General’ option on the left panel, on the right hand side click on ‘Select’ button to select the Topic Name as showed above.
Click on “OK”
Define the Topic String based on the Topic name along with Destination Queue name.
Create the another Subscription name as ‘Sub2’ with same topic name and topic string as given in ‘Sub1’ define queue name as ‘SportsQ’ in ‘Sub2’.
Test for Publish/Subscribe Setup
Perform the following steps to verify you have correctly completed the setup for the News topic
- In Queue Manager ‘QM’, click on Topics.
- In the right panel, right click NEWS/SPORTS/FOOTBALL/CLUB.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 ‘NewsQ’ and ‘SprotsQ’.
- In Queue Manager QM, click on Queues.
- In the right panel, right click ‘NewsQ’ 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 ‘SprotsQ’.
Check out our Popular Articles