tcptemplate/test/mq_test.go

34 lines
644 B
Go
Raw Normal View History

2020-04-07 07:55:33 +00:00
package test
import (
"go-tcpFramework-rudy/tools/mq"
2020-04-07 08:10:32 +00:00
"qiniupkg.com/x/log.v7"
2020-04-07 07:55:33 +00:00
"testing"
"time"
)
func Callback(key string,msg string) {
2020-04-07 08:10:32 +00:00
log.Print(key,msg)
2020-04-07 07:55:33 +00:00
}
func TestMq(t *testing.T) {
cli := mq.RedisMqClient{}
2020-04-07 08:10:32 +00:00
e := cli.Connect("49.235.25.67:16379",0,"")
if nil != e{
log.Print(e.Error())
t.Error(e)
}
2020-04-07 07:55:33 +00:00
cli.Subscribe("msg",Callback)
cli.Public("msg","shit")
2020-04-07 10:24:54 +00:00
cli.Public("msg","shit2")
cli.Public("msg","shit3")
2020-04-08 02:57:59 +00:00
mqcli := mq.MqttClient{}
e = mqcli.Connect("tcp://" + "49.235.25.67:1883",0,"122")
log.Print(e)
e = mqcli.Subscribe("/dev",Callback)
log.Print(e)
mqcli.Public("/dev","shit")
2020-04-07 07:55:33 +00:00
for true{
time.Sleep(100)
}
}