Serviced

Microservice dependency readiness probe
Small utility to probe for backing-service availability using http calls and promises. This will likely evolve to be more compatible but, for now, it uses features available in Node 6+. Feel free to send pull requests or open issues to make it compatible with earlier versions.
Motivation
When working with microservices, we often find we need to be prepared for variable times in backing service availability. Most times these are available and ready before we even probe them but some times they are not like in the case of a service needing to apply some configuration specific to a consuming service, etc. Serviced provides a way to probe multiple services with varying probe and retry configurations wrapped in a promise so you can, for example, not start an API server until all its backing services are available and ready.
Usage
npm i serviced
Test that a single service returns status code 200.
const Serviced = require('serviced');
new Serviced('http://exmample.com').then(() => {
});
Test that multiple services return status code 200.
new Serviced('http://svc-a.com', 'http://svc-b.com').then(() => {
});
Test the response body from a service request with a test function.
new Serviced({
url: 'http://svc-a.com',
test(body) {
return body.foo === true;
},
}).then(() => {
});
Test the response body from multiple service requests with test functions.
new Serviced({
url: 'http://svc-a.com',
test(body) {
return body.foo === true;
},
}, {
url: 'http://svc-b.com',
test(body) {
return body.bar === true;
},
}).then(() => {
});
Different options for multiple services.
new Serviced('http://svc-a.com', {
url: 'http://svc-b.com',
test(body) {
return body.bar === true;
},
}).then(() => {
});
Pass additional options to underlying request and retry modules.
The optional .request
and .retry
objects are passed through to the request and retry module instances respectively so you can control those as you deem necessary. It's a straight passthrough so please read their docs to find out what options are available for each.
new Serviced({
url: 'http://svc-a.com',
request: {
auth: {
user: 'username',
pass: 'password',
}
},
retry: {
retries: 2,
maxTimeout: 2000,
},
test(body) {
return body.foo === true;
},
}).then(() => {
});
Contributing
- Fork the repo.
npm i
npm start
to work on the library. This runs the tests continuously watching for changes but without test output (debug output instead).- Make your changes
npm t
to run the tests with no debug output (tap output instead).npm run cov
to run coverage report.npm run linter
to run eslint.- Submit a PR.
Change log
- 2.0.0 Breaking changes from 1.x. I switched to
retry
over backoff
primarily because of how it handles errors but also for simplicity.