如何在节点应用程序中configurationHystrixjs?

我正在尝试将hystrixJSconfiguration为我的一个nodejs应用程序。 我想包装我的应用程序正在做的外部依赖项的几个。 https://www.npmjs.com/package/hystrixjs

我读了自述文件,但我仍然无法得到如何包装我的依赖关系调用这个hystrix和如何configuration仪表板为此。 如果有人已经尝试过,请给我一些指导。

谢谢。

您可以在回购示例应用程序中find示例。 但也可以随意提交一个关于bitbucket的问题,我会尝试提供更多的例子。

一般来说,你可以包装任何返回一个promise的函数,它不一定是一个http请求,虽然它是最常见的用例。

仪表板不是hystrix本身的一部分。 它的工作方式是,您可以在本地运行仪表板, 在此处查看指示信息 ,然后向您的应用程序添加端点以显示指标。 示例应用程序显示如何执行此操作:

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); 

然后,您可以将该url粘贴到仪表板中,并显示您的命令。

让我知道,如果有帮助

如果你使用hapi服务器,你可以创buildsse数据:

 use strict' const hystrixSSEStream = require('hystrixjs').hystrixSSEStream; module.exports = [ { method: 'GET', path: '/hystrix-sse-stream', handler: (request, reply) => { request.raw.res.writeHead(200, { 'content-type': 'text/event-stream; charset=utf-8', 'Pragma': 'no-cache', 'cache-control': 'no-cache, no-store, max-age=0, must-revalidate' }) hystrixSSEStream.toObservable().subscribe( function onNext(sseData) { request.raw.res.write('data: ' + sseData + '\n\n') }, function onError(error) { reply(error) }, function onComplete() { reply.continue() } ) } } ]