From aa401d60483497466cfab89d52454c7521605675 Mon Sep 17 00:00:00 2001 From: what Date: Wed, 24 Apr 2024 09:44:46 +0800 Subject: [PATCH] =?UTF-8?q?[feat]=20Mqtt=20hook=20=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mqtt.go | 52 +++++++++++++++++++++++++--------------------------- 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/mqtt.go b/mqtt.go index 4a64539..d96e31d 100644 --- a/mqtt.go +++ b/mqtt.go @@ -1,6 +1,8 @@ package contracts -import "github.com/samber/do" +import ( + "github.com/samber/do" +) type MqttService interface { Start() error @@ -8,13 +10,19 @@ type MqttService interface { Restart() error // 消息推送 - // @param topic 订阅的主题 - // @param msg 传递的消息 - // @param retain 是否保留 - // @param qos 传递的消息, - // 0: 至多一次, 如果发送失败,也就算了 - // 1: 至少一次, 消息将确保至少被传递一次,但可能会重复发送 - // 2: 确保只有一次, 确保消息仅被传递一次且没有重复传递 + // + // Example: + // + // Parameters: + // topic 订阅的主题 + // msg 传递的消息 + // retain 是否保留 + // qos 传递的消息, + // 0: 至多一次, 如果发送失败,也就算了 + // 1: 至少一次, 消息将确保至少被传递一次,但可能会重复发送 + // 2: 确保只有一次, 确保消息仅被传递一次且没有重复传递 + // Returns: + // error - 执行结果 Publish(topic string, msg any, retain bool, qos byte) error // 关闭消息队列 @@ -32,15 +40,17 @@ type Mqtt interface { // 取消订阅事件 OnUnsubscribed(g GlobalParams, topic string) error // 消息发布事件 - OnMessage(g GlobalParams, topic string) error + OnMessage(g GlobalParams, topic string, retain bool, qos byte) error + // 消息被丢弃 + OnMessageDropped(g GlobalParams, topic string, retain bool, qos byte) error // 保留类型消息事件 - OnRetainMessage(g GlobalParams, topic string) error + // OnRetainMessage(g GlobalParams, topic string) error // Qos消息完成事件 - OnQosMessage(g GlobalParams, topic string) error + // OnQosMessage(g GlobalParams, topic string) error // 客户端超时事件 - OnClientExpired(GlobalParams) error + // OnClientExpired(GlobalParams) error // 保留消息超时事件 - OnRetainedExpired(g GlobalParams, topic string) error + // OnRetainedExpired(g GlobalParams, topic string) error } type MqttHandle struct { @@ -55,23 +65,11 @@ func (this MqttHandle) OnUnsubscribed(g GlobalParams, topic string) error { return nil } -func (this MqttHandle) OnMessage(g GlobalParams, topic string) error { +func (this MqttHandle) OnMessage(g GlobalParams, topic string, retain bool, qos byte) error { return nil } -func (this MqttHandle) OnRetainMessage(g GlobalParams, topic string) error { - return nil -} - -func (this MqttHandle) OnQosMessage(g GlobalParams, topic string) error { - return nil -} - -func (this MqttHandle) OnClientExpired(g GlobalParams) error { - return nil -} - -func (this MqttHandle) OnRetainedExpired(g GlobalParams, topic string) error { +func (this MqttHandle) OnMessageDropped(g GlobalParams, topic string, retain bool, qos byte) error { return nil }