IBM MQ: My first try at topic trees

There is a lot of texts and pictures out there talking about topic trees but I have had a hard time finding any complete examples, so to better get a grip on what topic trees are and how I can use them I created this small example.

Goal: To be able to subscribe to multiple topics of similar entity types using only one subscription

Let’s get right into the tree building. I’m here going to use the runmqsc program but you can use MQExplorer if you like a GUI

DEFINE TOPIC(APPLE)  TOPICSTR('/prices/fruit/apple')
DEFINE TOPIC(ORANGE) TOPICSTR('/prices/fruit/orange')
DEFINE TOPIC(PUZZLE) TOPICSTR('/prices/toys/puzzle')
DEFINE TOPIC(CUBE)   TOPICSTR('/prices/toys/cube')

These commands will give you a tree looking like this

                    /      \
               fruits       toys
              /     \      /    \
          orange  apple  cube  puzzle

And now I’m going to try to show the “magic” this brings

A. Subscribe to TOPICSTR(‘/prices/#’) will get you ALL messages published on ANY topic string in this tree
B. Subscribe to TOPICSTR(‘/prices/toys/#’) will get you messages published on ‘/prices/toys’, ‘/prices/toys/cube’ and ‘/prices/toys/puzzle’. No other
C. Subscribe to TOPICSTR(‘/prices/fruit/orange/#’) will get you messages published on ‘/prices/fruit/orange’ only. No other

Pure magic!

Tested on IBM MQ v9.0.5.0 on Red Hat Linux 7.5

  1. Great to see you making use of topics now. I look forward to more blog posts. One thing I thought you might like to know now, early on; you don’t have to create topic objects for every node in the topic tree. The nodes in the topic tree also come into existence when you publish or subscribe on them and such applications can do so without the use of a topic object. Something for you to look into 🙂

  2. P.S. Typo in your definition of topic object FRUITS. Topic string I suspect you wanted was ‘prices/fruit’

  3. does subscriber to different topics in topic hierarchy uses the same client is or different one?

Leave a Comment

NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre lang="" line="" escaped="" cssfile="">

This site uses Akismet to reduce spam. Learn how your comment data is processed.