feathers-opossum
feathers-opossum is a circuit breaker for Feathers services. It implements the opossum module.
npm install feathers-opossum --save
API
service(Service, serviceOptions, opossumOptions)
Example:
const service = require('service');
const opossumService = require('feathers-opossum');
const options = {
opossum: {
timeout: 3000,
errorThresholdPercentage: 50,
resetTimeout: 30000
},
fallback: () => {
return 'Sorry, out of service right now';
},
events: {
fallback: result => reportFallbackEvent(result),
}
methods: ['find', 'get']
};
const circuitedService = opossumService(service, {id:'_id', paginate: {max:10 }, options);
app.use('/may-fail', circuitedService);
Options:
Service
(required) - The main serviceopossum.timeout
(optional, default: 3000) - If our function takes longer than trigger a failureopossum.errorThresholdPercentage
(optional, default: 50) - When this ratio on requests fail, trip the circuitopossum.resetTimeout
(optional, default: 30000) - After this try again.fallback
- A fallback function that will be executed in the event of failure.events
- Opossum event listener.
Options per Service Method:
const options = {
find: {
opossum: {
timeout: 5000,
errorThresholdPercentage: 50,
resetTimeout: 30000
}
fallback: () => {
return 'Sorry, out of service right now';
},
events: {
fallback: result => reportFallbackEvent(result),
}
},
get: {
opossum: {
timeout: 1000,
errorThresholdPercentage: 50,
resetTimeout: 30000
}
fallback: () => {
return 'Sorry, out of service right now';
},
events: {
fallback: result => reportFallbackEvent(result),
}
}
};
Changelog
1.0.0
- implement opossum events
- add event test
0.1.0
...
License
Copyright (c) 2020
Licensed under the MIT license.