State

Example:state

state is another meta data. If you set state=inactive metadata for some services, only clients can not access those services even if those services are alive.

You can use it to disable a service temporally and don't shutdown the server.

You can manage rpcx service via rpcx-ui).

```go server.go

func main() { flag.Parse()

  1. go createServer1(*addr1, "")
  2. go createServer2(*addr2, "state=inactive")
  3. select {}

}

func createServer1(addr, meta string) { s := server.NewServer() s.RegisterName("Arith", new(example.Arith), meta) s.Serve("tcp", addr)}

func createServer2(addr, meta string) { s := server.NewServer() s.RegisterName("Arith", new(Arith), meta) s.Serve("tcp", addr)}

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

By smallnest updated 2018-12-04 11:47:26