1

我已按照Spring Cloud Netflix 的指南配置 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);
                }
            }

当同一台主机提供两种不同的微服务时,我们该怎么办?在这种情况下,仅注册了第一个实例。

4

3 回答 3

0

我想我有一个答案,但首先,可以肯定的是,你为什么期待“默认”?

于 2015-11-26T16:01:13.920 回答
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”。

于 2015-11-26T16:20:54.660 回答
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'

于 2015-11-26T16:36:36.290 回答