我正在尝试将hystrixJS配置为我的一个nodejs应用程序。我想包装我的应用程序正在制作的外部依赖关系。 https://www.npmjs.com/package/hystrixjs如何在节点应用程序中配置Hystrixjs?
我阅读自述,但我还是不能让我怎么能换我的依赖调用这个锥,以及如何配置仪表板这一点。如果有人已经尝试过,请给我一些指导。
谢谢。
我正在尝试将hystrixJS配置为我的一个nodejs应用程序。我想包装我的应用程序正在制作的外部依赖关系。 https://www.npmjs.com/package/hystrixjs如何在节点应用程序中配置Hystrixjs?
我阅读自述,但我还是不能让我怎么能换我的依赖调用这个锥,以及如何配置仪表板这一点。如果有人已经尝试过,请给我一些指导。
谢谢。
您可以在回购的example app中找到样品。但也可以随时提交一个关于bitbucket的问题,我会尝试提供更多的例子。
一般而言,您可以包装任何返回承诺的函数,但它不一定是http请求,尽管它是最常见的用例。
仪表板不是hystrix本身的一部分。它的工作方式是,您可以在本地运行仪表板,请参阅here的说明,然后将端点添加到您的应用程序以公开指标。该示例应用展示了如何做到这一点:
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);
您可以将网址,然后粘贴到仪表板,它会显示你的命令。
让我知道这是否有助于
在情况下,你使用高致病性禽流感服务器,您可以创建SSE数据:
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()
}
)
}
}
]