Tree Gateway - Circuit Breaker

Circuit Breaker

Circuit Breaker Example --- name: MyResilientAPI version: 1.0.0 path: circuit/ proxy: target: host: http://httpbin.org circuitBreaker: timeout: 30 seconds resetTimeout: 1 minute timeWindow: 2 minutes maxFailures: 5

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.

Circuit Breaker Events

Circuit Breaker Events --- name: MyResilientAPI version: 1.0.0 path: circuit/ proxy: target: host: http://httpbin.org circuitBreaker: timeout: 30 seconds resetTimeout: 1 minute timeWindow: 2 minutes maxFailures: 5 onOpen: name: myHandler onClose: name: myHandler "use strict"; module.exports = function (apiPath, event, apiId) { console.log('My API circuitbreaker for ' + apiId +' is now ' + event + '!); };

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.