From 2289559d7a44e4dfc9f14240f724ed7f5cfac9c5 Mon Sep 17 00:00:00 2001 From: loshiqi <553578653@qq.com> Date: Thu, 3 Nov 2022 15:35:31 +0800 Subject: [PATCH] =?UTF-8?q?mq=E5=8F=91=E9=80=81=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- conn.go | 9 +++++++++ conn_test.go | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/conn.go b/conn.go index 46d172f..093612b 100644 --- a/conn.go +++ b/conn.go @@ -1,6 +1,8 @@ package rocketmq import ( + "context" + "errors" "github.com/apache/rocketmq-client-go/v2" "github.com/apache/rocketmq-client-go/v2/primitive" "github.com/apache/rocketmq-client-go/v2/producer" @@ -26,3 +28,10 @@ func MqConnect(group string, resolver []string) { } MqPool = p } +func SendSync(ctx context.Context, mq *primitive.Message) (*primitive.SendResult, error) { + var res primitive.SendResult + if MqPool == nil { + return &res, errors.New("Mq未链接") + } + return MqPool.SendSync(ctx, mq) +} diff --git a/conn_test.go b/conn_test.go index 921f6ca..a50a371 100644 --- a/conn_test.go +++ b/conn_test.go @@ -20,7 +20,7 @@ func Test_Send(t *testing.T) { msg_str, _ := json.Marshal(mq_data) msg1 := primitive.NewMessage(topic, msg_str) msg1.WithTag(tag) - res, err := MqPool.SendSync(context.Background(), msg1) + res, err := SendSync(context.Background(), msg1) if err != nil { log.Printf("send tag sync message error:%s\n", err) } else {