producer_test.go 601 B

12345678910111213141516171819202122232425
  1. package nats
  2. import (
  3. "git.aionnect.com/aionnect/go-common/utils/date"
  4. "git.aionnect.com/aionnect/go-common/utils/mq"
  5. "git.aionnect.com/aionnect/go-common/utils/mq/topic"
  6. "testing"
  7. )
  8. func TestProducer_SendJSON(t *testing.T) {
  9. producer := NewProducer()
  10. defer func(producer *Producer) {
  11. _ = producer.Close()
  12. }(producer)
  13. msg := &mq.TestMsg{Message: "你好, 世界!", Time: date.Now()}
  14. tpc := topic.TOP("test-subject")
  15. for i := 0; i < 5; i++ {
  16. result, err := producer.SendJSON(tpc, msg)
  17. if err != nil {
  18. t.Error("Failed to produce message: ", err)
  19. }
  20. t.Logf(result.(string))
  21. }
  22. }