circuit-breaker-request
A wrapper around request-retry-stream, that itself wraps request.
cuircuit-breaker-request Implements a circuit breaker using the levee module.
For more information about circuit breaking read the akka docs on the circuit breaker pattern
npm install circuit-breaker-request
Usage - Basic with callbacks
var cbr = ; cbr;
Usage - Simple stream in express middleware with pump (piping streams)
var cbr = ;var pump = ; { ;}
Usage - Options and defaults
// NOTE: all options are OPTIONAL.// Defaults, displayed in parenthesis, will be used for anything you don't specify var cbr = ; cbr; cbr; // ... more HTTP requests with cbr //cbr request with special options, can also be used when defaults are not used.cbr;
Grouping
Circuit breaking is done per group of urls. By default the urls are grouped by protocol and host. Here is an example of this grouping:
Group 1
https://debitoor.com/test
https://debitorr.com
https://debitoor.com/test?a=true
Group 2
https://developers.debitoor.com/api
https://developers.debitorr.com
https://developers.debitoor.com/api?b=false
Group 3
https://google.com/api
https://google.com
https://plus.google.com/api?b=false
Each group has it's own circuit breaker. So if errors start happening in group 1, it will not close down group 2 or 3.
You can create a different grouping by passing a function in the getGroupId
parameter. The default getGroupId function
is:
var urlParser = ; { var u = urlParser; return uprotocol + uhost;}
So anything with a URL on the same protocol and host will be in the same circuit-breaker. This means if there are 5 consecutive errors returned for URLs with the same protocol and host, the circuit-breaker will pause requests to that protocol and host for a while, but anything on a different host and/or protocol will still be let through.