Group
When you register a service, maybe you have noticed there is third parameter and we set it as empty string at most examples. Actually you add some meta for those services.
You can manage rpcx service via rpcx-ui).
is a meta data. If you set group
metadata for some services, only clients in this group
can access those services.
func main() { flag.Parse()
}
func createServer1(addr, meta string) { s := server.NewServer() s.RegisterName("Arith", new(example.Arith), meta) s.Serve("tcp", addr)}
Discovery can find the group. Client can use `option.Group` to set group.
If you have not set `option.Group`, clients can access any services whether services set group or not.
```go client.go
option.Group = "test"
defer xclient.Close()
args := &example.Args{
A: 10,
B: 20,
}
reply := &example.Reply{}
err := xclient.Call(context.Background(), "Mul", args, reply)
if err != nil {
log.Fatalf("failed to call: %v", err)
}
log.Printf("%d * %d = %d", args.A, args.B, reply.C)
}
By smallnest updated 2018-03-27 11:12:10
原文: