1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- package gonsq
- import (
- "encoding/json"
- "log"
- "testing"
- "time"
- )
- func Test_nsq(t *testing.T) {
- c, e1 := NewConsumer(&Cconfig{
- IsJsonEncode: false,
- Addr: "192.168.3.207:4150",
- Topic: "jyalert",
- Channel: "jyalert",
- Concurrent: 1,
- })
- log.Println(c, e1)
- go func() {
- for {
- select {
- case obj := <-c.Ch:
- log.Println("ccc", obj)
- }
- }
- }()
- p, e2 := NewProducer("192.168.3.207:4150", "jyalert", false)
- go func() {
- log.Println(p, e2)
- time.Sleep(3 * time.Second)
- p.Publish([]byte("aaaa1111"))
- }()
- time.Sleep(15 * time.Second)
- }
- func Test_arr(t *testing.T) {
- v, _ := json.Marshal([]byte("aaaa1111"))
- var n []byte
- json.Unmarshal(v, &n)
- log.Println(v, n, []byte{0xFF})
- p, _ := NewProducer("192.168.3.207:4150", "jyalert", false)
- m := &Msg{"invoice_alert", "你有新的告警消息处理", "首页console错误请查看", map[string]interface{}{"ip": "127.0.0.1", "service": "sword"}}
- bs, _ := json.Marshal(m)
- p.Publish(bs)
- var b Msg
- json.Unmarshal(bs, &b)
- log.Println(string(bs), b)
- time.Sleep(1 * time.Second)
- }
- func Test_consumer(t *testing.T) {
- c, e1 := NewConsumer(&Cconfig{
- IsJsonEncode: false,
- Addr: "192.168.3.207:4150",
- Topic: "jyalert",
- Channel: "jyalert",
- Concurrent: 1,
- })
- log.Println(c, e1)
- select {
- case obj := <-c.Ch:
- log.Println("ccc", obj)
- case <-time.After(4 * time.Second):
- break
- }
- }
|