package testUnit import ( "goUpload/dbHelper" "log" "testing" "time" ) func TestMqttRecv(t *testing.T) { mqHelpers := dbHelper.MqttHelper{ Host: "10.8.30.160", Port: 30883, ClientId: "lzwjdq500101-lk", UserName: "lzwjdq500101", Password: "lzwjdq500101p", } mqHelpers.Initial() topic := "udasUpload/#" //荔枝乌江大桥 //topic = "t/500103" //龙河桥 time.Sleep(time.Second * 1) mqHelpers.Subscribe(topic, myHandle) log.Println("=====开始订阅=====") for { time.Sleep(1 * time.Minute) } } func myHandle(Topic string, Msg string) { log.Printf("mqtt-recv:[%s]:%s", Topic, Msg) }