hxmqtt

package
v0.0.0-...-532f4bb Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MqttClient

type MqttClient struct {
	// contains filtered or unexported fields
}

func NewMqtt

func NewMqtt(config *MqttConf) (*MqttClient, error)

func (*MqttClient) Publish

func (p *MqttClient) Publish(topic string, qos byte, data []byte) error

func (*MqttClient) PublishTimeout

func (p *MqttClient) PublishTimeout(topic string, qos byte, data []byte, timeout time.Duration) (bool, error)

func (*MqttClient) Subscribe

func (p *MqttClient) Subscribe(topic string, qos byte, subCallback mqtt.MessageHandler) error

订阅单个主题

func (*MqttClient) SubscribeMultiple

func (p *MqttClient) SubscribeMultiple(filters map[string]byte, subCallback mqtt.MessageHandler) error

订阅多个主题,同一个回调处理函数

func (*MqttClient) Unsubscribe

func (p *MqttClient) Unsubscribe(topics []string) error

type MqttConf

type MqttConf struct {
	Uri      string // 格式"tcp://[ip]:[port]"
	Username string // 用户名
	Password string // 密码

	ConnectedFunc      mqtt.OnConnectHandler      // 连接成功回调函数
	LostConnFunc       mqtt.ConnectionLostHandler // 断开连接回调函数
	DefaultPublishFunc mqtt.MessageHandler        // 默认订阅回调函数
	ClientId           string                     // 客户端id(客户端唯一标识)
	AutoAckDisabled    bool                       // 禁用自动ack
	AutoReconnect      bool
	ConnectTimeout     time.Duration
}

func DefaultMqttConf

func DefaultMqttConf() *MqttConf

Jump to

Keyboard shortcuts

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