dongpang9573 2018-09-05 16:19 采纳率: 0%
浏览 770

Golang中的mqtt客户端偶尔断开连接

I am using paho mqtt client in GO to connect to a broker. Everything works fine for a while, in which I can publish to topics and listen to any subscription. After a while the client loses connection to the broker, for no apparent reason with this log:

[MQTT] ERROR: 2018/09/04 17:31:30 [net] outgoing stopped with error write tcp IP1 -> IP2: write: broken pipe
[MQTT] ERROR: 2018/09/04 17:31:30 [net] logic received from error channel, other components have errored, stopping

I am connecting to the broker like this:

opts := mqtt.NewClientOptions().
    AddBroker(broker).
    SetClientID(fmt.Sprintf("%s-%v", ProgramName, time.Now().Unix())).
    SetUsername(username).
    SetPassword(password).
    SetOrderMatters(true)
if tlsConfig != nil {
    opts.SetTLSConfig(tlsConfig)
}

pahoClient := mqtt.NewClient(opts)
client = &DefaultMQTTClient{
    c:            pahoClient,
    subscribeQoS: subscribeQoS,
    publishQoS:   publishQoS,
    name:         name,
    log: Log.WithPrefix("mqtt").WithFields(logrus.Fields{
        "name":   name,
        "broker": broker,
    }),
}

client.Log().Debug("connecting to mqtt broker")
if err = client.Connect(); err != nil {
    err = client.Log().Trace(err, "failed to connect to mqtt broker")
    return
}
client.Log().Info("established connection with mqtt broker")

And the version of paho that I am using is 1.0.0. Any hint is welcome!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 用visual studi code完成html页面
    • ¥15 聚类分析或者python进行数据分析
    • ¥15 逻辑谓词和消解原理的运用
    • ¥15 三菱伺服电机按启动按钮有使能但不动作
    • ¥15 js,页面2返回页面1时定位进入的设备
    • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
    • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
    • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
    • ¥20 腾讯企业邮箱邮件可以恢复么
    • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?