circuitbreaker

package
v1.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 16, 2024 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 2 more Imports: 3 Imported by: 1

README

Circuit Breaker

Circuit Breaker filters out nodes that have higher error ratio by collecting response of each request.

Usages

Use client.WithCircuitBreakerName("xxx") to specify a circuit breaker.

opts := []client.Option{
	client.WithCircuitBreakerName("xxxx"),
}

proxy := pb.NewGreeterProxy()
req := &pb.HelloRequest{
	Msg: "trpc-go-client",
}
proxy.SayHello(ctx, req, opts...)

Circuit Breaker Interface

// CircuitBreaker defines whether a node is available and reports the result of RPC on the node.
type CircuitBreaker interface {
	Available(node *registry.Node) bool
	Report(node *registry.Node, cost time.Duration, err error) error
}

The default implementation is NOOP.

Documentation

Overview

Package circuitbreaker is a pluggable circuit breaker module.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(name string, s CircuitBreaker)

Register registers a named circuit breaker.

func SetDefaultCircuitBreaker

func SetDefaultCircuitBreaker(cb CircuitBreaker)

SetDefaultCircuitBreaker sets the default circuit breaker.

Types

type CircuitBreaker

type CircuitBreaker interface {
	Available(node *registry.Node) bool
	Report(node *registry.Node, cost time.Duration, err error) error
}

CircuitBreaker is the interface that defines the circuit breaker which determines whether a node is available and report the result of an RPC on the node.

var DefaultCircuitBreaker CircuitBreaker = &NoopCircuitBreaker{}

DefaultCircuitBreaker is the default circuit breaker.

func Get

func Get(name string) CircuitBreaker

Get gets a named circuit breaker.

type NoopCircuitBreaker

type NoopCircuitBreaker struct{}

NoopCircuitBreaker is a noop circuit breaker.

func (*NoopCircuitBreaker) Available

func (*NoopCircuitBreaker) Available(*registry.Node) bool

Available always returns true.

func (*NoopCircuitBreaker) Report

Report does nothing.

type Options

type Options struct{}

Options defines the call options.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL