package main import ( "fmt" "git.hpds.cc/Component/network/log" "git.hpds.cc/pavement/hpds_node" "math/rand" "os" "time" ) func main() { // connect to HPDS-MQ. ap := hpds_node.NewAccessPoint( "hpds-ap", hpds_node.WithMqAddr("localhost:27188"), hpds_node.WithCredential("token:z1"), ) err := ap.Connect() if err != nil { log.Printf("[AccessPoint] Emit the data to HPDS-MQ failure with err: %v", err) return } defer ap.Close() ap.SetDataTag(0x33) // generate mock data and send it to HPDS-MQ. err = generateAndSendData(ap) if err != nil { log.Printf("[AccessPoint] >>>> ERR >>>> %v", err) os.Exit(1) } select {} } func generateAndSendData(stream hpds_node.AccessPoint) error { for { rnd := rand.New(rand.NewSource(time.Now().UnixNano())) data := []byte(fmt.Sprintf("%d", rnd.Uint32())) // send data via QUIC stream. _, err := stream.Write(data) if err != nil { log.Printf("[AccessPoint] Emit %v to HPDS-MQ failure with err: %v", data, err) time.Sleep(500 * time.Millisecond) continue } log.Printf("[AccessPoint] Emit %s to HPDS-MQ", data) time.Sleep(1000 * time.Millisecond) } }