Package

org.squbs.streams

circuitbreaker

Permalink

package circuitbreaker

Visibility
  1. Public
  2. All

Type Members

  1. class CircuitBreakerBidi[In, Out, Context] extends GraphStage[BidiShape[(In, Context), (In, Context), (Try[Out], Context), (Try[Out], Context)]]

    Permalink

    A bidi GraphStage that is joined with a Flow to add Circuit Breaker functionality.

    A bidi GraphStage that is joined with a Flow to add Circuit Breaker functionality. When the joined Flow is having trouble responding in time or is responding with failures, then based on the provided settings, it short circuits the Flow: Instead of pushing an element to the joined Flow, it directly pushes down a Failure or a fallback response to downstream, given that there is downstream demand.

    CircuitBreakerSettings.circuitBreakerState that keeps circuit breaker state. The user can select a CircuitBreakerState implementation that is right for the use case. Please note, in many scenarios, a CircuitBreakerState might need to be shared across materializations or even different streams. In such scenarios, make sure to select a CircuitBreakerState implementation that can work across materializations concurrently.

    A CircuitBreakerSettings.fallback function provides an alternative response when circuit is OPEN.

    The joined Flow pushes down a Try. By default, any Failure is considered a problem and causes the circuit breaker failure count to be incremented. However, CircuitBreakerSettings.failureDecider can be used to decide on if an element passed by the joined Flow is actually considered a failure. For instance, if Circuit Breaker is joined with an Akka HTTP flow, a Success Http Response with status code 500 internal server error should be considered a failure.

    Emits when an element is available from the joined Flow or a short circuited element is available

    Backpressures when the downstream backpressures

    Completes when upstream completes

    Cancels when downstream cancels

    Please note, if the upstream does not control the throughput, then the throughput of the stream might temporarily increase once the circuit is OPEN: The downstream demand will be addressed with short circuit/fallback messages, which might (or might not) take less time than it takes the joined Flow to process an element. To eliminate this problem, a throttle can be applied specifically for circuit breaker related messages.

                           +------+
          (In, Context) ~> |      | ~> (In, Context)
                           | bidi |
    (Try[Out], Context) <~ |      | <~ (Try[Out], Context)
                           +------+
    In

    the type of the elements pulled from the upstream along with the Context and pushed down to joined flow

    Out

    the type that's contained in a Try and pushed downstream along with the Context

    Context

    the type of the context that is carried around along with the elements. The context may be of any type that can be used to uniquely identify each element

  2. case class CircuitBreakerEvent(eventType: EventType, payload: Any) extends Product with Serializable

    Permalink
  3. class CircuitBreakerEventBusImpl extends EventBus with SubchannelClassification

    Permalink

    Publishes the payload of the CircuitBreakerEvent when the event type of the CircuitBreakerEvent matches with the one used during subscription.

  4. class CircuitBreakerEventClassification extends Subclassification[EventType]

    Permalink
  5. case class CircuitBreakerOpenException(msg: String = ...) extends Exception with Product with Serializable

    Permalink

    Exception thrown when Circuit Breaker is open.

    Exception thrown when Circuit Breaker is open.

    msg

    Defaults to "Circuit Breaker is open; calls are failing fast"

  6. case class CircuitBreakerSettings[In, Out, Context] extends Product with Serializable

    Permalink

    A container to hold circuit breaker settings.

    A container to hold circuit breaker settings.

    Circuit Breaker functionality requires each element to be uniquely identified, so it requires a Context, of any type defined by the application, to be carried along with the flow's input and output as a Tuple2 (Scala) or Pair (Java). The requirement is that either the Context itself or a mapping from Context should be able to uniquely identify an element. Here is the ways how a unique id can be retrieved:

    uniqueIdMapper
    In

    the type of the elements pulled from the upstream along with the Context and pushed down to joined flow

    Out

    the type that's contained in a Try and pushed downstream along with the Context

    Context

    the type of the context that is carried around along with the elements. The context may be of any type that can be used to uniquely identify each element

  7. trait CircuitBreakerState extends AnyRef

    Permalink

    Holds the state of the circuit breaker.

    Holds the state of the circuit breaker. Transitions through three states:

    Closed: elements/requests/calls run through the main logic until the maxFailures count is reached. If maxFailures is reached, it transitions to Open state.

    Open: Short circuits. A scala.util.Failure or a fallback response is returned. After resetTimeout, it transitions to HalfOpen state.

    HalfOpen: the first element/request/call will be allowed through the main logic, if it succeeds the circuit breaker will reset to Closed state. If it fails, the circuit breaker will re-open to Open state. All elements/requests/calls beyond the first that execute while the first is running will fail-fast with scala.util.Failure or a fallback response.

    An ActorRef can be subscribed to receive certain events, e.g., TransitionEvents to receive all state transition events or specific state transition event like Open.

    It collects metrics for success, failure and short-circuit counts. Also, exposes the state as a gauge.

  8. trait CircuitBreakerStateMXBean extends AnyRef

    Permalink
    Annotations
    @MXBean()
  9. case class CircuitBreakerStateMXBeanImpl(name: String, implementationClass: String, maxFailures: Int, callTimeout: FiniteDuration, resetTimeout: FiniteDuration, maxResetTimeout: FiniteDuration, exponentialBackoffFactor: Double) extends CircuitBreakerStateMXBean with Product with Serializable

    Permalink
  10. sealed trait EventType extends AnyRef

    Permalink
  11. sealed trait State extends TransitionEvent

    Permalink
  12. sealed trait TransitionEvent extends EventType

    Permalink

Value Members

  1. object CircuitBreakerBidi

    Permalink
  2. object CircuitBreakerBidiFlow

    Permalink
  3. object CircuitBreakerSettings extends Serializable

    Permalink
  4. object Closed extends State

    Permalink
  5. object HalfOpen extends State

    Permalink
  6. object Open extends State

    Permalink
  7. object TransitionEvents extends TransitionEvent

    Permalink
  8. package impl

    Permalink
  9. package japi

    Permalink

Ungrouped