go - Golang 中 mqtt 客户端的零星断开连接
问题描述
我在 GO 中使用 paho mqtt 客户端连接到代理。一段时间内一切正常,我可以在其中发布到主题并收听任何订阅。过了一会儿,客户端失去了与代理的连接,这个日志没有明显的原因:
[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
我正在像这样连接到经纪人:
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")
我使用的 paho 版本是 1.0.0。欢迎任何提示!
解决方案
推荐阅读
- python - 如何检查 requirements.txt 文件中列出的所有包是否在 Python 项目中使用
- python - 计算在给定范围内对具有重复元素的数组进行排序所需的最小交换的算法?
- tensorflow - 具有 batch_normalization 的 resnet 18 的联合平均 (fedavg) 在第一轮之后做出相同的预测,但在其他轮中没有
- python - 如何在数据框列中获取最接近年末的日期?
- r - 循环遍历子目录,重塑矩阵并在 R 中保存输出
- websocket - Akka Streams 有效地折叠/合并子流(WebSocket Frames -> Messages)
- r - 将页脚添加到部分的开始/标题页
- ios - -layoutAttributesForDecorationViewOfKind 没有 UICollectionViewLayoutAttributes 实例:路径上的 shadowDecorationView
- c# - 当 %20 结尾时,Asp.net 分页
- vue.js - 从 vuejs2 迁移到 vuejs3 的 CSS 转换问题