Liking cljdoc? Tell your friends :D

lb.circuit-breaker

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 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
raw docstring

circuit-breaker-stateclj

source

circuit-half-open?clj

(circuit-half-open? target-id)

Check if a circuit is currently half-open (testing).

Check if a circuit is currently half-open (testing).
sourceraw docstring

circuit-open?clj

(circuit-open? target-id)

Check if a circuit is currently open (blocking traffic).

Check if a circuit is currently open (blocking traffic).
sourceraw docstring

force-close!clj

(force-close! target-id)

Manually force a circuit to CLOSED state.

Manually force a circuit to CLOSED state.
sourceraw docstring

force-open!clj

(force-open! target-id)

Manually force a circuit to OPEN state.

Manually force a circuit to OPEN state.
sourceraw docstring

get-all-circuitsclj

(get-all-circuits)

Get all circuit breaker states.

Get all circuit breaker states.
sourceraw docstring

get-circuitclj

(get-circuit target-id)

Get circuit breaker state for a target.

Get circuit breaker state for a target.
sourceraw docstring

get-circuit-states-for-proxyclj

(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.
sourceraw docstring

get-statusclj

(get-status)

Get formatted status for all circuits.

Get formatted status for all circuits.
sourceraw docstring

init!clj

(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
sourceraw docstring

parse-target-idclj

(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.
sourceraw docstring

(print-status)

Print formatted status for all circuits.

Print formatted status for all circuits.
sourceraw docstring

register-proxy!clj

(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.
sourceraw docstring

register-target!clj

(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.
sourceraw docstring

reset-circuit!clj

(reset-circuit! target-id)

Reset a circuit to initial CLOSED state with zero counts.

Reset a circuit to initial CLOSED state with zero counts.
sourceraw docstring

running?clj

(running?)

Check if the circuit breaker system is running.

Check if the circuit breaker system is running.
sourceraw docstring

shutdown!clj

(shutdown!)

Shutdown the circuit breaker system.

Shutdown the circuit breaker system.
sourceraw docstring

start!clj

(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.
sourceraw docstring

stop!clj

(stop!)

Stop the circuit breaker system.

Stop the circuit breaker system.
sourceraw docstring

subscribe!clj

(subscribe! callback)

Subscribe to circuit breaker events. Returns unsubscribe function.

Subscribe to circuit breaker events. Returns unsubscribe function.
sourceraw docstring

target-idclj

(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.
sourceraw docstring

unregister-proxy!clj

(unregister-proxy! proxy-name)

Unregister all targets for a proxy from circuit breaker tracking.

Unregister all targets for a proxy from circuit breaker tracking.
sourceraw docstring

unregister-target!clj

(unregister-target! target-id)

Unregister a target from circuit breaker tracking.

Unregister a target from circuit breaker tracking.
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close