Skip to content

Simple PUB/SUB Example Using WebSphere Message Broker v7 and MQ v 7

by on September 13, 2013

1.  OVERVIEW PUB/SUB

The Pub/Sub design pattern is based on a scenario where clients (publishers) “publish” messages to topics.  Then one or more clients (subscribers) that are interested in that topic can “subscribe” to that topic.   Publishers and Subscribers are loosely coupled and are not aware of each other.   This is different than the point-to-point implementation where sender and receivers are tightly coupled at minimum from a connectivity standpoint.

Following is a very high-level illustration of Pub/Sub:

Sub_Pub

2.  OVERVIEW OF OUR WMB/MQ PUB/SUB SCENARIO

There are many ways to implement a Pub/Sub design pattern depending on your platform.  To illustrate a simple Pub/Sub example, this blog is going to focus on one simple technique using WMB v7 and MQ v7.   There are also other ways to implement this depending on what version of WMB you are using.   These other techniques will not be covered in this blog, but detailed information can be found in the MQ and WMB infocenters.

Our Simple Example is going to leverage a WMB message flow with an MQ Input Node to define what topic to put to and WMB Publication Node to publish to an MQ topic.   The example is then going to leverage MQ Subscriptions to subscribe to that topic and route the topic to specific MQ queues that subscribers can read from.

Section 3 will provide step by step implementation for setting up this example.

3.  STEP BY STEP FOR SETTING UP WMB/MQ PUB/SUB EXAMPLE

0.   Pre-reqs: Our scenario depends on the following MQ queues being defined.   Please create these  queues In MQ explorer or using runmqsc from command line before proceeding with the steps.

  • TT.XML.EXAMPLE.PUB – Input queue for publication message flow
  • TT.XML.EXAMPLE.INPUT – Input queue for one of our subscriber message flow
  • TT.XML.EXAMPLE.OUT – Output queue for one of our subscriber message flow
  • TT.XML.EXAMPLE.COPY – Queue for a second subscriber

1.   Create MQ topic

Go to MQ Explorer Topic folder and create a topic called TT_XML_EXAMPLE_TOPIC.  In this example, the topic string we will use to publish messages to is “TT_XML_EXAMPLE” You can also give a topic a hierarchical structure using “/”.   More information on this can be found in MQ infocenter document.

TT_XML_EXAMPLE_TOPIC

2.   Create WMB Publication Flow

Next, we need to build a WMB Message Flow to publish message to the MQ Topic we setup in step one.

To build your Publication Flow, you need 2 Nodes:

(1)   MQ Input Node that uses TT.XML.EXAMPLE.PUB queue and also has the “topic” property set to our Topic string(“TT_XML_EXAMPLE”) in the advance property tab on the MQ Input Node (see image below).

(2)   Publication Node – No properties should be set on this.   It will get the topic to publish to from MQ Input Node Topic property.

Once you deploy this message flow and it receives a message, it will start publishing messages to the topic.

Publication_Flow_Image

3.   Create Subscription to Topic

Now that we are publishing messages to a topic, we can have subscribers to subscribe to this topic.  To do this, we need to first create an MQ subscription in MQ Explorer.  In this example, we will call it “TT_XML_TO_COBOL_SUB” and setup the topic to use(TT_XML_EXAMPLE_TOPIC) and the destination to be an MQ queue called “TT.XML.EXAMPLE.INPUT”.   This will be the input to our subscriber message flow that we will create in step 4.

TT_XML_TO_COBOL_SUB

4.   Create Subscription Message Flow

For this blog, we will use our previous message flow (XML TO COBOL) where an XML message is mapped to a COBOL Output.   The implementation can be anything you want this subscriber to do with the message including any transformation, enrichment, and/or routing.

Subscription_Message_Flow_Image

5.   Create 2nd subscription to topic

For simple illustration purposes, we are going to create a second subscription to just get a copy of the message published to the topic.   To do this, go to MQ Explorer again and create an MQ Subscription called “TT_XML_COPY_SUB” using the same topic(TT_EXAMLE_XML_TOPIC) and the destination queue to be “TT.XML.EXAMPLE.COPY”

TT_XML_COPY_SUB

6.   Testing Simple Pub/Sub Example Scenario

For our scenario, we will use RFHUtil to put a test XML message to the input queue (TT.XML.EXAMPLE.PUB) of the publication message flow.

Original_InputMessage_Image

This XML will then get published to the topic (TT_EXAMPLE_XML_TOPIC).   Our two subscriptions will then receive this XML message and we will get the following respective outputs from our two subscriptions:

Output (Subscription 1):

1.  Subscription sends XML to destination queue TT.XML.EXAMPLE.INPUT. The subscription message flow will process the message and send COBOL formatted message to TT.XML.EXAMPLE.OUT queue.

Cobol_Output_Message

2.  The second subscription will send XML to destination queue TT.XML.EXAMPLE.COPY.

TT.XML.EXAMPLE.COPY

This concludes our blog on using WMB v7 and MQ v7 to implement a simple Pub/Sub scenario.   We welcome any comments if you have any questions or want to provide feedback.

Thank you,

TransformaTech

Advertisements

From → Integration

20 Comments
  1. DeMatrixx permalink

    You incorrectly name TT.XML.EXAMPLE.PUT as input queue for the publisher flow. There is no TT.XML.EXAMPLE.PUT queue, that should be TT.XML.EXAMPLE.PUB queue

    • Thank you for your feedback. The blog has been updated.

      • DeMatrixx permalink

        Another correction: for the publication flow you configured the MQInput topic property to “TT.XML.EXAMPLE” ; that should be “TT_XML_EXAMPLE” to match the topic string used in MQ Explorer

  2. DeMatrixx permalink

    While I’m here, I need to call a subflow with INPUT and OUTPUT nodes as my subscriber flow; how do I achieve that?

    More details: I’m using WMBv8.0.02. I have a webservice with SOAPInput and SOAPOutput nodes (both in the parent/main flow). I use a RouteToLabel node to transition from main flow into the subflow which has the Input, Compute and Output nodes only.

    I’m going to add MQInput and MQOutput nodes to my subflow and configure using your guide, hopefully that will work

    • I am not sure how you want to use Pub/Sub from your comment. If you have a SOAPInput Node receiving messages and your flow specifically routes messages to a subflow, it does not require Pub/Sub.

      If you are creating a new message flow with MQInput node that you want to receive publication messages, then all you will need to do is create another MQ Subscription in MQExplorer that reads from a topic and routes that message to your queue that your MQInput Node is reading from.

      Hope this helps.

      • DeMatrixx permalink

        Thz for your reply. I was asked to create a webservice, I did that, the RouteToLabel node automatically calls the subflow…pretty much what you explained above. The task now is that they also want that same subflow to be called by a publisher flow as well – pub/sub.

        Which is where I’m puzzled because I recall reading in the infocenter that for a flow to be a subflow it must have as the ‘input node’ as it first node; not the other nodes (MQIput, SOAPInput,etc)

      • Sorry for delayed response. You are correct, the scenario in the blog is specifically tied using MQ’s Pub/Sub model and requires an MQInput which would mean this may not be a subflow. (I never tried it but you may be able to have both an Input and MQInput in your message flow that will accomplish both scenarios. You can also implement a simple subscriber message flow that reads from a queue and then uses your existing subflow.

        There are other mechanisms for implementing pub/sub with Broker but that is not a topic for this simple Pub/Sub scenarios this blog was for.

  3. DeMatrixx permalink

    Having both an Input and MQInput in my subflow did not work, so I tried ‘simple subscriber message flow that reads from a queue and then uses your existing subflow’…which makes much more sense. I think that’s the right layout this task.

    My issue now is when I test the project as a webservice…its works perfectly; however when I use RHFUtil to test pub/sub nothing gets writing to my subscriber input queue. Thinking maybe its something with the publication node, I also test it writing the message directly to the subscriber input queue; the message got written to queue but nothing in the output queue. I think there’s something fishy going on with WMB as usual because I follow your blog to the T

    • DeMatrixx permalink

      Do I need to explicitly set the Topic in my XML message or Topic gets assigned to my message once it is written to TT.XML.EXAMPLE.PUB queue?

  4. Ashwin permalink

    Please help me..,I’ve done the same steps..but not getting the output..,
    Please clear my below confusions
    In Topic section of publication flow..do i need to mention ‘Topic’ or ‘Topic string’ ?

    How can i knw tht my data has been published..?

    Once published am not able to receive at the subscribed node..neither the queue depth is increasing…,please help me out

    • The publication node will get the information from the MQInut node “topic” property. This should be set to “TT_XML_EXAMPLE” which refers to the Topic string.

      • Ashwin permalink

        i’ve did the same…,,But the subscription queue depth remains zero…How can i debug this please help

  5. If you want please send screen shots of each step in your setup to info@transformatech.com and we can take a quick look to see if we can see what is the problem.

  6. Srinivasa Rao Palla permalink

    In publish flow under Advanced property of MQInput Queue we must specify the complete topic string in order to make it complete.
    Topic: TT_XML_EXAMPLE/TT_XML_EXAMPLE

  7. Avinash permalink

    @ashwin: You can test if your publication is working using foll steps:
    Go to topics folder. Right click on ur topic and select TEST PUBLICATION. Enter some data in text box and click publish. Your queues should have this data.

    And I had the following issue, when I worked on this example. When I tested my publication , I never received the message in my queue.
    Solution: Check ur subscription. Check what is under topic_string field.

    If it is TT_XML_EXAMPLE/TT_XML_EXAMPLE , you wont receive output.
    Change it to TT_XML_EXAMPLE.

  8. Avinash permalink

    Transformatech:: Wonderful posts. I’m learning a lot from these scenarios . Please post as many as possible. Very much helpful to beginners.

  9. Roman permalink

    In scenario, where I need to receive a message over JMSInput node from remote QM and get it published to topic on local QM do I need to create subscription on local QM? In my case subscriber app is written in Java and is going to subscribe to this topic in order to receive messages.

    • Your scenario could be implemented very similar to the publish flow in this example. You will have a JMSInput node and publish node to publish to topic on local queue manager. You could then create an MQ subscription that puts to an MQ queue that your Java subscriber application would read from.

  10. Balaji permalink

    Hi, I’m using the same pub/sub setup but getting 2417 error while trying to post messages to the queues. It means MQRC_MSG_NOT_ALLOWED_IN_GROUP. please advise.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: