mqtt

package
v0.0.0-...-a89011a Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Client mqtt客户端

func NewClient

func NewClient(conf Config) (*Client, error)

NewClient 创建一个MQTT客户端实例

func (*Client) Close

func (b *Client) Close() error

func (*Client) GetHandlerByUpTopic

func (b *Client) GetHandlerByUpTopic(topic string) Handler

GetHandlerByUpTopic 通过主题获取数据处理器

func (*Client) Publish

func (b *Client) Publish(topic string, qos byte, data []byte) error

Publish 发布数据

func (*Client) RegisterHandler

func (b *Client) RegisterHandler(handler Handler)

RegisterHandler 注册订阅数据处理器

func (*Client) UnregisterHandler

func (b *Client) UnregisterHandler(topic string) error

UnregisterHandler 删除订阅数据处理器

type Config

type Config struct {
	//mqtt broker 地址
	Server string
	//用户名
	Username string
	//密码
	Password string
	//重连重试间隔
	MaxReconnectInterval time.Duration
	QOS                  uint8
	CleanSession         bool
	//client Id
	ClientID    string
	CAFile      string
	CertFile    string
	CertKeyFile string
}

Config 客户端配置

type Handler

type Handler struct {
	//订阅主题
	Topic string
	//订阅Qos
	Qos byte
	//接收订阅数据 处理
	Handle func(c paho.Client, data paho.Message)
}

Handler 订阅数据处理器

Jump to

Keyboard shortcuts

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