gonsq_test.go 698 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package gonsq
  2. import (
  3. "encoding/json"
  4. "log"
  5. "testing"
  6. "time"
  7. )
  8. func Test_nsq(t *testing.T) {
  9. p, e2 := NewProducer("192.168.3.207:4150", "tt", false)
  10. go func() {
  11. log.Println(p, e2)
  12. time.Sleep(3 * time.Second)
  13. p.Publish([]byte("aaaa1111"))
  14. }()
  15. c, e1 := NewConsumer(&Cconfig{
  16. IsJsonEncode: false,
  17. Addr: "192.168.3.207:4150",
  18. Topic: "tt",
  19. Channel: "cc",
  20. Concurrent: 1,
  21. })
  22. log.Println(c, e1)
  23. go func() {
  24. for {
  25. select {
  26. case obj := <-c.Ch:
  27. log.Println("ccc", obj)
  28. }
  29. }
  30. }()
  31. select {}
  32. }
  33. func Test_arr(t *testing.T) {
  34. v, _ := json.Marshal([]byte("aaaa1111"))
  35. var n []byte
  36. json.Unmarshal(v, &n)
  37. log.Println(v, n, []byte{0xFF})
  38. }