The topic is represented by a string and it has a hierarchical structure where each layer (subtopic) is separated by “/” character. For example, imagine that a company wants to monitor some physical data inside its buildings with a lot of sensors (temperature, humidity, …) for each floor and room; the topic structure for publishing and receiving sensors data could be the following :
building1/floor1/room1/temperature
building1/floor1/room1/humidity
building2/floor3/room4/temperature
The hierarchy starts from the building to a specific room through the floor and at the end we have the specific sensor.
Figure 3.4 : Topic hierarchical structure
A publisher can publish only to an absolute topic but a subscriber can subscribe to an absolute topic or can use wildcards so that it can receives messages published on more topics. There are two types of wildcards:
If we consider the above examples, we could be interested in all temperature values for all rooms on floor1 in the building1. In this case, we can use the wildcard “+” to collapse the room level inside our topic hierarchy in the following way :
building1/floor1/+/temperature
In the same manner, if we are interested in all data sensors (temperature, humidity, …) in room3 on floor2 in the building2, we can use the wildcard ”#” to collapse the last level of the topic hierarchy in the following way :
building2/floor2/room3/#