Search code examples
node.jsrabbitmqamqpmqttrabbitmq-exchange

It is safe to use "." has MQTT topic level separator instead of "/"?


The are several devices connected to RabbitMQ using MQTT protocol and there are many nodejs process subscribed with AMPQ protocol to RabbitMQ to fetch data from those devices.

The devices are publishing with topics structured like this: data.DEVICETYPE.IDDEVICE, for example one nodejs process is subscribed on the topic data.# for getting ALL messages from devices.

My concern is about the separator that, in this case, is the "."; because in all examples and the documentation of the MQTT protocol, they always use "/" (like a path folder) so i started to think that using the point instead of slash could be a problem.

It's worth to mention that the system actually works well, but i really don't know if in the future this decision could rise compatibly problems.

EDIT: Actually my structure is like this: RabbitMQ Topic structure I started from this to create that topic structure.


Solution

  • / is the hierarchy separator in MQTT. If you use . instead, it "works", but you just have a large number of distinct top level topics.

    You couldn't subscribe using wildcards using data.# - that is an invalid subscription topic. # must be the last character for a subscription and must be on its own level. As . is not a hierarchy separator you violate this last rule.