trooba-hystrix-handler
Trooba handler that provides Hystrix functionality to trooba based service pipelines. For more details on this topic, please read these blog posts Part 1 and Part 2.
Install
npm install trooba-hystrix-handler -S
Usage
The component collects services metrics and publishes it to process event stream under the topic 'trooba:hystrix:data'.
Pipeline configuration
const Trooba = require('trooba');
const pipe = Trooba
.use(require('trooba-hystrix-handler'), {
timeout: 2000,
circuitBreakerErrorThresholdPercentage: 50,
circuitBreakerForceClosed: false,
circuitBreakerForceOpened: false,
circuitBreakerRequestVolumeThreshold: 20,
circuitBreakerSleepWindowInMilliseconds: 5000,
requestVolumeRejectionThreshold: 0,
statisticalWindowNumberOfBuckets: 10,
statisticalWindowLength: 10000,
percentileWindowNumberOfBuckets: 6,
percentileWindowLength: 60000
})
.use(require('trooba-http-transport'), {
hostname: 'localhost',
port: 8000
})
.build({
fallback: (err, request) => {
console.log(request);
return Promise.resolve('fallback');
}
});
pipe.create({
command: 'my-service-command',
})
.request({
foo: 'bar'
}, (err, response) => console.log(err, response));
Viewing metrics using Hystrix dashboard
In case an application and hystrix-dashboard are packaged together, one can expose hystrix.stream as one of the http commands.
const express = require('express');
const app = express();
const dashboard = require('hystrix-dashboard');
app.use(dashboard({
topic: 'trooba:hystrix:data'
}));
app.listen(8000);