Spring Cloud Netflix Hystrix Turbine无法从同一主机上的服务获取信息

时间:2015-11-26 15:48:12

标签: spring spring-cloud netflix hystrix turbine

我已按照Spring Cloud Netflix's guide配置了Turbine。在两个微服务中启用Hystrix之后,我已经验证了/hystrix.stream端点生成了正确的输出。

现在,在hystrix仪表板项目中,我已配置Turbine以获取所有服务的汇总结果。然而,我得到的只是一系列:

: ping
data: {"reportingHostsLast10Seconds":0,"name":"meta","type":"meta","timestamp":1448552456486}

这是我的配置:

HystrixDashboard + Turbine Application:

@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);
                }
            }

当同一主机提供两种不同的微服务时,我们需要做什么?在这种情况下只注册了第一个实例。

3 个答案:

答案 0 :(得分:0)

我想我有一个答案,但首先,确定,为什么你期待"默认" ?

答案 1 :(得分:0)

事实上,我认为你误解了这个文档:

The configuration key turbine.appConfig is a list of eureka serviceIds that turbine will use to lookup instances. The turbine stream is then used in the Hystrix dashboard using a url that looks like: http://my.turbine.sever:8080/turbine.stream?cluster=<CLUSTERNAME>; (the cluster parameter can be omitted if the name is "default"). The cluster parameter must match an entry in turbine.aggregator.clusterConfig. Values returned from eureka are uppercase, thus we expect this example to work if there is an app registered with Eureka called "customers":

turbine:
  aggregator:
    clusterConfig: CUSTOMERS
  appConfig: customers

在你的情况下:

turbine:
  aggregator:
    clusterConfig: MY_CLUSTER
  appConfig: random-story-microservice,storyteller-api

所以它会以大写字母返回“random-story-microservice,storyteller-api”。

答案 2 :(得分:0)

所以,我认为你需要应用这个部分:

The clusterName can be customized by a SPEL expression in turbine.clusterNameExpression with root an instance of InstanceInfo. The default value is appName, which means that the Eureka serviceId ends up as the cluster key (i.e. the InstanceInfo for customers has an appName of "CUSTOMERS"). A different example would be turbine.clusterNameExpression=aSGName, which would get the cluster name from the AWS ASG name. Another example:

turbine:
  aggregator:
    clusterConfig: SYSTEM,USER
  appConfig: customers,stores,ui,admin
  clusterNameExpression: metadata['cluster']

In this case, the cluster name from 4 services is pulled from their metadata map, and is expected to have values that include "SYSTEM" and "USER".

To use the "default" cluster for all apps you need a string literal expression (with single quotes):

turbine:
  appConfig: customers,stores
  clusterNameExpression: 'default'

Spring Cloud provides a spring-cloud-starter-turbine that has all the dependencies you need to get a Turbine server running. Just create a Spring Boot application and annotate it with @EnableTurbine.

在您的配置中添加: clusterNameExpression:'default'