盘古框架Mqtt集成,方便用户在盘古框架中接入Mqtt功能
本框架对
Mqtt做了一定的封装,使用参看使用文档
Mqtt使用非常简单,只需要定义配置和依赖项
配置有很多,但是大部分都有默认值,可以参考配置文档
配置代码如下
mqtt:
broker:
- tcp://192.168.95.102:31883
- ws://192.168.95.102:38083
options:
username: test_username
password: test_password
clientid: ${HOSTNAME}依赖项的代码如下
package main
import (
`github.com/pangum/mqtt`
)
type agent struct {
client *mqtt.Client
}
func newAgent(client *mqtt.Client) *agent {
return &agent{
client: client,
}
}
func (a *agent) subscribe() error {
return a.client.Subscribe(`topic`, opts...)
}
Mqtt有非常多的配置项,请参看使用文档


