mqtt

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BufferConfig

type BufferConfig struct {
	SendBufferSize    int `json:"send-buffer-size"`
	ReceiveBufferSize int `json:"receive-buffer-size"`
	MessageQueueSize  int `json:"message-queue-size"`
}

BufferConfig 缓冲区配置

type ClientConfig

type ClientConfig struct {
	ID                   string `json:"id"`
	Username             string `json:"username"`
	Password             string `json:"password"`
	CleanSession         bool   `json:"clean-session"`
	KeepAlive            int    `json:"keep-alive"`
	ConnectTimeout       int    `json:"connect-timeout"`
	AutoReconnect        bool   `json:"auto-reconnect"`
	ReconnectInterval    int    `json:"reconnect-interval"`
	MaxReconnectAttempts int    `json:"max-reconnect-attempts"`
}

ClientConfig 客户端配置

type LoggingConfig

type LoggingConfig struct {
	Debug               bool `json:"debug"`
	LogConnectionEvents bool `json:"log-connection-events"`
	LogMessageEvents    bool `json:"log-message-events"`
}

LoggingConfig 日志配置

type MQTTClient

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

MQTTClient MQTT 客户端包装器

func InitMQTT

func InitMQTT(opt *Options) *MQTTClient

InitMQTT 初始化 MQTT 客户端

func (*MQTTClient) Connect

func (m *MQTTClient) Connect() error

Connect 连接到 MQTT 服务器

func (*MQTTClient) Disconnect

func (m *MQTTClient) Disconnect()

Disconnect 断开连接

func (*MQTTClient) GetClient

func (m *MQTTClient) GetClient() mqtt.Client

GetClient 获取原始客户端

func (*MQTTClient) IsConnected

func (m *MQTTClient) IsConnected() bool

IsConnected 检查连接状态

func (*MQTTClient) Publish

func (m *MQTTClient) Publish(topic string, payload interface{}) error

Publish 发布消息

func (*MQTTClient) PublishWithQoS

func (m *MQTTClient) PublishWithQoS(topic string, payload interface{}, qos byte) error

PublishWithQoS 使用指定 QoS 发布消息

func (*MQTTClient) Subscribe

func (m *MQTTClient) Subscribe(topic string, callback mqtt.MessageHandler) error

Subscribe 订阅主题

func (*MQTTClient) SubscribeWithQoS

func (m *MQTTClient) SubscribeWithQoS(topic string, qos byte, callback mqtt.MessageHandler) error

SubscribeWithQoS 使用指定 QoS 订阅主题

func (*MQTTClient) Unsubscribe

func (m *MQTTClient) Unsubscribe(topics ...string) error

Unsubscribe 取消订阅

type MQTTServiceProvider

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

func (*MQTTServiceProvider) Boot

func (m *MQTTServiceProvider) Boot()

func (*MQTTServiceProvider) Conf added in v1.3.0

func (m *MQTTServiceProvider) Conf() map[string]string

func (*MQTTServiceProvider) Description added in v1.3.0

func (m *MQTTServiceProvider) Description() string

func (*MQTTServiceProvider) Register

func (m *MQTTServiceProvider) Register()

type MessageConfig

type MessageConfig struct {
	DefaultQoS byte `json:"default-qos"`
	Retain     bool `json:"retain"`
	Timeout    int  `json:"timeout"`
}

MessageConfig 消息配置

type Options

type Options struct {
	Broker       string             `json:"broker"`
	Client       ClientConfig       `json:"client"`
	TLS          TLSConfig          `json:"tls"`
	Message      MessageConfig      `json:"message"`
	Subscription SubscriptionConfig `json:"subscription"`
	Publish      PublishConfig      `json:"publish"`
	Logging      LoggingConfig      `json:"logging"`
	Buffer       BufferConfig       `json:"buffer"`
	Performance  PerformanceConfig  `json:"performance"`
}

Options MQTT 配置选项

type PerformanceConfig

type PerformanceConfig struct {
	MaxConcurrentConnections int `json:"max-concurrent-connections"`
	MessageHandlerCount      int `json:"message-handler-count"`
	BatchSize                int `json:"batch-size"`
}

PerformanceConfig 性能配置

type PublishConfig

type PublishConfig struct {
	DefaultQoS byte `json:"default-qos"`
	Timeout    int  `json:"timeout"`
	WaitForAck bool `json:"wait-for-ack"`
}

PublishConfig 发布配置

type SubscriptionConfig

type SubscriptionConfig struct {
	DefaultQoS byte `json:"default-qos"`
	Timeout    int  `json:"timeout"`
}

SubscriptionConfig 订阅配置

type TLSConfig

type TLSConfig struct {
	Enabled            bool   `json:"enabled"`
	CertFile           string `json:"cert-file"`
	KeyFile            string `json:"key-file"`
	CAFile             string `json:"ca-file"`
	InsecureSkipVerify bool   `json:"insecure-skip-verify"`
}

TLSConfig TLS/SSL 配置

Jump to

Keyboard shortcuts

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