2017-04-18 95 views
1

我有一个与蚊子经纪人的树莓和桥梁与亚马逊物联网服务。 https://aws.amazon.com/es/blogs/iot/how-to-bridge-mosquitto-mqtt-broker-to-aws-iot/重复的消息蚊子MQTT经纪人到亚马逊物联网服务使用持久性

这是我mosquitto.conf文件:

# 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 

这是是/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 

所有工作正常,内bridge.conf。但是,如果我取下以太网电缆来测试节拍。当通讯重新建立时。代理向亚马逊IoT服务发送重复消息。

这是我送

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

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

它是一个正常的行为的消息?

+0

您尚未在该配置中包含该桥的详细信息。你还发送什么类型的消息,QOS和他们保留什么? – hardillb

+0

对不起@hardillb ...编辑的问题。 QOS是1。 – JosepB

回答

2

(的一部分)的MQTT规格的短版本:

  • QOS 0 - >信息可以被递送
  • QOS 1 - >信息将被至少一次输送
  • QOS 2 - >消息将只传送一次。

因此,如果消息没有被确认,那么QOS 1消息将有可能再次被传递。他们应该在标题中设置DUP标志,以便收款经纪人知道他们可能已经交付。

IIRC AWS-IoT不支持QOS 2,因此您可能已经忍受了这一点。

+0

这是一个正常的行为,在10秒后,或多或少,保留的消息被删除?因为如果我在短时间内失去通讯,则会发送队列中的消息。但是如果我失去了超过1分钟的通讯,似乎所有队列中的消息都被删除了,因为我没有收到任何消息在亚马逊物联网 – JosepB

0

AWS IoT不支持cleansession false。电桥的结果是,当:

  • 你有一个错误发送消息
  • ,并有persistence true
  • ,并没有有效地断开
  • 和服务质量> 0,甚至服务质量= 0 if queue_qos0_messages true

=>消息保存在db中。

但是,如果客户端自动设置为网桥会有效断开连接,则cleansession true会通知代理不保留数据,因此会清除该客户端的数据库。

希望当你发送cleansession false AWS物联网并没有断开连接,这样我们就可以保持这个本地缓存...

PS:在“客户端自动设置为桥”的是,当你设置的桥梁在两个经纪人之间,创建一个客户来订阅一个客户并且总是发布给另一个客户。