UsingCircuitBreaker

uk.gov.hmrc.circuitbreaker.UsingCircuitBreaker

Trait to be mixed in to services or connectors that wish to protect their outgoing calls from wasting unsuccessful invocations in periods where the service seems to be unavailable.

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Value members

Abstract methods

protected def breakOnException(t: Throwable): Boolean

Predicate that defines the exceptions that should be treated as a failure. In most cases only 5xx status responses should be treated as a server-side issue.

Predicate that defines the exceptions that should be treated as a failure. In most cases only 5xx status responses should be treated as a server-side issue.

Attributes

The configuration for the circuit breaker:

The configuration for the circuit breaker:

  • serviceName - the name of the service
  • numberOfCallsToTriggerStateChange - the number of failed calls that need to accumulate within unstablePeriodDuration for the service to get disabled, as well as the number of successful calls that are needed to get a service back from the disabled state to normal.
  • unavailablePeriodDuration - the time in seconds that a service should be disabled in case it accumulated more than the configured maximum number of failures
  • unstablePeriodDuration - the time in seconds that failure counts are accumulated. When the period ends without reaching the limit, the counter switches back to 0.

Attributes

Concrete methods

protected def isServiceAvailable: Boolean

Indicates whether the service is available. Returns false if the service is disabled due to accumulating too many failures in the configured time frame. Note that due to the asynchronous nature of the circuit breaker, you can still get an UnhealthyServiceException after this method returned true as the state might change any time.

Indicates whether the service is available. Returns false if the service is disabled due to accumulating too many failures in the configured time frame. Note that due to the asynchronous nature of the circuit breaker, you can still get an UnhealthyServiceException after this method returned true as the state might change any time.

Attributes

protected def withCircuitBreaker[T](f: => Future[T])(implicit hc: HeaderCarrier): Future[T]

Protects the specified future from being evaluated in case the service is disabled due to accumulating too many failures in the configured time frame. If the service is disabled, the future will fail with a UnhealthyServiceException, if it is enabled, it will succeed or fail with whatever result the original future produces.

Protects the specified future from being evaluated in case the service is disabled due to accumulating too many failures in the configured time frame. If the service is disabled, the future will fail with a UnhealthyServiceException, if it is enabled, it will succeed or fail with whatever result the original future produces.

Attributes

Concrete fields

lazy protected val circuitBreaker: CircuitBreaker

The CircuitBreaker instance used by this trait.

The CircuitBreaker instance used by this trait.

Attributes