Skip to content

Commit

Permalink
feat: rocketmq add util func (#1082)
Browse files Browse the repository at this point in the history
Co-authored-by: 太一 <[email protected]>
  • Loading branch information
li-keli and 太一 committed Mar 28, 2024
1 parent 4f50ef5 commit 0c8e413
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions pkg/client/rocketmq/producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,28 @@ func (pc *Producer) SendWithMsg(ctx context.Context, msg *primitive.Message) err
}
return nil
}

// SendWithResult rocket mq 发送消息,可以自定义选择 tag 及返回结果
func (pc *Producer) SendWithResult(ctx context.Context, msg []byte, tag string) (*primitive.SendResult, error) {
m := primitive.NewMessage(pc.Topic, msg)
if tag != "" {
m.WithTag(tag)
}

res, err := pc.SendSync(ctx, m)
if err != nil {
xlog.Jupiter().Error("send message error", xlog.Any("msg", string(msg)))
return res, err
}
return res, nil
}

// SendMsg... 自定义消息格式
func (pc *Producer) SendMsg(ctx context.Context, msg *primitive.Message) (*primitive.SendResult, error) {
res, err := pc.SendSync(ctx, msg)
if err != nil {
xlog.Jupiter().Error("send message error", xlog.Any("msg", msg))
return res, err
}
return res, nil
}

0 comments on commit 0c8e413

Please sign in to comment.