Understanding the Publish/Subscribe pattern

The Publish/Subscribe pattern solves the problem of detail, by introducing a new concept: a topic, or a node. A broker is used to distribute messages from publishers to subscribers. Each message that is being published, is published on a given topic (or node). In turn, subscribers let the broker know which topics (or nodes) they are interested in. The broker matches incoming publications with the requests of the subscribers, and forwards messages accordingly. Using such message filtering makes sure participants avoid receiving unnecessary messages. In MQTT, publishers can also be subscribers.

Topics (or nodes) can also be formed into trees, with topics, sub-topics, and so on. This allows for a great amount of detail. In MQTT, topics are simple string names, where nodes are separated by the forward slash character (/). MQTT also allows subscribers to subscribe to any node in the tree. Using wildcards, subscribers can even subscribe to entire branches of the tree, or even the entire tree itself. MQTT defines two types of wildcards: a node wildcard (+), and a branch wildcard (#). The node wildcard matches any node on a given level. The branch wildcard matches any number of nodes.

Using a broker also allows machines to overcome the problem of network topology, where the publishers and subscribers normally reside behind firewalls. Since both publishers and subscribers connect to the broker, only the broker needs to be accessible. The others can reside behind firewalls. The following figure illustrates the basic Publish/Subscribe communication pattern, where solid lines represent connections, dashed lines represent the flow of information, and the grey boxes represent possible local networks protected by firewalls:

Publish/Subscribe pattern
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset