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(PRICES) TOPICSTR('/prices') DEFINE TOPIC(FRUITS) TOPICSTR('/prices/fruits') DEFINE TOPIC(APPLE) TOPICSTR('/prices/fruit/apple') DEFINE TOPIC(ORANGE) TOPICSTR('/prices/fruit/orange') DEFINE TOPIC(TOYS) TOPICSTR('/prices/toys') DEFINE TOPIC(PUZZLE) TOPICSTR('/prices/toys/puzzle') DEFINE TOPIC(CUBE) TOPICSTR('/prices/toys/cube')
These commands will give you a tree looking like this
prices / \ fruits toys / \ / \ orange apple cube puzzle
And now I’m going to try to show the “magic” this brings
Tests
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
Comments are closed.