I'm trying to bridge two MQTT brokers on the same system, HiveMQ
and Mosquitto
. HiveMQ
is working on port 1884
and Mosquitto
is running on 1883
. However when I use the mosquitto_pub
command to publish to the mosquitto
broker at port 1883
, it does not show up on port 1884
(Using MQTT.fx
as a client subscribing to all topics on port 1884
)
This is while I only configured the mosquitto
broker with a bridge. When I configured HiveMQ
as well, it only shows an unable to connect to Bridge1, disconnected
message on the HiveMQ
command window. I've included the configurations below. Someone please help.
In the mosquitto.config
file I have done the following under bridges
.
connection hivemq
address 127.0.0.1:1884
start_type automatic
clientid clientno1
notifications true
Meanwhile, I also editted the HiveMQ bridges.xml
file to read
<?xml version="1.0" encoding="UTF-8"?>
<bridges xsi:noNamespaceSchemaLocation="http://www.hivemq.com/bridges/bridge.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<bridge>
<connectionName>Bridge1</connectionName>
<addresses>
<address>
<host>localhost</host>
<port>1883</port>
</address>
</addresses>
<clientId>bridgeClient</clientId>
<topicPatterns>
<topicPattern>
<topic>#</topic>
<qos>1</qos>
<direction>both</direction>
<localPrefix>local/</localPrefix>
<remotePrefix>remote/</remotePrefix>
</topicPattern>
</topicPatterns>
<cleanSession>true</cleanSession>
<idleTimeout>10</idleTimeout>
<notificationsEnabled>true</notificationsEnabled>
<tryPrivate>true</tryPrivate>
</bridge>
The image shown is when I tried the same process on another system. Here, the brokers are bridged. Comparing this to what I was doing earlier, the only difference is that on my original system there is no statement saying opening ipv4 listen socket on 1883. Is this the problem?
You should only need to have the bridge configured in one of the brokers, having bridges configured for both will lead to problems, most likely message loops
For your mosquitto config you need to add a topic line to your mosquitto bridge so it knows what topics to send (and receive) to the hive broker
The full details about the topic directive can be found in the mosquitto.conf man page ( http://mosquitto.org/man/mosquitto-conf-5.html ) but the basics are:
topic pattern [[[ out | in | both ] qos-level] local-prefix remote-prefix]
To mirror all topics in both directions
topic # both
Bridging should only be set on the publisher/client side (mosquitto in your case), leaving default settings on Hivemq (server) should be fine
Try make changes to your mosquitto.conf
connection bridge-mosquitto-to-hivemq
address 127.0.0.1:1884
topic room1/# both 2 sensor/ myhouse/
bridge_protocol_version mqttv311
notifications true
cleansession true
try_private true
After restart your brokers, at mosquitto broker, try publish an example message below
mosquitto_pub -t sensor/room1/temperature -m '26.3'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.