2017-04-18 48 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:在「客戶端自動設置爲橋」的是,當你設置的橋樑在兩個經紀人之間,創建一個客戶來訂閱一個客戶並且總是發佈給另一個客戶。