首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Spring Hystrix涡轮机无法从同一主机上的服务中获取信息

Spring Hystrix涡轮机无法从同一主机上的服务中获取信息
EN

Stack Overflow用户
提问于 2015-11-26 15:48:11
回答 3查看 1.9K关注 0票数 1

我跟随Spring指南来配置涡轮机。在两个微服务中启用Hystrix之后,我已经验证了/hystrix.stream端点是否生成正确的输出。

现在,在hystrix仪表板项目中,我已经将透平配置为获得所有服务的聚合结果。然而,我得到的只是一连串的:

代码语言:javascript
复制
: ping
data: {"reportingHostsLast10Seconds":0,"name":"meta","type":"meta","timestamp":1448552456486}

这是我的配置:

HystrixDashboard +汽轮机应用:

代码语言:javascript
复制
@EnableHystrixDashboard
@EnableTurbine
@SpringBootApplication
public class HystrixDashboardApplication {

    public static void main(String[] args) {
        SpringApplication.run(HystrixDashboardApplication.class, args);
    }
}

HystrixDashboard +涡轮application.yml:

代码语言:javascript
复制
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的指示,我用这种方式配置了涡轮机:

代码语言:javascript
复制
turbine:
  appConfig: random-story-microservice,storyteller-api
  instanceUrlSuffix: /hystrix.stream
  clusterNameExpression: new String("default")

它不再出现异常,在日志中我看到涡轮机找到了两个候选主机/微服务:

代码语言:javascript
复制
[        Timer-0] c.n.t.discovery.InstanceObservable       : Retrieved hosts from InstanceDiscovery: 2

然而,他们中只有一人最终被登记。在InstanceObservable.run()中,只有一个主机被添加,因为它们具有相同的哈希代码,所以当它们添加到newState.hostsUp时被认为是相同的。com.netflix.turbine.discovery.Instance哈希码是根据主机名(两种情况下都是“myhost”)和集群(“默认”)计算的:

代码语言:javascript
复制
// set the current state
            for(Instance host: newList) {
                if(host.isUp()) {
                    newState.hostsUp.add(host);
                } else {
                    newState.hostsDown.add(host);
                }
            }

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

EN

回答 3

Stack Overflow用户

发布于 2015-11-26 16:01:13

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

票数 0
EN

Stack Overflow用户

发布于 2015-11-26 16:20:54

事实上,我认为你误解了医生:

代码语言:javascript
复制
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

就你而言:

代码语言:javascript
复制
turbine:
  aggregator:
    clusterConfig: MY_CLUSTER
  appConfig: random-story-microservice,storyteller-api

因此,它将返回“随机故事-微服务,故事讲述-api”大写。

票数 0
EN

Stack Overflow用户

发布于 2015-11-26 16:36:36

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

代码语言:javascript
复制
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‘

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33942534

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档