client_test.go 857 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package main
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "jygit.jydev.jianyu360.cn/data_processing/common_utils/mongodb"
  6. "testing"
  7. "time"
  8. )
  9. func Test_NatsClient(t *testing.T) {
  10. mgo := mongodb.MongodbSim{
  11. MongodbAddr: "192.168.3.166:27082",
  12. DbName: "qfw",
  13. Size: 1,
  14. }
  15. mgo.InitPool()
  16. tmp, _ := mgo.FindById("bidding", "65578e020687916fae514d34", nil)
  17. msg := &MsgInfo{
  18. Id: "1", //消息唯一id
  19. CurrSetp: "test", //当前步骤
  20. Data: *tmp, //数据内容
  21. }
  22. msgByte, _ := json.Marshal(msg)
  23. resp, err := Jnats.PubReqZip(Subscribe, msgByte, 10*time.Second)
  24. if err != nil {
  25. fmt.Println("发布回执异常:", err)
  26. return
  27. }
  28. respMsg := &MsgInfo{}
  29. if json.Unmarshal(resp.Data, &respMsg) == nil {
  30. fmt.Println(respMsg.CurrSetp)
  31. fmt.Println(respMsg.Data["detail"])
  32. } else {
  33. fmt.Println("解析数据失败")
  34. }
  35. }