Documentation ¶
Index ¶
Constants ¶
View Source
const ( ConnectEvent = "ConnectEvent" DisconnectEvent = "DisconnectEvent" NullEvent = "NullEvent" )
Variables ¶
View Source
var MqttList = CreateSafeMQTTList()
MqttList MQTT 客户端列表
View Source
var MqttRespOption = &MqttRespOptionType{
SuccessCode: 1000,
ErrorCode: 1001,
SuccessMsg: "SUCCESS!!!",
ErrorMsg: "ERROR!!!",
}
View Source
var SendDefaultQos byte = 0
Functions ¶
func CreateClient ¶
func CreateClient(optionHandler func(*ClientCallBackOption, *Config))
CreateClient 创建客户端
Types ¶
type Client ¶
type Client struct { IsInit bool // Cfg 配置 Cfg *Config // Client 客户端 Client *mqtt.Client // MessageCallbackFunc 接收到消息时触发函数 MessageCallbackFunc MessageHandler // OnConnectCallBackFunc 连接成功时触发函数 OnConnectCallBackFunc mqtt.OnConnectHandler }
Client 客户端结构对象
func (*Client) SetMessageCallbackFunc ¶
func (t *Client) SetMessageCallbackFunc(fn MessageHandler) *Client
SetMessageCallbackFunc 接收到消息时触发函数
func (*Client) SetOnConnectCallBackFunc ¶
func (t *Client) SetOnConnectCallBackFunc(fn mqtt.OnConnectHandler) *Client
type ClientCallBackOption ¶
type ClientCallBackOption struct { // MessageCallbackFunc 接收到消息时触发函数 MessageCallbackFunc MessageHandler // OnConnectCallBackFunc 连接成功时触发函数 OnConnectCallBackFunc mqtt.OnConnectHandler }
ClientCallBackOption 客户端回调设置
type Config ¶
type Config struct { Name string `json:"name"` // name 名称 Debug bool `json:"debug"` // debug 调试模式 MqttUrl string `json:"mqttUrl"` // mqtt 链接地址 ClientId string `json:"clientId"` // 客户端 id Subscribe string `json:"subscribe"` // 订阅地址 Qos byte `json:"qos"` // qos Username string `json:"username"` // 用户名 Password string `json:"password"` // 密码 Ping int `json:"ping"` // ping 频率 CleanSession bool `json:"cleanSession"` // cleanSession }
type EventHandlerData ¶
type EventHandlerData struct { MsgHandlerData *MessageHandlerData EventData any }
EventHandlerData 事件处理数据
func (*EventHandlerData) GetJson ¶
func (t *EventHandlerData) GetJson() (json *gjson.Json)
GetJson 获取 JSON 对象
type MessageHandler ¶
type MessageHandler func(handlerData *MessageHandlerData)
MessageHandler 消息处理函数
type MessageHandlerData ¶
type MessageHandlerData struct { // XMQTT 本扩展 MQTT 操作对象 XMQTT *Client // OMQTT 原始 MQTT 操作对象 OMQTT mqtt.Client // Message 接收到的消息操作对象 Message mqtt.Message }
func (*MessageHandlerData) GetEvent ¶
func (t *MessageHandlerData) GetEvent() (eventName string, data any, err error)
GetEvent 获取事件
func (*MessageHandlerData) GetMessageId ¶
func (t *MessageHandlerData) GetMessageId() uint16
GetMessageId 获取 messageId
func (*MessageHandlerData) GetTopic ¶
func (t *MessageHandlerData) GetTopic() string
GetTopic 获取 topic
type MqttResp ¶
type MqttResp struct {
// contains filtered or unexported fields
}
MqttResp MQTT 返回数据
func CreateMqttResp ¶
type MqttRespOptionType ¶
type SafeMQTTList ¶
SafeMQTTList 安全 MQTT 列表
func (*SafeMQTTList) Set ¶
func (t *SafeMQTTList) Set(mqttName string, client *Client)
Set 设置 MQTT 客户端对象
type SystemConnectEvent ¶
SystemConnectEvent 系统客户端连接事件
func IsSystemConnectEvent ¶
func IsSystemConnectEvent(message, topic string) (*SystemConnectEvent, bool, error)
IsSystemConnectEvent 是否为监听系统连接事件
func (*SystemConnectEvent) IsCurrentService ¶
func (t *SystemConnectEvent) IsCurrentService(clientId string) bool
IsCurrentService 是否为当前服务
Click to show internal directories.
Click to hide internal directories.