From f3fd54906ff682a367cbd68c6635d19b145cefc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Wed, 6 Jul 2022 18:58:59 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=94=9F=E4=BA=A7=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E7=BB=93=E6=9E=84=E7=9A=84=E5=AE=9A=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- delay/define.go | 11 +++++++++++ delay/redis_produce.go | 7 ++++++- go.mod | 9 +++++++++ go.sum | 19 +++++++++++++++++++ 4 files changed, 45 insertions(+), 1 deletion(-) diff --git a/delay/define.go b/delay/define.go index 29a5e54..7a3acc5 100644 --- a/delay/define.go +++ b/delay/define.go @@ -7,6 +7,17 @@ // Date : 2022-07-06 17:55 package delay +// ProduceData 生产的数据结构 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 18:56 2022/7/6 +type ProduceData struct { + MsgID string `json:"msg_id"` // 消息ID + Timestamp int64 `json:"timestamp"` // 消息生成时间: ms + Data map[string]interface{} `json:"data"` // 传入的业务数据 +} + // Queue 队列数据 // // Author : go_developer@163.com<白茶清欢> diff --git a/delay/redis_produce.go b/delay/redis_produce.go index 31b100f..b2cdbf0 100644 --- a/delay/redis_produce.go +++ b/delay/redis_produce.go @@ -13,6 +13,7 @@ import ( "sync" "time" + "git.zhangdeman.cn/zhangdeman/util" "github.com/go-redis/redis/v8" ) @@ -65,7 +66,11 @@ func (rp *redisProduce) Produce(ctx context.Context, data ...*Queue) error { // // Date : 18:22 2022/7/6 func (rp *redisProduce) buildAddMember(queueData *Queue) *redis.Z { - byteData, _ := json.Marshal(queueData) + byteData, _ := json.Marshal(&ProduceData{ + MsgID: util.String.Md5(util.String.GenRandom("", 16)), + Timestamp: time.Now().UnixNano() / 1e6, + Data: queueData.Data, + }) return &redis.Z{ Score: float64(time.Now().Unix() + queueData.DelayTime), Member: string(byteData), diff --git a/go.mod b/go.mod index acc6ec9..7753716 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,16 @@ module git.zhangdeman.cn/zhangdeman/queue go 1.17 require ( + git.zhangdeman.cn/zhangdeman/util v0.0.0-20220704053716-ec9271c0f350 // indirect + github.com/Jeffail/gabs v1.4.0 // indirect github.com/cespare/xxhash/v2 v2.1.2 // indirect github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect + github.com/go-ini/ini v1.66.6 // indirect github.com/go-redis/redis/v8 v8.11.5 // indirect + github.com/pkg/errors v0.9.1 // indirect + github.com/spaolacci/murmur3 v1.1.0 // indirect + github.com/tidwall/gjson v1.14.1 // indirect + github.com/tidwall/match v1.1.1 // indirect + github.com/tidwall/pretty v1.2.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 8dfa85a..f1991c3 100644 --- a/go.sum +++ b/go.sum @@ -1,6 +1,25 @@ +git.zhangdeman.cn/zhangdeman/util v0.0.0-20220704053716-ec9271c0f350 h1:y54/TJ7SCSG1LlKrX7QebDBdv+JoEl8JVs2kEqFoEXs= +git.zhangdeman.cn/zhangdeman/util v0.0.0-20220704053716-ec9271c0f350/go.mod h1:aAIhnUdQewLipl4bddewAsAeSLST9SRvgTcPN5ITkAQ= +github.com/Jeffail/gabs v1.4.0 h1://5fYRRTq1edjfIrQGvdkcd22pkYUrHZ5YC/H2GJVAo= +github.com/Jeffail/gabs v1.4.0/go.mod h1:6xMvQMK4k33lb7GUUpaAPh6nKMmemQeg5d4gn7/bOXc= github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE= github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= +github.com/go-ini/ini v1.66.6 h1:h6k2Bb0HWS/BXXHCXj4QHjxPmlIU4NK+7MuLp9SD+4k= +github.com/go-ini/ini v1.66.6/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8= github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI= github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI= +github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= +github.com/tidwall/gjson v1.14.1 h1:iymTbGkQBhveq21bEvAQ81I0LEBork8BFe1CUZXdyuo= +github.com/tidwall/gjson v1.14.1/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= +github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= +github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= +github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs= +github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=