Morag's Quirks #2: Pub/Sub Wildcard Schemes

By Morag Hughson posted Wed April 25, 2018 12:00 AM

This is part of an occasional series of small blog posts where I (Morag) will write about some of the quirks in IBM MQ, in the hope of invoking the response, "Well, I didn't know that!" Read other posts in this series.

There are two wildcard schemes for IBM MQ subscriptions to choose from. Learn why this is. IBM WebSphere MQ V7.0 introduced Publish/Subscribe into the MQ API. You have the ability to MQOPEN a topic to then MQPUT to it in order to publish, and to MQSUB to a topic to register an interest in messages published about that topic.

As you get to know the detail of the MQ API for Publish/Subscribe, you may notice that when subscribing, using the MQSUB verb, you have two choices for wildcards.

When you wish to subscribe to a topic, you can do so either to an exact topic string, or to a wildcarded topic string. Using a wildcarded topic string, with a suitably designed topic tree can allow you to capture messages for several topics without having to make several subscriptions. In the example topic tree shown below, with the price of Fruit and Veg, you can, for example, subscribe to the price of all of the Fruit with a single wildcarded subscription.


The subject of today's MQuirk, is why there are two choices for wildcards.

There are two schemes to chose from, a topic based scheme and a character based scheme.

The topic based scheme expects that you need to subscribe on a whole section within a topic string. Each section is separated by a '/' character. For example, in the diagram above, one example topic string might be 'Price/Fruit/Apple' and you might want to subscribe for all fruit prices, so you want the whole 'Price' section and the whole 'Fruit' section and then a wildcard character.


In contrast the character based scheme pays little attention to the structure of the topic tree and allows you to use the wildcard anywhere on the topic string as a whole. If we were to extend the above example further and add another fruit, Apricot, then, if you needed to, you could subscribe to all Fruit beginning with the letter 'A'.


The topic based scheme is the default used if you don't explicitly state the scheme you want, since it is the most likely to be used in a structured topic tree.

In order to explicitly indicate which scheme you want to use, there are two MQSUB options, MQSO_WILDCARD_TOPIC and MQSO_WILDCARD_CHAR.

The reason two schemes exist is because prior to MQ V7, there were two queue based Publish/Subscribe options available, one in IBM Message Broker which used the topic based scheme, and one in MQ which used the character based scheme. MQ V7 took over from both those previous queue based options and so had to be able to support both schemes.

Morag Hughson is an MQ expert. She spent 18 years in the MQ Devt organisation before taking on her current job writing MQ Technical education courses with MQGem. She also blogs for MQGem. You can connect with her here on IMWUC or on Twitter and LinkedIn.