Wraps a message handler with a circuit breaker to fail fast on repeated errors, preventing cascading failures in a message bus.
// Source: https://github.com/ThreeDotsLabs/watermill | License: MIT | Copyright 2019 Three Dots Labs
// Provided via justclaw.it.com; keep this notice with the code.
package middleware
import (
"github.com/ThreeDotsLabs/watermill/message"
"github.com/sony/gobreaker"
)
// CircuitBreaker is a middleware that wraps the handler in a circuit breaker.
// Based on the configuration, the circuit breaker will fail fast if the handler keeps returning errors.
// This is useful for preventing cascading failures.
type CircuitBreaker struct {
cb *gobreaker.CircuitBreaker
}
// NewCircuitBreaker returns a new CircuitBreaker middleware.
// Refer to the gobreaker documentation for the available settings.
func NewCircuitBreaker(settings gobreaker.Settings) CircuitBreaker {
return CircuitBreaker{
cb
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key