trpc.group/trpc-go/trpc-go@v1.0.3/naming/loadbalance/README.md (about)

     1  # tRPC-Go Load Balance
     2  
     3  LoadBalancer is used for each request, not connection. It's decoupled from client, and the different load balance
     4  strategy maintains their own status. tRPC-Go provides round-robin and smooth weighted round-robin.
     5  
     6  ## Usages
     7  Use `client.WithBalancerName("xxx")` to specify a load balance algorithm.
     8  ```go
     9  opts := []client.Option{
    10      client.WithBalancerName("round_robin"),
    11  }
    12  
    13  proxy := pb.NewGreeterProxy()
    14  req := &pb.HelloRequest{
    15      Msg: "trpc-go-client",
    16  }
    17  proxy.SayHello(ctx, req, opts...)
    18  ```
    19  
    20  ## Load Balancer Interface
    21  ```go
    22  // LoadBalancer is the interface which returns a node from node list.
    23  type LoadBalancer interface {
    24  	Select(serviceName string, list []*registry.Node, opt ...Option) (node *registry.Node, err error)
    25  }
    26  ```
    27  The custom implementation should refer to the implementation inside that project.