rocketmq方法
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
669 B

1 year ago
  1. package rocketmq
  2. import (
  3. "encoding/json"
  4. "github.com/apache/rocketmq-client-go/v2/primitive"
  5. "log"
  6. "testing"
  7. // "tgo/helper"
  8. "context"
  9. )
  10. func Test_Send(t *testing.T) {
  11. MqConnect("ProductService", []string{"127.0.0.1:9876"})
  12. log.Println("2", MqPool)
  13. mq_data := map[string]interface{}{
  14. "a": "a",
  15. }
  16. topic := "product"
  17. tag := "collect_product"
  18. msg_str, _ := json.Marshal(mq_data)
  19. msg1 := primitive.NewMessage(topic, msg_str)
  20. msg1.WithTag(tag)
  21. res, err := SendSync(context.Background(), msg1)
  22. if err != nil {
  23. log.Printf("send tag sync message error:%s\n", err)
  24. } else {
  25. log.Printf("send tag sync message success. result=%s\n", res.String())
  26. }
  27. }