Browse Source

mq发送示例

master v1.1.0
loshiqi 2 years ago
parent
commit
2289559d7a
2 changed files with 10 additions and 1 deletions
  1. +9
    -0
      conn.go
  2. +1
    -1
      conn_test.go

+ 9
- 0
conn.go View File

@ -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)
}

+ 1
- 1
conn_test.go View File

@ -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 {


Loading…
Cancel
Save