盘古框架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
有非常多的配置项,请参看使用文档