【发布时间】:2016-02-29 18:42:11
【问题描述】:
我已关注Spring Cloud Netflix's guide 配置 Turbine。在两个微服务中启用 Hystrix 后,我已验证 /hystrix.stream 端点生成正确的输出。
现在,在 hystrix 仪表板项目中,我已配置 Turbine 以获取所有服务的聚合结果。然而,我得到的只是一系列的:
: ping
data: {"reportingHostsLast10Seconds":0,"name":"meta","type":"meta","timestamp":1448552456486}
这是我的配置:
HystrixDashboard + Turbine 应用程序:
@EnableHystrixDashboard
@EnableTurbine
@SpringBootApplication
public class HystrixDashboardApplication {
public static void main(String[] args) {
SpringApplication.run(HystrixDashboardApplication.class, args);
}
}
HystrixDashboard + Turbine application.yml:
spring:
application:
name: hystrix-dashboard
server:
port: 10000
turbine:
appConfig: random-story-microservice,storyteller-api
instanceUrlSuffix: /hystrix.stream
logging:
level:
com.netflix.turbine: 'TRACE'
更新
按照 kreel 的指示,我以这种方式配置了 Turbine:
turbine:
appConfig: random-story-microservice,storyteller-api
instanceUrlSuffix: /hystrix.stream
clusterNameExpression: new String("default")
它不再因异常而失败,在日志中我看到 Turbine 找到了两个候选主机/微服务:
[ Timer-0] c.n.t.discovery.InstanceObservable : Retrieved hosts from InstanceDiscovery: 2
但是最终只有其中一个被注册。在InstanceObservable.run() 中,仅添加了一个主机,因为它们具有相同的哈希码,因此在添加到 newState.hostsUp 时它们被认为是相同的。 com.netflix.turbine.discovery.Instance 哈希码是根据主机名(在这两种情况下都是“myhost”)和集群(“默认”)计算得出的:
// set the current state
for(Instance host: newList) {
if(host.isUp()) {
newState.hostsUp.add(host);
} else {
newState.hostsDown.add(host);
}
}
当同一台主机提供两种不同的微服务时,我们该怎么办?在这种情况下只注册了第一个实例。
【问题讨论】:
-
有一个增强功能可以让涡轮机做到这一点。 github.com/spring-cloud/spring-cloud-netflix/pull/661
-
太棒了!感谢您的信息!
标签: spring spring-cloud netflix hystrix turbine