Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure Hystrixjs in a node app?

I am trying to configure hystrixJS into one of my nodejs app. I want to wrap up couple of external dependencies which my app is making. https://www.npmjs.com/package/hystrixjs

I read the readme but I still couldn't get how can i wrap my dependency call with this hystrix and how to configure a dashboard for this. If anyone already tried this before please give me some directions.

Thanks.

like image 222
munna_1 Avatar asked Mar 07 '16 05:03

munna_1


1 Answers

You can find a sample in the example app in the repo. But also feel free to submit a question on bitbucket and I will try to provide more examples.

In general you can wrap any function that returns a promise, it does not have to be a http request, although it is the most common use case.

The dashboard is not part of hystrix itself. The way it works, you can run a dashboard locally, see for instructions here and then add an endpoint to your application to expose the metrics. The example app shows how to do it:

function hystrixStreamResponse(request, response) {
    response.append('Content-Type', 'text/event-stream;charset=UTF-8');
    response.append('Cache-Control', 'no-cache, no-store, max-age=0, must-revalidate');
    response.append('Pragma', 'no-cache');
    return hystrixStream.toObservable().subscribe(
        function onNext(sseData) {
            response.write('data: ' + sseData + '\n\n');
        },
        function onError(error) {console.log(error);
        },
        function onComplete() {
            return response.end();
        }
    );
};

app.get('/api/hystrix.stream', hystrixStreamResponse);

You can then paste the url into the dashboard and it will display your commands.

Let me know if it helps

like image 129
Igor Sechyn Avatar answered Oct 16 '22 18:10

Igor Sechyn