2016-03-07 98 views

回答

7

您可以在回購的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); 

您可以將網址,然後粘貼到儀表板,它會顯示你的命令。

讓我知道這是否有助於

0

在情況下,你使用高致病性禽流感服務器,您可以創建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() 
       } 
      ) 
     } 
    } 
] 
相關問題