trpc.group/trpc-go/trpc-go@v1.0.3/naming/circuitbreaker/README.md (about) 1 # Circuit Breaker 2 3 Circuit Breaker filters out nodes that have higher error ratio by collecting response of each request. 4 5 ## Usages 6 Use `client.WithCircuitBreakerName("xxx")` to specify a circuit breaker. 7 ```go 8 opts := []client.Option{ 9 client.WithCircuitBreakerName("xxxx"), 10 } 11 12 proxy := pb.NewGreeterProxy() 13 req := &pb.HelloRequest{ 14 Msg: "trpc-go-client", 15 } 16 proxy.SayHello(ctx, req, opts...) 17 ``` 18 19 ## Circuit Breaker Interface 20 ```go 21 // CircuitBreaker defines whether a node is available and reports the result of RPC on the node. 22 type CircuitBreaker interface { 23 Available(node *registry.Node) bool 24 Report(node *registry.Node, cost time.Duration, err error) error 25 } 26 ``` 27 The default implementation is NOOP.