Circuit breaker pattern for backend protection.
Prevents cascade failures by automatically stopping traffic to backends that are experiencing high error rates, allowing them time to recover.
State Machine:
Transitions:
Circuit breaker pattern for backend protection. Prevents cascade failures by automatically stopping traffic to backends that are experiencing high error rates, allowing them time to recover. State Machine: - CLOSED (normal): Traffic flows, errors are counted - OPEN (blocking): No traffic sent, waiting for timeout - HALF-OPEN (testing): Limited traffic to test recovery Transitions: - CLOSED -> OPEN: When error rate exceeds threshold - OPEN -> HALF-OPEN: After open-duration-ms timeout - HALF-OPEN -> CLOSED: After N consecutive successes - HALF-OPEN -> OPEN: On any failure
(circuit-half-open? target-id)Check if a circuit is currently half-open (testing).
Check if a circuit is currently half-open (testing).
(circuit-open? target-id)Check if a circuit is currently open (blocking traffic).
Check if a circuit is currently open (blocking traffic).
(force-close! target-id)Manually force a circuit to CLOSED state.
Manually force a circuit to CLOSED state.
(force-open! target-id)Manually force a circuit to OPEN state.
Manually force a circuit to OPEN state.
(get-all-circuits)Get all circuit breaker states.
Get all circuit breaker states.
(get-circuit target-id)Get circuit breaker state for a target.
Get circuit breaker state for a target.
(get-circuit-states-for-proxy proxy-name)Get circuit states for all targets in a proxy. Returns a map of target-id -> state keyword.
Get circuit states for all targets in a proxy. Returns a map of target-id -> state keyword.
(get-status)Get formatted status for all circuits.
Get formatted status for all circuits.
(init! update-weights-fn
&
{:keys [check-interval-ms] :or {check-interval-ms 1000}})Initialize the circuit breaker system with update function. update-weights-fn: Function (proxy-name) -> nil that triggers weight recalculation
Initialize the circuit breaker system with update function. update-weights-fn: Function (proxy-name) -> nil that triggers weight recalculation
(parse-target-id id)Parse a target ID string into {:ip :port}. Returns IP as u32 and port as int.
Parse a target ID string into {:ip :port}.
Returns IP as u32 and port as int.(print-status)Print formatted status for all circuits.
Print formatted status for all circuits.
(register-proxy! proxy-name target-group config)Register all targets in a proxy for circuit breaker tracking. target-group should be a TargetGroup record. config should be a CircuitBreakerConfig record.
Register all targets in a proxy for circuit breaker tracking. target-group should be a TargetGroup record. config should be a CircuitBreakerConfig record.
(register-target! proxy-name target-id config)Register a target with circuit breaker tracking. Called when initializing a proxy with circuit breaker enabled.
Register a target with circuit breaker tracking. Called when initializing a proxy with circuit breaker enabled.
(reset-circuit! target-id)Reset a circuit to initial CLOSED state with zero counts.
Reset a circuit to initial CLOSED state with zero counts.
(running?)Check if the circuit breaker system is running.
Check if the circuit breaker system is running.
(shutdown!)Shutdown the circuit breaker system.
Shutdown the circuit breaker system.
(start!)(start! {:keys [check-interval-ms] :or {check-interval-ms 1000}})Start the circuit breaker system. Must be called after health module is started.
Start the circuit breaker system. Must be called after health module is started.
(stop!)Stop the circuit breaker system.
Stop the circuit breaker system.
(subscribe! callback)Subscribe to circuit breaker events. Returns unsubscribe function.
Subscribe to circuit breaker events. Returns unsubscribe function.
(target-id ip port)Create a target ID string from IP and port. IP can be a string or u32 value.
Create a target ID string from IP and port. IP can be a string or u32 value.
(unregister-proxy! proxy-name)Unregister all targets for a proxy from circuit breaker tracking.
Unregister all targets for a proxy from circuit breaker tracking.
(unregister-target! target-id)Unregister a target from circuit breaker tracking.
Unregister a target from circuit breaker tracking.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |