hpds_node/example/multi-mq/sf/main.go

36 lines
586 B
Go
Raw Normal View History

2022-10-12 11:55:36 +08:00
package main
import (
"git.hpds.cc/pavement/hpds_node"
"log"
"os"
)
func main() {
sf := hpds_node.NewStreamFunction(
"echo-sf",
hpds_node.WithMqAddr("localhost:27187"),
hpds_node.WithObserveDataTags(0x33),
hpds_node.WithCredential("token:z2"),
)
defer sf.Close()
// set handler
sf.SetHandler(handler)
// start
err := sf.Connect()
if err != nil {
log.Fatalf("[sf] connect err=%v", err)
os.Exit(1)
}
select {}
}
func handler(data []byte) (byte, []byte) {
val := string(data)
log.Printf(">> [streamFunction] got tag=0x33, data=%s", val)
return 0x0, nil
}