From d9244e0f0c1ed4bc5ce49256a733218e58c8a60f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Thu, 27 Jun 2024 18:52:20 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=95=B0=E6=8D=AE=E8=A7=A3?= =?UTF-8?q?=E6=9E=90=E5=A4=B1=E8=B4=A5=E7=9A=84=E5=9B=9E=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- abstract/IEvent.go | 13 +++++++++++++ define/handler.go | 9 +++++++++ redis_pub_sub.go | 25 +++++++++++++++++++------ 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/abstract/IEvent.go b/abstract/IEvent.go index 0f57d22..12cd6a6 100644 --- a/abstract/IEvent.go +++ b/abstract/IEvent.go @@ -54,6 +54,13 @@ type ConsumeSuccessCallback func(eventData *define.EventData, handleResult map[s // Date : 18:07 2024/6/26 type PanicCallback func(err any, eventData *define.EventData, handleResult map[string]any) +// EventParseFailCallback ... +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 18:48 2024/6/27 +type EventParseFailCallback func(err error, eventData string) + // IEvent 事件接口定义 // // Author : go_developer@163.com<白茶清欢> @@ -103,4 +110,10 @@ type IEvent interface { // // Date : 18:39 2024/6/27 SetPanicCallback(panicCallback PanicCallback) + // SetEventParseFailCallback 设置数据解析失败的处理函数 + // + // Author : go_developer@163.com<白茶清欢> + // + // Date : 18:51 2024/6/27 + SetEventParseFailCallback(parseFailCallbackCallback EventParseFailCallback) } diff --git a/define/handler.go b/define/handler.go index 897c346..305660f 100644 --- a/define/handler.go +++ b/define/handler.go @@ -48,3 +48,12 @@ func DefaultSendFailCallback(ctx context.Context, eventData *EventData, eventRes // // Date : 11:46 2024/6/27 func DefaultSendSuccessCallback(ctx context.Context, eventResult *SendResult) {} + +// DefaultParseFailCallbackFunc ... +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 18:49 2024/6/27 +func DefaultParseFailCallbackFunc(err error, eventData string) { + +} diff --git a/redis_pub_sub.go b/redis_pub_sub.go index 8b36554..7eb406a 100644 --- a/redis_pub_sub.go +++ b/redis_pub_sub.go @@ -45,12 +45,13 @@ func InitRedisPubSubEvent(redisClient *redis.Client, pubSubConfig *define.RedisE // // Date : 16:07 2024/6/25 type RedisEventPubSub struct { - redisClient *redis.Client // redis客户端 - pubSubConfig *define.RedisEventPubSubConfig // 事件配置 - messageChan chan *define.EventData // 消息队列 - stopConsumer chan bool // 停止消费者 - isStop bool // 是否已停止 - panicCallback abstract.PanicCallback // panic回调 + redisClient *redis.Client // redis客户端 + pubSubConfig *define.RedisEventPubSubConfig // 事件配置 + messageChan chan *define.EventData // 消息队列 + stopConsumer chan bool // 停止消费者 + isStop bool // 是否已停止 + panicCallback abstract.PanicCallback // panic回调 + parseFailCallback abstract.EventParseFailCallback // 数据解析失败回调 } // SendEvent 发布时间 @@ -131,6 +132,18 @@ func (r *RedisEventPubSub) SetPanicCallback(panicCallback abstract.PanicCallback r.panicCallback = panicCallback } +// SetEventParseFailCallback 设置事件解析失败回回调函数 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 18:42 2024/6/27 +func (r *RedisEventPubSub) SetEventParseFailCallback(parseFailCallbackCallback abstract.EventParseFailCallback) { + if nil == parseFailCallbackCallback { + parseFailCallbackCallback = define.DefaultParseFailCallbackFunc + } + r.parseFailCallback = parseFailCallbackCallback +} + // ConsumeEvent 获取数据消费实例 // // Author : go_developer@163.com<白茶清欢>