1
votes

I have a Raspberry with a mosquitto broker on it and bridged with amazon IoT service. https://aws.amazon.com/es/blogs/iot/how-to-bridge-mosquitto-mqtt-broker-to-aws-iot/

This is my mosquitto.conf file:

# Place your local configuration in /etc/mosquitto/conf.d/
#
# A full description of the configuration file is at
# /usr/share/doc/mosquitto/examples/mosquitto.conf.example

pid_file /var/run/mosquitto.pid

persistence true
persistence_location /var/lib/mosquitto/

log_dest file /var/log/mosquitto/mosquitto.log

include_dir /etc/mosquitto/conf.d

This is the bridge.conf that is inside the /etc/mosquitto/conf.d

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

# AWS IoT endpoint, use AWS CLI 'aws iot describe-endpoint'
connection awsiot
address xxxxxxxxx.iot.eu-central-1.amazonaws.com:8883

# Specifying which topics are bridged
topic awsiot_to_localgateway in 1
topic localgateway_to_awsiot/iot out 1
topic both_directions both 1

# Setting protocol version explicitly
bridge_protocol_version mqttv311
bridge_insecure false

# 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

# Path to the PEM encoded client certificate
bridge_certfile /etc/mosquitto/certs/cert.crt

# Path to the PEM encoded client private key
bridge_keyfile /etc/mosquitto/certs/private.key

All works fine. But, If I remove the ethernet cable to test the pesistence. When the comunications are reestablished. The broker send repeated messages to the amazon IoT service.

This is the message that I'm sending

char dataToSend[] = "Message Id: ";
counter++;

snprintf(dataToSend, sizeof(dataToSend) + 10, "Message Id: %d", counter);
app_mqtt_publish(&dataToSend);

Is it a normal behaviour?

2
You haven't included the details of the bridge in that configuration. Also what sort of messages are you sending, what QOS and are they retained?hardillb
Sorry @hardillb... Question edited. The QOS is 1.JosepB

2 Answers

2
votes

The short version of (part of) the MQTT spec:

  • QOS 0 - > Messages may be delivered
  • QOS 1 -> Messages will be delivered at least once
  • QOS 2 -> Messages will be delivered once and only once.

So if messages have not been acknowledged then there is a chance that QOS 1 messages will be delivered again. They should have the DUP flag set in the header so the receiving broker should know they may have been delivered already.

IIRC AWS-IoT doesn't support QOS 2 so you may have just put up with this.

0
votes

AWS IoT doesn't support cleansession false. The consequence for the bridge is that, when:

  • you have an error sending a message
  • and have persistence true
  • and didn't effectually disconnect
  • and the QoS > 0 or even QoS = 0 if queue_qos0_messages true

=> messages are saved in db.

But if the client automatically set to the bridge effectually disconnects, the cleansession true tells the broker to do not persist the data, so it clears the db for this client.

Wish that AWS IoT didn't disconnect when you send cleansession false, so we could keep this local cache...

ps: The "client automatically set to the bridge" is that, when you set a bridge between two brokers, a client is created to subscribe to one and always publish to the other.