我正在嘗試將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()
}
)
}
}
]