IBM MQ basics: publish and subscribe

In the first three arti­cles of this series, I intro­duced you to IBM MQ and its basic func­tion­al­i­ties (queues, local and remote, chan­nels and listeners).

This time, I’ll start com­pli­cat­ing things a bit. This time I’ll write about the pub­lish and sub­scribe fea­ture of IBM MQ.

Overview

Sup­pose you have some data that is pro­duced by one appli­ca­tion and want to have that data processed by two dif­fer­ent appli­ca­tions. It would be high­ly inef­fi­cient to have that data pro­duced twice or copied by oth­er means.

Using MQ’s pub­lish and sub­scribe func­tion­al­i­ty it is pos­si­ble to have the same data sent to one or more des­ti­na­tions, which, in MQ, means any object which you can write to (local, alias or remote queues, etc.).

In the­o­ry, it works like this: you cre­ate a top­ic object, then an alias queue spec­i­fy­ing its tar­get as the top­ic pre­vi­ous­ly cre­at­ed. Final­ly, you cre­ate as many sub­scrip­tions as you want/need.

Putting all together

In the fol­low­ing exam­ple, I’ll show how to con­fig­ure MQ so that mes­sages sent to an alias queue get writ­ten in two dif­fer­ent local queues.

First­ly, cre­ate two local queues.

DEFINE QLOCAL(Q1.R) DEFPSIST(YES) MAXDEPTH(5000) REPLACE
DEFINE QLOCAL(Q2.R) DEFPSIST(YES) MAXDEPTH(5000) REPLACE

Then cre­ate a top­ic, 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 mes­sage 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 sub­scrip­tions’ des­ti­na­tions can also be remote queues or oth­er alias queues.

 

This entry was posted in Uncategorized. Bookmark the permalink.

One Response to IBM MQ basics: publish and subscribe

  1. Pingback: MQGem Monthly (July 2019) | MQGem Software

Leave a Reply