49 lines
1.1 KiB
Go
49 lines
1.1 KiB
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"github.com/go-kratos/kratos/v2/log"
|
|
"strconv"
|
|
"voucher/internal/pkg/mq"
|
|
)
|
|
|
|
func (j *VoucherService) GetNotifyRetryConfig() *mq.ConsumerConfig {
|
|
elm, ok := j.bc.RocketMQ.EventMap["notifyRetry"]
|
|
if !ok {
|
|
return nil
|
|
}
|
|
|
|
if !elm.IsOpenConsumer {
|
|
log.Warnf("notify MQ is not open")
|
|
return nil
|
|
}
|
|
|
|
return &mq.ConsumerConfig{
|
|
TopicName: elm.Topic,
|
|
GroupName: elm.Group,
|
|
PerCoroutineCnt: int(elm.PerCoroutineCnt),
|
|
}
|
|
}
|
|
|
|
func (j *VoucherService) NotifyRetryConsumer(ctx context.Context, msg *mq.ConsumerMessage) error {
|
|
|
|
shardingKey := msg.GetShardingKey()
|
|
if len(shardingKey) == 0 {
|
|
log.Error("notify retry 消费异常,获取 shardingKey 失败")
|
|
return errors.New("orderNotify 消费异常,获取 orderNo 失败")
|
|
}
|
|
|
|
orderNotifyId, err := strconv.ParseUint(shardingKey, 10, 64)
|
|
if err != nil {
|
|
log.Error("notify retry 消费异常,orderNotifyId转换失败,shardingKey=%s", shardingKey)
|
|
return err
|
|
}
|
|
|
|
if err = j.VoucherBiz.NotifyRetryConsume(ctx, orderNotifyId); err != nil {
|
|
log.Errorf("notify retry 消费异常,shardingKey:%s,error: %s", shardingKey, err.Error())
|
|
}
|
|
|
|
return nil
|
|
}
|