From 7d55b17630788e5f100ef9414da8e88ee4bf80b5 Mon Sep 17 00:00:00 2001 From: what Date: Tue, 23 Apr 2024 09:49:28 +0800 Subject: [PATCH] =?UTF-8?q?[feat]=20mqtt=20=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mqtt.go | 40 ++++++++++++++++++++++------------------ service.go | 2 ++ 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/mqtt.go b/mqtt.go index 9c767a0..4a64539 100644 --- a/mqtt.go +++ b/mqtt.go @@ -2,7 +2,7 @@ package contracts import "github.com/samber/do" -type Mqtt interface { +type MqttService interface { Start() error Stop() error Restart() error @@ -21,58 +21,62 @@ type Mqtt interface { Close(origin string) } -type MqttController interface { +type Mqtt interface { Controller + // 链接 + // OnConnect(g GlobalParams, topic string) error + // 断开链接 + // OnDisconnect(g GlobalParams, topic string) error // 订阅事件 - OnSubscribed(GlobalParams) error + OnSubscribed(g GlobalParams, topic string) error // 取消订阅事件 - OnUnsubscribed(GlobalParams) error + OnUnsubscribed(g GlobalParams, topic string) error // 消息发布事件 - OnMessage(GlobalParams) error + OnMessage(g GlobalParams, topic string) error // 保留类型消息事件 - OnRetainMessage(GlobalParams) error + OnRetainMessage(g GlobalParams, topic string) error // Qos消息完成事件 - OnQosMessage(GlobalParams) error + OnQosMessage(g GlobalParams, topic string) error // 客户端超时事件 OnClientExpired(GlobalParams) error // 保留消息超时事件 - OnRetainedExpired(GlobalParams) error + OnRetainedExpired(g GlobalParams, topic string) error } -type MqttHandleController struct { +type MqttHandle struct { Controller } -func (this MqttHandleController) OnSubscribed(g GlobalParams) error { +func (this MqttHandle) OnSubscribed(g GlobalParams, topic string) error { return nil } -func (this MqttHandleController) OnUnsubscribed(g GlobalParams) error { +func (this MqttHandle) OnUnsubscribed(g GlobalParams, topic string) error { return nil } -func (this MqttHandleController) OnMessage(g GlobalParams) error { +func (this MqttHandle) OnMessage(g GlobalParams, topic string) error { return nil } -func (this MqttHandleController) OnRetainMessage(g GlobalParams) error { +func (this MqttHandle) OnRetainMessage(g GlobalParams, topic string) error { return nil } -func (this MqttHandleController) OnQosMessage(g GlobalParams) error { +func (this MqttHandle) OnQosMessage(g GlobalParams, topic string) error { return nil } -func (this MqttHandleController) OnClientExpired(g GlobalParams) error { +func (this MqttHandle) OnClientExpired(g GlobalParams) error { return nil } -func (this MqttHandleController) OnRetainedExpired(g GlobalParams) error { +func (this MqttHandle) OnRetainedExpired(g GlobalParams, topic string) error { return nil } -func NewMqttController(container *do.Injector) MqttController { - return &MqttHandleController{ +func NewMqttController(container *do.Injector) Mqtt { + return &MqttHandle{ Controller: &BaseController{container}, } } diff --git a/service.go b/service.go index e5ea569..fa7f22a 100644 --- a/service.go +++ b/service.go @@ -7,9 +7,11 @@ type Service interface { RegGRpcs(items map[string]GRpc) error RegJobs(items map[string]Job) error RegCrons(items map[string]Cron) error + RegMqtts(items map[string]Mqtt) error GetResListener(code string) (ResListener, bool) GetAppController(code string) (Controller, bool) GetAppGRpc(code string) (GRpc, bool) GetAppJob(code string) (Job, bool) GetAppCron(code string) (Cron, bool) + GetAppMqtt(code string) (Mqtt, bool) }