Spring boot、eureka、hystrix、turtle:turtle 总是显示 0 个报告主机

Posted

技术标签:

【中文标题】Spring boot、eureka、hystrix、turtle:turtle 总是显示 0 个报告主机【英文标题】:Spring boot, eureka, hystrix, turbine: turbine always shows 0 reporting hosts 【发布时间】:2015-12-04 12:53:18 【问题描述】:

我有一个能够通过 Eureka 发现正在运行的服务的涡轮机实现:

2015-09-08 11:40:13.727  INFO 13112 --- [        Timer-0] o.s.c.n.turbine.EurekaInstanceDiscovery  : Fetching instance list for apps: [policy-service]
2015-09-08 11:40:13.727  INFO 13112 --- [        Timer-0] o.s.c.n.turbine.EurekaInstanceDiscovery  : Fetching instances for app: policy-service
2015-09-08 11:40:13.727  INFO 13112 --- [        Timer-0] o.s.c.n.turbine.EurekaInstanceDiscovery  : Received instance list for app: policy-service, size=1
2015-09-08 11:40:13.727  INFO 13112 --- [        Timer-0] c.n.t.discovery.InstanceObservable       : Retrieved hosts from InstanceDiscovery: 1
2015-09-08 11:40:13.728  INFO 13112 --- [        Timer-0] c.n.t.discovery.InstanceObservable       : Found hosts that have been previously terminated: 0
2015-09-08 11:40:13.728  INFO 13112 --- [        Timer-0] c.n.t.discovery.InstanceObservable       : Hosts up:1, hosts down: 0

Hystrix 正在客户端应用程序策略服务上运行。我可以查看它的流并在 hystrix 仪表板中看到它。

问题是当我查看涡轮流时,我得到了这个:

: ping
data: "reportingHostsLast10Seconds":0,"name":"meta","type":"meta","timestamp":1441734488823

当我使用 URI http://localhost:8095/turbine.stream?cluster=DEV 在 Hystrix 仪表板中查看它时,我只看到“正在加载...”

我已经尝试了this帖子中提到的所有方法,但无济于事。

这是我的涡轮机服务的 application.yml:

turbine:
  aggregator:
    clusterNameExpression: new String("default")
    clusterConfig: DEV
    #http://localhost:8095/turbine.stream?cluster=DEV
  appConfig: policy-service
  InstanceMonitor:
    eventStream:
      skipLineLogic:
        enabled: false

我在没有 clusterConfig 和 clusterNameExpression 的情况下试过这个。

这是我的 bootstrap.yml:

eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/
spring:
  application:
    name: turbine-service
server:
  port: 8095

这是我的来源:

package com.ml.turbine;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.turbine.EnableTurbine;

@SpringBootApplication
@EnableTurbine
@EnableEurekaClient
public class TurbineService 

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

当我在浏览器中点击涡轮流时,日志显示:

2015-09-08 14:03:19.967  INFO 12024 --- [nio-8095-exec-4] c.n.t.s.servlet.TurbineStreamServlet     : FilterCriteria: []
2015-09-08 14:03:19.967  INFO 12024 --- [nio-8095-exec-4] c.n.t.s.servlet.TurbineStreamServlet     : StatsType filters: []
2015-09-08 14:03:19.967  INFO 12024 --- [nio-8095-exec-4] c.n.t.s.TurbineStreamingConnection       : Relevance config: []
2015-09-08 14:03:19.967  INFO 12024 --- [nio-8095-exec-4] c.n.t.s.TurbineStreamingConnection       : Relevance metrics config: 
2015-09-08 14:03:19.967  INFO 12024 --- [nio-8095-exec-4] c.n.t.monitor.cluster.ClusterMonitor     : Registering event handler for cluster monitor: StreamingHandler_92386c8c-b263-4548-be07-10c1a2a3dc27
2015-09-08 14:03:19.967  INFO 12024 --- [nio-8095-exec-4] c.n.t.handler.TurbineDataDispatcher      : 

Just added and starting handler tuple: StreamingHandler_92386c8c-b263-4548-be07-10c1a2a3dc27
2015-09-08 14:03:19.968  INFO 12024 --- [nio-8095-exec-4] c.n.turbine.data.AggDataFromCluster      : Per handler dispacher started for: StreamingHandler_92386c8c-b263-4548-be07-10c1a2a3dc27
2015-09-08 14:03:19.973  INFO 12024 --- [nio-8095-exec-4] c.n.t.monitor.cluster.ClusterMonitor     : All event handlers for cluster monitor: [StreamingHandler_92386c8c-b263-4548-be07-10c1a2a3dc27, StreamingHandler_deaba37e-b712-49db-beba-ab9f60848118, StaticListener_For_Aggregator, StreamingHandler_42896dd8-5d90-43c2-89ad-f57151b94894]
2015-09-08 14:03:19.974  INFO 12024 --- [nio-8095-exec-4] c.n.t.monitor.cluster.ClusterMonitor     : Starting up the cluster monitor for DEV_agg

为什么当我的涡轮流连接到策略服务并且 hystrix 流正常工作时,我在涡轮流中什么也得不到?

【问题讨论】:

【参考方案1】:

原来是我的application.yml配置错误。

来自here:

clusterName 可以通过 Turbo.clusterNameExpression 中的 SPEL 表达式自定义,root 是 InstanceInfo 的实例。默认值为 appName,这意味着 Eureka serviceId 最终作为集群键(即客户的 InstanceInfo 的 appName 为“CUSTOMERS”)。

我的 application.yml 现在看起来像这样:

turbine:
  aggregator:
    clusterNameExpression: new String("default")
    clusterConfig: POLICY-SERVICE
    #http://localhost:8095/turbine.stream?cluster=POLICY-SERVICE
  appConfig: policy-service

【讨论】:

来自projects.spring.io/spring-cloud/docs/1.0.3/…: turbine.appConfig: policy-service 而你不需要turbine.aggregator.clusterNameExpression

以上是关于Spring boot、eureka、hystrix、turtle:turtle 总是显示 0 个报告主机的主要内容,如果未能解决你的问题,请参考以下文章

Spring Boot集成Eureka

没有 Spring-boot 的 Eureka 服务发现

spring boot eureka server

spring boot eureka client

spring boot 1.5.2中eureka客户端如何找到eureka server?

使用 Eureka 服务集成测试 Spring Boot 服务