mqttgo

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewClient

func NewClient(clientOptions *mqtt.ClientOptions) (mqtt.Client, error)

func NewClientOptions

func NewClientOptions(cfg *Config, clientID string) *mqtt.ClientOptions

func NewClientWithCallback added in v0.0.2

func NewClientWithCallback(config *Config, clientID string, callback *Callback) (mqtt.Client, error)

NewClientWithCallback 客户端 cannot re-subscribe on reconnect,即,假如有订阅 topic,在客户端断开连接时就会断开订阅,而重连时却不能自动重新订阅。 在 https://github.com/eclipse/paho.mqtt.golang/issues/22 提到了解决方案 认为在 OnConnect 中调用订阅,是简单可靠的方案

func OnConnectWithRetries added in v0.0.1

func OnConnectWithRetries(client mqtt.Client, onConnect func(client mqtt.Client, retryTimes uint64) (CallbackState, error))

func SetLog

func SetLog(mqttLog Log)

Types

type Callback added in v0.0.2

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

func NewCallback added in v0.0.2

func NewCallback() *Callback

func (*Callback) OnConnect added in v0.0.2

func (C *Callback) OnConnect(onConnect func(client mqtt.Client, retryTimes uint64) (CallbackState, error)) *Callback

type CallbackState added in v0.0.2

type CallbackState string
const (
	CallbackUnknown CallbackState = "unknown"
	CallbackRetries CallbackState = "retries"
	CallbackTimeout CallbackState = "timeout"
	CallbackSuccess CallbackState = "success"
)

type Client

type Client = mqtt.Client

type Config

type Config struct {
	BrokerServer string
	Username     string
	Password     string
	OrderMatters bool
}

type Log

type Log interface {
	ErrorLog(msg string, fields ...zap.Field)
	DebugLog(msg string, fields ...zap.Field)
}

type Message

type Message = mqtt.Message

type Token

type Token = mqtt.Token

type TokenState added in v0.0.1

type TokenState string
const (
	TokenStateUnknown TokenState = "unknown"
	TokenStateTimeout TokenState = "timeout"
	TokenStateSuccess TokenState = "success"
)

func CheckToken added in v0.0.1

func CheckToken(token mqtt.Token, timeout time.Duration) (TokenState, error)

func WaitToken added in v0.0.1

func WaitToken(token mqtt.Token) (TokenState, error)

Jump to

Keyboard shortcuts

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