Fork

Example:broadcast

Broadcast is a method of XClient and you can use it to send a request to all servers that contains this service.

If all servers return response whithout an error, Broadcast will return OK for this XClient. If any of servers returns an error, Broadcast returns an error of those errors.

  1. func main() {
  2. ……
  3. xclient := client.NewXClient("Arith", client.Failover, client.RoundRobin, d, client.DefaultOption)
  4. defer xclient.Close()
  5. args := &example.Args{
  6. A: 10,
  7. B: 20,
  8. }
  9. for {
  10. reply := &example.Reply{}
  11. err := xclient.Broadcast(context.Background(), "Mul", args, reply)
  12. if err != nil {
  13. log.Fatalf("failed to call: %v", err)
  14. }
  15. log.Printf("%d * %d = %d", args.A, args.B, reply.C)
  16. time.Sleep(1e9)
  17. }
  18. }

By smallnest updated 2018-03-27 11:12:10

原文:

http://doc.rpcx.site/part3/broadcast.html