eclipse-mosquitto / mosquitto

Eclipse Mosquitto - An open source MQTT broker
https://mosquitto.org
Other
9.05k stars 2.39k forks source link

Mosquitto bridge connection to IoT failing periodically. #367

Closed amit1rrr closed 7 years ago

amit1rrr commented 7 years ago

I have a mosquitto instance running on an ec2 host. We have bridged this to AWS IoT. Everything works fine except that the bridge looses connection to IoT endpoint every now and then. Our restart_timeout setting is at 1 second. But all the messages in that 1-2 second period of re-connection are lost. My ec2 instance and IoT endpoint are in the same region as well.

I am not sure if this is a bug in the mosquitto bridging connection or AWS IoT dropping the connection. But would want to know what's happening.

My bridge config is as follow:

#
# =================================================================
# Bridges to AWS IOT
# =================================================================

# AWS IoT endpoint, use AWS CLI 'aws iot describe-endpoint'
connection awsiot
address a3m62xf68nsc3x.iot.us-east-1.amazonaws.com:8883

# Specifying which topics are bridged
#topic awsiot_to_localgateway in 1
#topic localgateway_to_awsiot out 0
#topic both_directions both 1
topic GPSLog/# out 2
topic DeviceHealth/# out 2
topic DeviceLogs/# out 2
topic DriverConnection/# out 2
topic Staging/GPSLog/# out 2
topic Staging/DeviceHealth/# out 2
topic Staging/DriverConnection/# out 2

# Setting protocol version explicitly
bridge_protocol_version mqttv311
bridge_insecure false

# Added by Amit
bridge_attempt_unsubscribe false
try_private true
log_dest stdout
keepalive_interval 5
restart_timeout 0

# Bridge connection name and MQTT client Id,
# enabling the connection automatically when the broker starts.
cleansession true
clientid bridgeawsiot
start_type automatic
notifications false
log_type all

# =================================================================
# Certificate based SSL/TLS support
# -----------------------------------------------------------------
#Path to the rootCA
bridge_cafile /etc/mosquitto/certs/rootCA.pem
amit1rrr commented 7 years ago

Closing it.

This was happening because I had another instance of mosquitto with same client ID trying to connect to same IoT endpoint. As per mqtt protocol, broker drops existing connection when it receives another connection with same clientID. So these instances kept disconnecting each other.

Resolution was to change the clientID.