gomqtt

package
v1.2.47 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

README

MQTT Go client

mqtt server 事件中心

Documentation

Index

Constants

View Source
const (
	PROTOCOL_TCP = "tcp"
	PROTOCOL_SSL = "ssl"
	PROTOCOL_WS  = "ws"
	PROTOCOL_WSS = "wss"
)

Variables

This section is empty.

Functions

func Init added in v1.2.42

func Init(configs ...Config) (err error)

Types

type Config

type Config struct {
	Name             string `yaml:"Name,optional" json:"name,optional"`
	Protocol         string `yaml:"Protocol,optional" json:"protocol,optional"`
	CaFilePath       string `yaml:"CaFilePath,optional" json:"caFilePath,optional"` //tls(ssl wss) 证书位置
	Server           string `yaml:"Server,optional" json:"server,optional"`
	Port             int    `yaml:"Port,optional" json:"port,optional"`
	ClientId         string `yaml:"ClientId,optional" json:"clientId,optional"`
	User             string `yaml:"User,optional" json:"user,optional"`
	Secret           string `yaml:"Secret,optional" json:"secret,optional"`
	KeepAlive        int64  `yaml:"KeepAlive,optional" json:"keepAlive,optional"` //s
	AutoReconnect    bool   `yaml:"AutoReconnect,optional" json:"autoReconnect,optional"`
	ConnectRetry     bool   `yaml:"ConnectRetry,optional" json:"connectRetry,optional"`
	ConnectTimeout   int64  `yaml:"ConnectTimeout,optional" json:"connectTimeout,optional"`
	DefaultHandler   *mqtt.MessageHandler
	OnConnect        *mqtt.OnConnectHandler
	OnConnectionLost *mqtt.ConnectionLostHandler
}

type GoMqttClient

type GoMqttClient struct {
	Client mqtt.Client
}

func Client added in v1.2.42

func Client() *GoMqttClient

func GetClient added in v1.2.42

func GetClient(names ...string) *GoMqttClient

func NewClient added in v1.2.42

func NewClient(config Config) (*GoMqttClient, error)

func NewConfig

func NewConfig(opts *mqtt.ClientOptions) (*GoMqttClient, error)

func (*GoMqttClient) Connect

func (g *GoMqttClient) Connect() error

func (*GoMqttClient) Disconnect

func (g *GoMqttClient) Disconnect(quiesce uint)

func (*GoMqttClient) Publish

func (g *GoMqttClient) Publish(topic string, qos byte, retained bool, payload interface{}) error

func (*GoMqttClient) Subscribe

func (g *GoMqttClient) Subscribe(topic string, qos byte, callback mqtt.MessageHandler) error

func (*GoMqttClient) Unsubscribe

func (g *GoMqttClient) Unsubscribe(topics ...string) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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