mqtt

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func OnInit

func OnInit(config map[string]interface{}, option ...Optionfn) (err error)

func Publish

func Publish(topic string, qos byte, retained bool, payload interface{}) mqtt.Token

func Subscribe

func Subscribe(topic string, qos byte, callback mqtt.MessageHandler) mqtt.Token

Types

type DefMqttDoor

type DefMqttDoor struct{}

func (*DefMqttDoor) ConnectHandler

func (z *DefMqttDoor) ConnectHandler(client mqtt.Client)

连接的回掉函数

func (*DefMqttDoor) ConnectLostHandler

func (z *DefMqttDoor) ConnectLostHandler(client mqtt.Client, err error)

丢失连接的回掉函数

func (*DefMqttDoor) MessageHandler

func (z *DefMqttDoor) MessageHandler(client mqtt.Client, msg mqtt.Message)

创建全局 mqtt 消息处理 handler

type IMqtt

type IMqtt interface {
	Subscribe(topic string, qos byte, callback mqtt.MessageHandler) mqtt.Token
	Publish(topic string, qos byte, retained bool, payload interface{}) mqtt.Token
}

func NewSys

func NewSys(option ...Optionfn) (sys IMqtt, err error)

type IMqttDoor

type IMqttDoor interface {
	ConnectHandler(client mqtt.Client)
	ConnectLostHandler(client mqtt.Client, err error)
	MessageHandler(client mqtt.Client, msg mqtt.Message)
}

type Mqtt

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

func (*Mqtt) Publish

func (z *Mqtt) Publish(topic string, qos byte, retained bool, payload interface{}) mqtt.Token

func (*Mqtt) Subscribe

func (z *Mqtt) Subscribe(topic string, qos byte, callback mqtt.MessageHandler) mqtt.Token

type Optionfn

type Optionfn func(*Options)

func SetClientID

func SetClientID(v string) Optionfn

func SetMPassword

func SetMPassword(v string) Optionfn

func SetMqttAddr

func SetMqttAddr(v string) Optionfn

func SetMqttDoor

func SetMqttDoor(v IMqttDoor) Optionfn

func SetMqttPort

func SetMqttPort(v int) Optionfn

func SetUserName

func SetUserName(v string) Optionfn

type Options

type Options struct {
	MqttAddr string
	MqttPort int
	ClientID string
	UserName string
	PassWord string
	MqttDoor IMqttDoor
}

Jump to

Keyboard shortcuts

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