This sample uses a circuit breaker to control calls to the target API.
If a call to the API spends more than 30 seconds to answer, Tree Gateway will assume that the call failed and a timeout error will be returned to the caller.
If during the same time window (in this case a period of 2 minutes), this API fail more than 5 times, the circuit will open.
When the circuit is open, Tree Gateway will fast fail any call to the API, with a 'Service Unavailable' response.
When the circuit is open, Tree Gateway will wait for 1 minute to check again if the API is working (Entering in the 'Half Open' state). In this state, Tree Gateway will allow that only one request try to hit the target API. Depending on the response of that request, it will close the circuit or open it again.
This sample is similar to the previous example, but it declare middlewares to be called when the circuit breaker changes its state to open or close.