Documentation
¶
Index ¶
- Constants
- Variables
- func LogLevelToInt(level LogLevel) int
- type Client
- func (c *Client) Close() error
- func (c *Client) GetClient() paho.Client
- func (c *Client) GetHandlerByTopic(topic string) (Handler, bool)
- func (c *Client) IsConnected() bool
- func (c *Client) Publish(topic string, qos byte, data []byte) error
- func (c *Client) RegisterHandler(handler Handler) error
- func (c *Client) SetLogLevel(level LogLevel)
- func (c *Client) SetLogger(logger Logger)
- func (c *Client) UnregisterHandler(topic string) error
- type Config
- type Handler
- type LogLevel
- type Logger
Constants ¶
View Source
const ( DefaultMaxReconnectInterval = time.Second * 60 DefaultQueueSize = 100 )
定义常量和错误
Variables ¶
View Source
var ( ErrNilHandler = errors.New("handler cannot be nil") ErrClientClosed = errors.New("client is closed") ErrInvalidConfig = errors.New("invalid configuration") ErrSubscriptionFailed = errors.New("subscription failed") ErrConnectionFailed = errors.New("connection failed") ErrPublishFailed = errors.New("publish failed") ErrUnsubscribeFailed = errors.New("unsubscribe failed") )
Functions ¶
Types ¶
type Client ¶
Client 实现MQTT客户端
func (*Client) GetHandlerByTopic ¶
GetHandlerByTopic 获取指定主题的处理器
func (*Client) RegisterHandler ¶
RegisterHandler 注册消息处理器
func (*Client) UnregisterHandler ¶
UnregisterHandler 注销消息处理器
type Config ¶
type Config struct {
Server string // MQTT broker地址
Username string // 用户名
Password string // 密码
MaxReconnectInterval time.Duration // 重连间隔
QOS uint8 // 服务质量等级
CleanSession bool // 清理会话标志
ClientID string // 客户端ID
CAFile string // CA证书文件
CertFile string // 客户端证书
CertKeyFile string // 客户端密钥
Logger Logger // 日志记录器
LogLevel LogLevel // 日志级别
QueueSize int // 消息队列大小
}
Config 定义客户端配置
type Handler ¶
type Handler struct {
Topic string // 订阅主题
Qos byte // 订阅QoS级别
Handle paho.MessageHandler // 消息处理函数
}
Handler 定义订阅数据处理器
Click to show internal directories.
Click to hide internal directories.