mqttclient

package
v0.1.64 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MqttClientHandle

type MqttClientHandle interface {
	//订阅消息
	Subscribe(topic string, qos byte, handle MqttConsumerHandle) error

	//发布消息
	Publish(topic string, qos byte, retained bool, payload interface{}) error

	//取消订阅
	Unsubscribe(topic string) error

	//断开连接
	Disconnect(quiesce uint)
}

返回的接口

func NewMqttClient

func NewMqttClient(param *MqttParam, handle MqttEventHandle) (MqttClientHandle, error)

type MqttConsumerHandle

type MqttConsumerHandle interface {
	//接收消息
	SubMessage(clientId string, topic string, messageId uint16, data []byte) error
}

使用者必须实现的接口

type MqttEventHandle

type MqttEventHandle interface {
	//连接事件
	ConnectEvent(clientId string) error

	//断开连接事件
	DisConnectEvent(clientId string, err error) error

	//重连事件
	ReconnectEvent(clientId string) error
}

使用者必须实现的接口

type MqttParam

type MqttParam struct {
	//连接地址,比如:tcp://foobar.com:1883
	Server string

	//客户端id
	ClientId string

	//用户名
	Username string

	//密码
	Password string

	//协议版本,3:3.1 4:3.1.1 5:5.0
	ProtocolVersion uint32

	//保持活跃的时间
	KeepAlive uint32

	//发送心跳时间
	PingTimeout uint32

	//连接超时
	ConnectTimeout uint32

	//最大重连间隔
	MaxReconnectInterval uint32

	//重连间隔
	ConnectRetryInterval uint32

	//清理会话
	CleanSession bool

	//自动重连
	AutoReconnect bool
}

最好不要直接使用这个结构,通过NewMqttParam得到有默认值

func NewMqttParam

func NewMqttParam() *MqttParam

Jump to

Keyboard shortcuts

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