2016-03-07 101 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() 
       } 
      ) 
     } 
    } 
] 
相关问题