0

I have two mosquitto brokers installed on PC1 (mosquitto v1.4.8) and PC2 (RabbitMQ v3.6.2 with MQTT Adapter).

Bridging initiated at PC1 like below

sensor/room1/ <-> office/room1/

But I noticed there is always a duplicate message being published back whenever the bridge is active, means all my application (on PC1) which subscribes to the same topic will receives the same message twice. What setting I did wrong here?

PC1 mosquitto.conf

connection bridge-pc1-to-pc2
address pc2-address.com
topic room1/# both 2 sensor/ office/

bridge_protocol_version mqttv311
notifications true
cleansession true
try_private false

To test loopback issue, I had PC1 subscribed to topic sensor/#

mosquitto_sub -t sensor/# -v -d 

Then at PC1 I publish a test message

mosquitto_pub -t sensor/room1/temperature -m '{"value":27.3, "timestamp":"2016-06-03 14:02:38"}'

Broker at cloud (PC2) received the message correctly (message received only once)

Client mosqsub/3121-Dennis-iMa sending CONNECT
Client mosqsub/3121-Dennis-iMa received CONNACK
Client mosqsub/3121-Dennis-iMa sending SUBSCRIBE (Mid: 1, Topic: office/#, QoS: 0)
Client mosqsub/3121-Dennis-iMa received SUBACK
Subscribed (mid: 1): 0
Client mosqsub/3121-Dennis-iMa received PUBLISH (d0, q0, r0, m0, 'office/room1/temperature', ... (14 bytes))
office/room1/temperature {"value":27.3, "timestamp":"2016-06-03 14:02:38"}

But PC1 received the same message twice! Below is the Pi's output

Received CONNACK
Received SUBACK
Subscribed (mid: 1): 0
Received PUBLISH (d0, q0, r0, m0, 'sensor/room1/temperature', ... (14 bytes))
sensor/room1/temperature {"value":27.3, "timestamp":"2016-06-03 14:02:38"}
Received PUBLISH (d0, q0, r0, m0, 'sensor/room1/temperature', ... (14 bytes))
sensor/room1/temperature {"value":27.3, "timestamp":"2016-06-03 14:02:38"}

Why there is loopback published message and how to solve this?

Update 3 Jun 2016
This is not the same question with this question, as it does not involve horizontal scaling (1-to-many brokers)

Community
  • 1
  • 1
Dennis
  • 3,528
  • 4
  • 28
  • 40
  • Possible duplicate of [mqtt mosquitto bridge horizontal scaling](http://stackoverflow.com/questions/36283197/mqtt-mosquitto-bridge-horizontal-scaling) – hardillb Jun 03 '16 at 07:37
  • @hardillb This is not the same question with this question, as it does not involve horizontal scaling (1-to-many brokers) – Dennis Jun 03 '16 at 08:02

2 Answers2

1

Change try_private false to try_private true. This is exactly what it is intended for. If rabbit doesn't support that feature (it is currently not in the spec, but widely used) then you're out of luck.

ralight
  • 11,033
  • 3
  • 49
  • 59
  • i tried, it work if both brokers are mosquitto, but it doesn't work for mosquito + RabbitMQ – Dennis Jun 03 '16 at 08:09
0

RabbitMQ doesn't support try_private and doesn't know anything about the bridge. So messages published to office/* in RabbitMQ will be sent back to subscribed mosquitto without taking to account any private flags. To remove cycles you can use different topic names for in and out connections or use two mosquitto servers.

Daniil Fedotov
  • 371
  • 1
  • 2
  • changing my topic structure will be a lot of work now. I initially choose RabbitMQ because is free and support cloud clustering. Do you know any other brand which can do the same? – Dennis Jun 03 '16 at 10:08