So I've been playing with bridging in mosquitto and wanted to share my experiences.
I tried this a while ago and failed mainly because I tried to set it all up at once and had problems with SSL and gave up.
This time I'm splitting it into three sections
1 Get Bridging working on open default install unsecured brokers.
2 Add password protection
3 Add TSL/SSL encryption
So the rest of this document is some notes on the first task, getting bridging working.
Iv'e been working on setting up a bridge from a local mosquitto broker to a remote mosquitto broker. To do this I configured the local broker to set up a bridge with the remote broker. As I'm writing this I'm using Mosquitto version 1.4.4.
So to get started with bridging I used some resources I found online, so I suggest you start there as well.
Securing MQTT communication between Ardruino and Mosquitto
When setting up bridging my advice is to set the log level to Debug on both brokers and read the logs often.
log conf section
log_dest file /var/log/mosquitto/mosquitto.log log_type debug
sudo cat /var/log/mosquitto/mosquitto.log or even
sudo cat /var/log/mosquitto/mosquitto.log | grep SUBSCRIBE
and unless you have a massive amount of traffic on your brokers
mosquitto_sub -t "#" -v is really useful for debugging as well.
Because I found that no matter how you interpret what you read on topic mapping it won't work like you think it should and some amount of digging and testing will be required to get the hang of it.
The following topic patterns
topic inbound/# in alpha/ beta/ topic outbound/# out harry/ larry/ topic duplex/# both ying/ yang/
Result in the following subscriptions on the broker from the logs
1447053408: Bridge **** doing local SUBSCRIBE on topic larry/outbound/# 1447053408: Bridge **** doing local SUBSCRIBE on topic yang/duplex/# 1447053408: Bridge **** sending SUBSCRIBE (Mid: 38, Topic: inbound/#, QoS: 0) 1447053408: Bridge **** sending UNSUBSCRIBE (Mid: 39, Topic: outbound/#) 1447053408: Bridge **** sending SUBSCRIBE (Mid: 40, Topic: duplex/#, QoS: 0)
Which is nothing like what the documentation indicate, YMMV
For example the documentation states.
"For incoming topics, the bridge will prepend the pattern with the remote prefix and subscribe to the resulting topic on the remote broker. When a matching incoming message is received, the remote prefix will be removed from the topic and then the local prefix added."
And in my testing the remote prefix is not prepended to the pattern so its just the pattern that is the topic name and the incoming message has the remote prefix added not the local. e.g.
remote publish: mosquitto_pub -t "inbound" -m "foo" local subscription receives: beta/inbound foo
and for outgoing the documentation states
"For outgoing topics, the bridge will prepend the pattern with the local prefix and subscribe to the resulting topic on the local broker. When an outgoing message is processed, the local prefix will be removed from the topic then the remote prefix added."
and in my testing the local topic is actually the remote prefix followed by the pattern and on the remote broker its published with just the pattern as the topic.
local publish: mosquitto_pub -t "larry/outbound" -m "foo" remote subscription receives: outbound foo
So while mosquito bridging does work and is awesome I've found it's not necessarily working as advertised and so the best solution is digging around in the logs and testing things out with wildcard subscriptions.
YMMV Your millage may vary. Perhaps I'm missing something with the topic mapping and there's a good reason it's behaving as it is. In any case it's working and usable and can be made to do what you need to do once you figure out where your topics are going to.
Commentscomments powered by Disqus