Search code examples
jmswebsphereibm-mq

Have a message queue subscribe to a topic


I have a Topic that has two subscribers. However, one of the subscribers will be deployed in a cluster. So, in effect (I think?) the cluster will be seen as multiple subscribers. I need to make sure only one message is consumed by the cluster.

I do not know the options to do this. Is it possible to insert a queue in between the cluster and the topic, and then have the clustered application only work with the inserted queue?

If this is possible, how, in general, to make the queue "subscribe" to the Topic?

Another idea I heard is to make cloned subscribers in the cluster, anyone hear of this before to solve this issue?

Another idea is to do away with the Topic and just use two queues in its place, this seems to be a safe solution?

Using WebSphere MQ


Solution

  • You can use a durable subscription to achieve this.

    Administratively create a durable subscription and specify a destination, basically a queue, which will receive the publications that are published on the specified topic. Your clustered application can then get messages from that destination. Since the publications are being received from a queue, only one instance of your application will get message(s).

    The command below creates durable subscription for topic "/SPORTS/HOCKEY" with destination queue as Q1.

    DEFINE SUB(SPORTSUB) TOPICSTR(/SPORTS/HOCKEY) TOPICOBJ(SPORT) DESTQ(Q1)