亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

蚊子的持久性不一致

蚊子的持久性不一致

Go
料青山看我應如是 2022-07-11 15:34:54
我在 mosquitto 上看到消息持久性和 qos=2 的消息傳遞不一致。有什么我做錯了嗎?我有一個簡單的測試應用程序,它使用 clientId="receive-client" 注冊消費主題,但立即斷開連接。然后它以 clientId="send-client" 的身份連接并發布 10 條消息,“message #1”...“message #10”。然后斷開連接,等待五秒鐘,然后在打印和計算收到的消息時再次連接以使用“receive-client”消費。結果不一致。有時我收到 6 條消息,有時是 8 條。典型的輸出是這樣的:WARN[0005] GOT A MESSAGE:message #1                     WARN[0005] GOT A MESSAGE:message #2                     WARN[0005] GOT A MESSAGE:message #3                     WARN[0005] GOT A MESSAGE:message #4                     WARN[0005] GOT A MESSAGE:message #5                     WARN[0005] GOT A MESSAGE:message #6                     WARN[0005] GOT A MESSAGE:message #7                     WARN[0005] GOT A MESSAGE:message #8                     WARN[0305] PAUSE                                        WARN[0605] received message count=8                     我的版本信息是 1.4.15。我的 mosquitto.conf 是:pid_file /var/run/mosquitto.pidpersistence truepersistence_location /var/lib/mosquitto/allow_anonymous falsepassword_file /etc/mosquitto/passwdlog_dest file /var/log/mosquitto/mosquitto.log最初 /var/lib/mosquitto/mosquitto.db 直到運行了幾次迭代才會出現。我的測試應用在這里:import (    mqtt "github.com/eclipse/paho.mqtt.golang"    log "github.com/sirupsen/logrus"    "time")var receivedMsg intfunc Persist() {    const TOPIC = "test"    const URL = "tcp://localhost:1883"    const USERNAME = "myuser"    const PASSWORD = "mypassword"    defer printReceived()    options := mqtt.NewClientOptions().AddBroker(URL).SetUsername(USERNAME).SetPassword(PASSWORD)    options.SetCleanSession(false)    options.SetConnectRetry(true)    options.SetConnectRetryInterval(10 * time.Millisecond)
查看完整描述

1 回答

?
慕碼人8056858

TA貢獻1803條經驗 獲得超6個贊

在 QOS 2 上發布是一個多步驟過程,因此最可能的原因是您在所有消息真正完成發布到代理之前斷開了發布客戶端的連接。您可能應該在循環中進行發布,并使用調用返回的令牌client.publish()來等待它完成,然后再斷開客戶端。


例如,如示例所示:


//Publish 5 messages to /go-mqtt/sample at qos 1 and wait for the receipt

//from the server after sending each message

for i := 0; i < 5; i++ {

  text := fmt.Sprintf("this is msg #%d!", i)

  token := c.Publish("go-mqtt/sample", 0, false, text)

  token.Wait()

}


查看完整回答
反對 回復 2022-07-11
  • 1 回答
  • 0 關注
  • 128 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號