NATSGo是NATS的Go客户端。
安装:
# Go clietgo get github.com/ats-io/ats# Servers# gatsdgo get github.com/ats-io/gatsd# ats-server (Ruby)gem istall ats基础编码使用
c, _ := ats.Coect(ats.DefaultURL)c, _ := ats.NewEcodedCo(c, ats.JSON_ENCODER)defer c.Close()// Simple Publisherc.Publish("foo", "Hello World")// Simple Asyc Subscriberc.Subscribe("foo", fuc(s strig) { fmt.Pritf("Received a message: %s\", s)})// EcodedCo ca Publish ay raw Go type usig the registered Ecodertype perso struct { Name strig Address strig Age it}// Go type Subscriberc.Subscribe("hello", fuc(p *perso) { fmt.Pritf("Received a perso: %+v\", p)})me := &perso{Name: "derek", Age: 22, Address: "585 Howard Street, Sa Fracisco, CA"}// Go type Publisherc.Publish("hello", me)// Usubscribigsub, err := c.Subscribe("foo", il)...sub.Usubscribe()// Requestsvar respose strigerr := c.Request("help", "help me", &respose, 10*time.Millisecod)// Replyigc.Subscribe("help", fuc(subj, reply strig, msg strig) { c.Publish(reply, "I ca help!")})// Close coectioc.Close();









评论