gomqtt

package module
v0.0.0-...-917e98d Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2023 License: MIT Imports: 3 Imported by: 0

README

gomqtt


Requirements

gomqtt library requires Go version >=1.14

拉取代码

go get -u github.com/jellycheng/gomqtt
    或者
GO111MODULE=on GOPROXY=https://goproxy.cn/,direct go get -u github.com/jellycheng/gomqtt

直接拉取master分支代码:
    go get -u github.com/jellycheng/gomqtt@master

Documentation

Index

Constants

View Source
const (
	QoS0 byte = 0 //最多一次,即:<=1,消息可能丢失
	QoS1 byte = 1 //至少一次,即:>=1,消息不会丢失,但可能重复
	QoS2 byte = 2 //一次,即:=1,消息不会丢失,也不会重复
)

Variables

This section is empty.

Functions

func NewMqttClient

func NewMqttClient(opts *mqtt.ClientOptions) (mqtt.Client, error)

func Publish

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

Publish 发消息

func Subscribe

func Subscribe(client mqtt.Client, topic string, qos byte, callback mqtt.MessageHandler) error

Subscribe 订阅消息/消费消息

Types

type MqttConfig

type MqttConfig struct {
	Broker   string //mqtt地址,示例:tcp://broker.emqx.io:1883
	Username string //账号
	Pwd      string //密码
	ClientID string //客户端id
	// contains filtered or unexported fields
}

func NewMqttConfig

func NewMqttConfig(broker string, opts ...MqttConfigOption) *MqttConfig

func (*MqttConfig) GetClientOptions

func (m *MqttConfig) GetClientOptions() *mqtt.ClientOptions

type MqttConfigManage

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

func NewMqttConfigManage

func NewMqttConfigManage() *MqttConfigManage

func (MqttConfigManage) Get

func (m MqttConfigManage) Get(group string) (*MqttConfig, error)

func (MqttConfigManage) GetAll

func (m MqttConfigManage) GetAll() map[string]*MqttConfig

func (*MqttConfigManage) Set

func (m *MqttConfigManage) Set(group string, mqttCfg *MqttConfig) *MqttConfigManage

type MqttConfigOption

type MqttConfigOption func(m *MqttConfig)

func WithMqttConfigBroker

func WithMqttConfigBroker(broker string) MqttConfigOption

func WithMqttConfigClientID

func WithMqttConfigClientID(id string) MqttConfigOption

func WithMqttConfigPwd

func WithMqttConfigPwd(pwd string) MqttConfigOption

func WithMqttConfigUsername

func WithMqttConfigUsername(username string) MqttConfigOption

Jump to

Keyboard shortcuts

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