mqtt_util

package
v0.0.1-beta.17 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 21, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Create

func Create(config *ClientConfig, handler func(*paho.Publish), connectionManager **autopaho.ConnectionManager) (err error)

Create 创建 mqtt 的 autopaho.ConnectionManager,

config 是 mqtt 的配置

handler 是 mqtt 收到消息的回调

connectionManager 是 mqtt 的连接实例, 通过这个二级指针返回新的 mqtt 连接实例, 还会关闭旧的连接实例。

func DefaultConnectionManager

func DefaultConnectionManager() **autopaho.ConnectionManager

DefaultConnectionManager 获取空的 MQTT 连接

Types

type ClientBuild

type ClientBuild struct {
	ClientConfig
	MessageCallback   paho.MessageHandler
	ConnectionSuccess ConnectionSuccess
	ConnectionError   ConnectionError
	ClientError       ClientError
	ServerDisconnect  ServerDisconnect
}

func NewClientBuild

func NewClientBuild() *ClientBuild

func (*ClientBuild) AddServerURL

func (build *ClientBuild) AddServerURL(url ...string) *ClientBuild

AddServerURL 添加服务器

func (*ClientBuild) AddSubscribe

func (build *ClientBuild) AddSubscribe(subscribe ...string) *ClientBuild

AddSubscribe 添加订阅

func (*ClientBuild) BuildAndConnection

func (build *ClientBuild) BuildAndConnection() (connectionManager *autopaho.ConnectionManager, err error)

func (*ClientBuild) SetClientError

func (build *ClientBuild) SetClientError(clientError ClientError) *ClientBuild

SetClientError 其它原因导致客户端连接断开

func (*ClientBuild) SetClientID

func (build *ClientBuild) SetClientID(clientID string) *ClientBuild

SetClientID 设置客户端ID

func (*ClientBuild) SetConnectionError

func (build *ClientBuild) SetConnectionError(connectionError ConnectionError) *ClientBuild

SetConnectionError 连接 MQTT 服务端失败

func (*ClientBuild) SetConnectionSuccess

func (build *ClientBuild) SetConnectionSuccess(connectionSuccess ConnectionSuccess) *ClientBuild

SetConnectionSuccess 成功连接到 MQTT 服务端

func (*ClientBuild) SetMessageCallback

func (build *ClientBuild) SetMessageCallback(m paho.MessageHandler) *ClientBuild

SetMessageCallback 设置消息回调

func (*ClientBuild) SetServerDisconnect

func (build *ClientBuild) SetServerDisconnect(serverDisconnect ServerDisconnect) *ClientBuild

SetServerDisconnect 收到服务端的断开连接命令

func (*ClientBuild) SetUsernamePassword

func (build *ClientBuild) SetUsernamePassword(un, pwd string) *ClientBuild

SetUsernamePassword 设置用户名和密码

type ClientConfig

type ClientConfig struct {
	ServerURL []string `yaml:"serverURL" json:"serverURL"`
	Subscribe []string `yaml:"subscribe" json:"subscribe"`
	ClientID  string   `yaml:"clientID" json:"clientID"`
	UserName  string   `yaml:"userName" json:"userName"`
	PassWord  string   `yaml:"passWord" json:"passWord"`
}

type ClientError

type ClientError func(err error)

type ConnectionError

type ConnectionError func(err error)

type ConnectionSuccess

type ConnectionSuccess func(*autopaho.ConnectionManager, *paho.Connack)

type ServerDisconnect

type ServerDisconnect func(*paho.Disconnect)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL