xmqtt

package
v1.5.15 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2022 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotExists   = errors.New("mqtt not exists")
	ErrLostConnect = errors.New("mqtt connection lost")
)

Functions

This section is empty.

Types

type Client

type Client struct {
	Ops      *mqtt.ClientOptions
	Mqtt     mqtt.Client
	SubFuncs map[string]mqtt.MessageHandler // key:topic#qos, value: callback func
	// contains filtered or unexported fields
}

func New

func New(c *Config) (mc *Client)

New 1、New()

func (*Client) Close

func (c *Client) Close()

Close 主动断开连接

func (*Client) DefaultOnConnectFunc

func (c *Client) DefaultOnConnectFunc(cli mqtt.Client)

func (*Client) OnConnectListener

func (c *Client) OnConnectListener(fun mqtt.OnConnectHandler) (mc *Client)

OnConnectListener 2、设置链接监听

func (*Client) OnConnectLostListener

func (c *Client) OnConnectLostListener(fun mqtt.ConnectionLostHandler) (mc *Client)

OnConnectLostListener 3、设置断开链接监听

func (*Client) Publish

func (c *Client) Publish(topic string, qos QosType, payload interface{}) error

Publish 推送消息

func (*Client) StartAndConnect

func (c *Client) StartAndConnect() (err error)

StartAndConnect 4、真实创建Client并连接mqtt

func (*Client) Subscribe

func (c *Client) Subscribe(topic string, qos QosType, callback mqtt.MessageHandler) error

Subscribe 订阅topic

func (*Client) UnSubscribe

func (c *Client) UnSubscribe(topics ...string) error

UnSubscribe 取消订阅topic

type Config

type Config struct {
	Host           string // host地址
	Port           int    // TCP 端口
	ClientId       string
	Uname          string
	Password       string
	KeepAlive      int // 单位秒
	IsCleanSession bool
}

type QosType

type QosType byte
const (
	QosAtMostOne  QosType = 0
	QosAtLeastOne QosType = 1
	QosOnlyOne    QosType = 2
)

Jump to

Keyboard shortcuts

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