gomqtt

package
v1.2.57 Latest Latest
Warning

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

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

README

MQTT Go client

mqtt server 事件中心

注意

  • 每个客户端都需要单独的 ClientId ,不能重复

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" json:"name,optional"`
	Protocol         string `yaml:"Protocol" json:"protocol,optional"`
	CaFilePath       string `yaml:"CaFilePath" json:"caFilePath,optional"` //tls(ssl wss) 证书位置
	Server           string `yaml:"Server" json:"server,optional"`
	Port             int    `yaml:"Port" json:"port,optional"`
	ClientId         string `yaml:"ClientId" json:"clientId,optional"`
	User             string `yaml:"User" json:"user,optional"`
	Secret           string `yaml:"Secret" json:"secret,optional"`
	KeepAlive        int64  `yaml:"KeepAlive" json:"keepAlive,optional"` //s
	AutoReconnect    bool   `yaml:"AutoReconnect" json:"autoReconnect,optional"`
	ConnectRetry     bool   `yaml:"ConnectRetry" json:"connectRetry,optional"`
	ConnectTimeout   int64  `yaml:"ConnectTimeout" 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