mqtx

package
v0.2.7 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeMessage

func DecodeMessage(payload []byte) (*map[string]interface{}, error)

DecodeMessage 解码消息

func Init

func Init()

Init 初始化mqtt

func RegisterMQTT

func RegisterMQTT(aliasName string, conf *Config)

RegisterMQTT 注册mqtt

Types

type Client

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

Client mqtt客户端

func MQ

func MQ(name ...string) *Client

MQ 根据名称获取mq客户端

func (*Client) Connect

func (c *Client) Connect() error

Connect 连接

func (*Client) GetClientID

func (c *Client) GetClientID() string

GetClientID 获取客户端ID

func (*Client) Publish

func (c *Client) Publish(topic string, data interface{}, qos QoS) error

Publish 发布消息,topic主题,data发送数据,qos发送等级

func (*Client) Subscribe

func (c *Client) Subscribe(qos QoS, observer func(c *Client, payload []byte), topics ...string) error

Subscribe 订阅消息

func (*Client) Unsubscribe

func (c *Client) Unsubscribe(topics ...string)

Unsubscribe 取消订阅

type Config

type Config struct {
	Name     string `mapstructure:"name"`
	Host     string `mapstructure:"host"`
	Port     int    `mapstructure:"port"`
	User     string `mapstructure:"user"`
	Password string `mapstructure:"password"`
	ClientID string `mapstructure:"client_id"`
}

Config mqtt配置

type QoS

type QoS int32

QoS 消息发送策略类型

const (
	// QoS0 最多一次
	QoS0 QoS = 0
	// QoS1 至少一次
	QoS1 QoS = 1
	// QoS2 只有一次
	QoS2 QoS = 2
)

Jump to

Keyboard shortcuts

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