Building a Service for Use with an Open Circuit
When a circuit for a service is open, the service does not execute. Instead, circuit breaker responds to requests for the service by throwing the same exception that caused the last failure event or by executing an alternate service. The alternate service, known as the open circuit service, is a user-defined service that performs an action that makes sense for your application. In some applications, you might want the open circuit service to return a cached value or an alternate result to the calling service. You can also code the open circuit service to perform a different action based on whether it is the first invocation of the open circuit service since the circuit opened or if it is a subsequent invocation.
Whether a circuit breaker throws an exception or executes an alternate service depends on the value of the Circuit open action property. If you specify Invoke service as the circuit open action, you must identify the service to invoke in the Circuit open service property.When circuit breaker invokes the open circuit service, circuit breaker places parameters and values in the service pipeline for use by the open circuit service.
The following identifies and describes the parameters that circuit breaker places in the pipeline for an open circuit service.
Parameter Name | Description |
$circuitBreakerService | String. Fully qualified name of the service with the open circuit. |
$circuitBreakerEvent | String. Indicates whether this is the first time circuit breaker called the open circuit service since the circuit opened or if this is a subsequent invocation. The $circuitBreakerEvent parameter has one of the following values: CIRCUIT_OPENED if this is the first execution of this open circuit service since the circuit opened. CIRCUIT_OPEN if this is not the first execution of the open circuit service since the circuit opened. |
Note:
The open circuit service has access to the parameters in the above table as well as any parameters that existed in the pipeline at the time of the execution request for the service with a configured circuit breaker.
Keep the following information in mind when building an open circuit service for use with a circuit breaker:
If the open circuit service interacts with a remote resource, such as a database or web server, make the interaction asynchronous to prevent a service execution from blocking other threads or delaying the execution of the original calling service.
An open circuit service can be used with more than one service with a configured circuit breaker.
Circuit breaker does not use a thread from the circuit breaker thread pool to execute the open circuit service. Circuit breaker uses the same thread that executed the calling service to execute the open circuit service.
If an exception occurs while executing this service, it does not impact the circuit breaker failure count for the originally requested service.
Software AG recommends that the open circuit service is not configured to use a circuit breaker.
Software AG recommends that the open circuit service is not the same as the service with the configured circuit breaker. That is, do not create a circular situation where a service with an open circuit calls itself.