mqttgo

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 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(config *Config, clientID string, onConnects ...func(c mqtt.Client, retryTimes uint64) (RetryType, error)) (mqtt.Client, error)

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

func NewClientConnect

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

func NewClientOptions

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

func OnConnectWithRetries added in v0.0.1

func OnConnectWithRetries(c mqtt.Client, onConnect func(c mqtt.Client, retryTimes uint64) (RetryType, error))

func SetLog

func SetLog(mqttLog Log)

Types

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 RetryType

type RetryType string
const (
	RetryTypeUnknown RetryType = "unknown"
	RetryTypeRetries RetryType = "retries"
	RetryTypeTimeout RetryType = "timeout"
	RetryTypeSuccess RetryType = "success"
)

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