lib

package
v0.6.11 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//Host     = "192.168.31.32:1883"
	//UserName = "root"
	//Password = "root"
	Host     = "47.116.75.143:1883"
	UserName = "client"
	Password = "hi2020go"
)

mqtt服务器配置

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

func NewClient

func NewClient(clientId string) *Client

func (*Client) Connect

func (client *Client) Connect() error

func (*Client) GetClientID

func (client *Client) GetClientID() string

func (*Client) Publish

func (client *Client) Publish(topic string, qos byte, retained bool, data []byte) error

发布消息 retained: 是否保留信息

func (*Client) Subscribe

func (client *Client) Subscribe(observer func(c *Client, msg *Message), qos byte, topics ...string) error

消费消息

func (*Client) Unsubscribe

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

type Message

type Message struct {
	// client_id
	ClientID string `json:"client_id"`
	// 接口名,订阅号通过识别接口名处理相应业务
	Action string `json:"action"`
	// 数据类型
	Type string `json:"type"`
	// 发布时间
	Time int64 `json:"time"`
	// 业务数据的header,可以携带一些系统参数
	Header interface{} `json:"header"`
	// 业务数据的body,业务参数
	Body interface{} `json:"body"`
}

Jump to

Keyboard shortcuts

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