1

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 below 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?

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?

avelampudi
  • 316
  • 2
  • 6
  • 16

2 Answers2

0

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
hardillb
  • 54,545
  • 11
  • 67
  • 105
  • I only configured the bridge on `mosquitto` and also added in the topic line in the config file now. Still not bridging. – avelampudi Jun 04 '15 at 10:19
  • Does the mosquitto output show anything about the bridge? – hardillb Jun 04 '15 at 10:29
  • Nothing at all. I can't tell whether it has even configured or not. Both are working perfectly separate, but `mosquitto` doesn't display anything about the bridge. I'm a bit perplexed. – avelampudi Jun 04 '15 at 10:47
  • When I try to configure the bridge via `HiveMQ` instead of `mosquitto` it says `trying to connect to bridge 'mosquitto' with target localhost:1883` Followed by `Connected to bridge 'mosquitto' with target localhost:1883` Then immediately changes to `bridge mosquitto got disconnected. restarting bridge in 30 seconds` – avelampudi Jun 04 '15 at 10:55
  • If mosquitto doesn't say anything about the bridge, try starting it as `mosquitto -v` to enable all logging. – ralight Jun 04 '15 at 15:15
  • @ralight when I do that, it says `using default config. opening ipv6 listen socket on port 1883. Error:Unknown error` Not sure what to make of that. – avelampudi Jun 05 '15 at 04:53
  • Sorry of course you also need to tell mosquitto which config file to load: `mosquitto -v -c mosquitto.conf` – ralight Jun 05 '15 at 07:40
  • @ralight Now it displays `config loaded from mosquitto.conf. opening ipv6 listen socket on port 1883. Error:Unknown error` Can't quite pinpoint this error, it's too generic. – avelampudi Jun 09 '15 at 05:43
  • This isn't the place for an extended discussion. The ipv6 error is a red herring unless you are using ipv6. – ralight Jun 09 '15 at 12:13
0

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'
Dennis
  • 3,528
  • 4
  • 28
  • 40