In the first three articles of this series, I introduced you to IBM MQ and its basic functionalities (queues, local and remote, channels and listeners).
This time, I’ll start complicating things a bit. This time I’ll write about the publish and subscribe feature of IBM MQ.
Overview
Suppose you have some data that is produced by one application and want to have that data processed by two different applications. It would be highly inefficient to have that data produced twice or copied by other means.
Using MQ’s publish and subscribe functionality it is possible to have the same data sent to one or more destinations, which, in MQ, means any object which you can write to (local, alias or remote queues, etc.).
In theory, it works like this: you create a topic object, then an alias queue specifying its target as the topic previously created. Finally, you create as many subscriptions as you want/need.
Putting all together
In the following example, I’ll show how to configure MQ so that messages sent to an alias queue get written in two different local queues.
Firstly, create two local queues.
DEFINE QLOCAL(Q1.R) DEFPSIST(YES) MAXDEPTH(5000) REPLACE
DEFINE QLOCAL(Q2.R) DEFPSIST(YES) MAXDEPTH(5000) REPLACE
Then create a topic, an alias queue and two subscriptions.
DEFINE TOPIC(TOPIC1.T) TOPICSTR(TOPIC1.T) REPLACE
DEFINE QALIAS(Q1.A) TARGET(TOPIC1.T) TARGTYPE(TOPIC) DEFPSIST(YES) REPLACE
DEFINE SUB(SUB1.S) TOPICSTR(TOPIC1.T) DEST(Q1.R) REPLACE
DEFINE SUB(SUB2.S) TOPICSTR(TOPIC1.T) DEST(Q2.R) REPLACE
After this, any message that is put in the alias queue Q1.A gets sent to both Q1.R and Q2.R local queues.
Instead of local queues, the subscriptions’ destinations can also be remote queues or other alias queues.
Pingback: MQGem Monthly (July 2019) | MQGem Software