circuitbreaker

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrHystrixCircuitOpen = errors.New("hystrix: circuit open")

ErrHystrixCircuitOpen is returned when the Hystrix circuit is open and the request is rejected without calling the wrapped endpoint.

View Source
var ErrHystrixMaxConcurrency = errors.New("hystrix: max concurrency reached")

ErrHystrixMaxConcurrency is returned when the number of in-flight requests exceeds MaxConcurrentRequests.

View Source
var ErrHystrixTimeout = errors.New("hystrix: timeout")

ErrHystrixTimeout is returned when the wrapped endpoint exceeds the configured timeout.

Functions

func Gobreaker

Gobreaker returns an endpoint.Middleware that implements the circuit breaker pattern using the sony/gobreaker package. Only errors returned by the wrapped endpoint count against the circuit breaker's error count.

See http://godoc.org/github.com/sony/gobreaker for more information.

func HandyBreaker

func HandyBreaker(cb breaker.Breaker) endpoint.Middleware

HandyBreaker returns an endpoint.Middleware that implements the circuit breaker pattern using the streadway/handy/breaker package. Only errors returned by the wrapped endpoint count against the circuit breaker's error count.

See http://godoc.org/github.com/streadway/handy/breaker for more information.

func Hystrix

func Hystrix(commandName string) endpoint.Middleware

Hystrix returns an endpoint.Middleware that implements the Hystrix circuit breaker pattern. It is a drop-in replacement for the afex/hystrix-go package with no external dependency.

Configure the command before use:

circuitbreaker.HystrixConfigureCommand("my-endpoint", circuitbreaker.HystrixConfig{
    Timeout:                time.Second,
    MaxConcurrentRequests:  100,
    RequestVolumeThreshold: 20,
    SleepWindow:            5 * time.Second,
    ErrorPercentThreshold:  50,
})
ep = circuitbreaker.Hystrix("my-endpoint")(ep)

func HystrixConfigureCommand added in v1.2.0

func HystrixConfigureCommand(name string, cfg HystrixConfig)

HystrixConfigureCommand registers or updates the configuration for a named command. Call this before using Hystrix() with the same name.

Types

type HystrixConfig added in v1.2.0

type HystrixConfig struct {
	// Timeout is the maximum duration for a single request (default: 1s).
	Timeout time.Duration

	// MaxConcurrentRequests is the maximum number of in-flight requests
	// allowed at any time (default: 10).
	MaxConcurrentRequests int

	// RequestVolumeThreshold is the minimum number of requests in the
	// rolling window before the error rate is evaluated (default: 20).
	RequestVolumeThreshold int

	// SleepWindow is how long to wait after the circuit opens before
	// allowing a single probe request (default: 5s).
	SleepWindow time.Duration

	// ErrorPercentThreshold is the error rate (0–100) above which the
	// circuit opens (default: 50).
	ErrorPercentThreshold int
}

HystrixConfig holds the configuration for a single Hystrix command. All fields have sensible defaults; zero values are replaced by defaults when the command is first used.

Jump to

Keyboard shortcuts

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