消息能力升级 #1
@ -8,7 +8,8 @@
|
|||||||
package define
|
package define
|
||||||
|
|
||||||
const (
|
const (
|
||||||
DefaultPartitionNum = 1
|
DefaultRedisPartitionNum = 1
|
||||||
|
DefaultRedisTopic = "EVENT_TOPIC_C6DBE0AAE846C5C0DE35802107326B1E"
|
||||||
)
|
)
|
||||||
|
|
||||||
// RedisEventPubSubConfig redis事件配置
|
// RedisEventPubSubConfig redis事件配置
|
||||||
|
@ -11,7 +11,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"git.zhangdeman.cn/zhangdeman/event/abstract"
|
"git.zhangdeman.cn/zhangdeman/event/abstract"
|
||||||
"git.zhangdeman.cn/zhangdeman/event/define"
|
"git.zhangdeman.cn/zhangdeman/event/define"
|
||||||
"git.zhangdeman.cn/zhangdeman/wrapper"
|
|
||||||
"github.com/redis/go-redis/v9"
|
"github.com/redis/go-redis/v9"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -41,7 +40,6 @@ func InitRedisPubSubEvent(redisClient *redis.Client, pubSubConfig *define.RedisE
|
|||||||
type RedisEventPubSub struct {
|
type RedisEventPubSub struct {
|
||||||
redisClient *redis.Client // redis客户端
|
redisClient *redis.Client // redis客户端
|
||||||
pubSubConfig *define.RedisEventPubSubConfig // 事件配置
|
pubSubConfig *define.RedisEventPubSubConfig // 事件配置
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *RedisEventPubSub) SendEvent(ctx context.Context, eventData *define.EventData) (*define.SendResult, error) {
|
func (r *RedisEventPubSub) SendEvent(ctx context.Context, eventData *define.EventData) (*define.SendResult, error) {
|
||||||
@ -102,10 +100,10 @@ func (r *RedisEventPubSub) SetRedisClient(redisClient *redis.Client, pubSubConfi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(pubSubConfig.Topic) == 0 {
|
if len(pubSubConfig.Topic) == 0 {
|
||||||
pubSubConfig.Topic = "EVENT_TOPIC_" + wrapper.StringFromRandom(128, "").Md5().Value
|
pubSubConfig.Topic = define.DefaultRedisTopic
|
||||||
}
|
}
|
||||||
if pubSubConfig.PartitionNum <= 0 {
|
if pubSubConfig.PartitionNum <= 0 {
|
||||||
pubSubConfig.PartitionNum = define.DefaultPartitionNum
|
pubSubConfig.PartitionNum = define.DefaultRedisPartitionNum
|
||||||
}
|
}
|
||||||
r.redisClient = redisClient
|
r.redisClient = redisClient
|
||||||
r.pubSubConfig = pubSubConfig
|
r.pubSubConfig = pubSubConfig
|
||||||
|
19
redis_pub_sub_test.go
Normal file
19
redis_pub_sub_test.go
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
// Package event ...
|
||||||
|
//
|
||||||
|
// Description : event ...
|
||||||
|
//
|
||||||
|
// Author : go_developer@163.com<白茶清欢>
|
||||||
|
//
|
||||||
|
// Date : 2024-06-25 16:51
|
||||||
|
package event
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"git.zhangdeman.cn/zhangdeman/wrapper"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestInitRedisPubSubEvent(t *testing.T) {
|
||||||
|
fmt.Println(strings.ToUpper(wrapper.StringFromRandom(128, "").Md5().Value))
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user