diff --git a/internal/data/mq_test.go b/internal/data/mq_test.go index 8b4af8b..b0299d7 100644 --- a/internal/data/mq_test.go +++ b/internal/data/mq_test.go @@ -49,10 +49,18 @@ func Test_NotifyProducer(t *testing.T) { Topic: "voucher_order_notifyRetry", } + //c := &conf.RocketMQ{ + // Addr: "http://rmq-cn-nwy3fn4ex09.cn-chengdu.rmq.aliyuncs.com:8080", + // AccessKey: "Qecl4cea2IAZPKoD", + // SecretKey: "Z3596KCFA9RAUR6k", + // SecretToken: "", + // EventMap: m, + //} + c := &conf.RocketMQ{ - Addr: "http://rmq-cn-nwy3fn4ex09.cn-chengdu.rmq.aliyuncs.com:8080", - AccessKey: "Qecl4cea2IAZPKoD", - SecretKey: "Z3596KCFA9RAUR6k", + Addr: "http://rmq-cn-j4g3zpaiz06-vpc.cn-beijing.rmq.aliyuncs.com:8080", + AccessKey: "X3Dc7lRupY2bWc91", + SecretKey: "5G4h85f4my10P4vK", SecretToken: "", EventMap: m, } @@ -64,7 +72,7 @@ func Test_NotifyProducer(t *testing.T) { } ctx := context.Background() - shardingKey := "3" + shardingKey := "22" eventMap := c.EventMap["notifyRetry"] sendOption := []mq.SendOption{ diff --git a/internal/server/http.go b/internal/server/http.go index 4e7adab..adcfbb3 100644 --- a/internal/server/http.go +++ b/internal/server/http.go @@ -36,6 +36,8 @@ func NewHTTPServer( return ctx.String(http2.StatusOK, "pong") }) + srv.Route("/voucher/").GET("notifyRetry/{id}", cmb.NotifyRetry) + v1.RegisterCmbHTTPServer(srv, cmb) return srv diff --git a/internal/service/cmb.go b/internal/service/cmb.go index 4a76c18..54bea42 100644 --- a/internal/service/cmb.go +++ b/internal/service/cmb.go @@ -2,8 +2,11 @@ package service import ( "context" + "fmt" "github.com/go-kratos/kratos/v2/log" + "github.com/go-kratos/kratos/v2/transport/http" "github.com/robfig/cron" + "strconv" v1 "voucher/api/v1" "voucher/internal/biz" "voucher/internal/biz/bo" @@ -55,3 +58,17 @@ func (c *CmbService) GetResponse(ctx context.Context, replyBizContent []byte) (* return reply, nil } + +func (this *CmbService) NotifyRetry(ctx http.Context) error { + id := ctx.Vars().Get("id") + if id == "" { + return fmt.Errorf("id is empty") + } + + orderNotifyId, err := strconv.ParseUint(id, 10, 64) + if err != nil { + return err + } + + return this.VoucherBiz.PushNotifyRetryDelayMQ(ctx, 1, orderNotifyId) +}