func sub(i int, wg *sync.WaitGroup) { topic := fmt.Sprintf("loadtest/%v", i) var cc *mqtt.ClientConn if cc = connect(); cc == nil { return } ack := cc.Subscribe([]proto.TopicQos{ {topic, proto.QosAtLeastOnce}, }) if *dump { fmt.Printf("suback: %#v\n", ack) } go func() { ok := false count := 0 for range cc.Incoming { count++ if count == *messages { cc.Disconnect() ok = true } } if !ok { bad <- i } wg.Done() }() }
func pub(i int) { topic := fmt.Sprintf("loadtest/%v", i) var cc *mqtt.ClientConn if cc = connect(); cc == nil { return } for i := 0; i < *messages; i++ { cc.Publish(&proto.Publish{ Header: proto.Header{QosLevel: proto.QosAtMostOnce}, TopicName: topic, Payload: proto.BytesPayload([]byte("loadtest payload")), }) } cc.Disconnect() }