【问题标题】:Unable to connect to Command Metric Stream in Spring Cloud + Hystrix + Turbine - MIME type ("text/plain") that is not "text/event-stream"无法连接到 Spring Cloud + Hystrix + Turbine 中的 Command Metric Stream - MIME 类型(“text/plain”)不是“text/event-stream”
【发布时间】:2019-02-07 18:13:45
【问题描述】:

我已经通过链接:Unable to connect to Command Metric Stream for Hystrix Dashboard with Spring Cloud 并尝试了几个选项,但还没有成功。 我正在开发 Spring Cloud Code + Hystrix + Turbine

你能告诉我是什么问题吗?我正在使用 Spring Boot v2.0.4.RELEASE

HystrixDashboardApplication.java

@EnableTurbine
@EnableHystrixDashboard
@SpringBootApplication
public class HystrixDashboardApplication {

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

pom.xml

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.4.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <spring-cloud.version>Finchley.SR1</spring-cloud.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-turbine</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

tollrate-billboard 应用程序有以下代码 TollrateBillboardApplication.java

@EnableCircuitBreaker
@SpringBootApplication
@EnableEurekaClient
public class TollrateBillboardApplication {

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

DashboardController.java

@Controller
public class DashboardController {

    @LoadBalanced
    @Bean
    public RestTemplate restTemplate(RestTemplateBuilder builder) {
        return builder.build();
    }

    @Autowired
    private RestTemplate restTemplate;

    @HystrixCommand(fallbackMethod = "getTollRateBackup")
    @RequestMapping("/dashboard")
    public String GetTollRate(@RequestParam int stationId, Model m) {

        TollRate tr = restTemplate.getForObject("http://pluralsight-toll-service/tollrate/" + stationId, TollRate.class);
        System.out.println("stationId: " + stationId);
        m.addAttribute("rate", tr.getCurrentRate());
        return "dashboard";
    }

    public String getTollRateBackup(@RequestParam int stationId, Model m) { 
        System.out.println("Fallback operation called");
        m.addAttribute("rate", "1.00");
        return "dashboard";
    }
}

bootstrap.properties

spring.application.name=pluralsight-tollrate-billboard

application.properties

server.port=8082
# eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/
eureka.client.register-with-eureka=true
eureka.client.fetch-registry=true

#http://cloud.spring.io/spring-cloud-static/Finchley.RELEASE/single/spring-cloud.html#_environment_changes
management.endpoints.web.exposure.include=hystrix.stream

CURL 命令结果:

curl "http://localhost:8085/clusters"

输出

[
    {
        "name": "PLURALSIGHT-FASTPASS-CONSOLE",
        "link": "http://localhost:8085/turbine.stream?cluster=PLURALSIGHT-FASTPASS-CONSOLE"
    },
    {
        "name": "PLURALSIGHT-TOLLRATE-BILLBOARD",
        "link": "http://localhost:8085/turbine.stream?cluster=PLURALSIGHT-TOLLRATE-BILLBOARD"
    }
]

EDIT-1::,我正在使用“hystrix-turbine”

@EnableTurbineStream
@SpringBootApplication
public class HystrixTurbineApplication {

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

现在,我遇到以下错误:

2018-09-03 22:23:45.808  WARN 2820 --- [nio-8085-exec-5] ashboardConfiguration$ProxyStreamServlet : Failed opening connection to http://localhost:8085/turbine.stream?cluster=PLURALSIGHT-FASTPASS-CONSOLE : 404 : HTTP/1.1 404 
2018-09-03 22:23:45.808  WARN 2820 --- [nio-8085-exec-2] ashboardConfiguration$ProxyStreamServlet : Failed opening connection to http://localhost:8085/turbine.stream?cluster=PLURALSIGHT-FASTPASS-CONSOLE : 404 : HTTP/1.1 404 

【问题讨论】:

  • 我使用 Zuul 来保护我的 API,在此会话配置中我阻止了 Zuul 的 CORS 选项,此配置阻止了 Hystrix dashbord,因为浏览器无法显示指标。

标签: spring spring-boot spring-cloud hystrix turbine


【解决方案1】:

@Sayali 我尝试在我自己的系统中重新创建错误并且我设法让它工作,这里有一些你可以做的检查:

1) 您的第一个屏幕截图中的 URL 不正确。您在 Hystrix Dashboard 中的流 URL 应该是:

http://localhost:8085/turbine.stream?cluster=PLURALSIGHT-TOLLRATE-BILLBOARD

url 应该指向仪表板应用程序的端口,在您的主类中具有@EnableTurbine 注释。

2) 检查您是否收到以下回复:

http://localhost:8082/actuator/hystrix.stream

(请使用您的浏览器) (这应该来自您使用 @EnableCircuitBreaker 启用 hystrix 的应用程序)

如果您收到 ping,那么至少可以访问您的 hystrix 流。 如果不, 检查您是否有:org.springframework.boot:spring-boot-starter-actuator 在依赖项和
确保您在主类中具有@EnableCircuitBreaker 的应用程序的 application.properties 文件中设置了以下属性:

management.endpoints.web.exposure.include= hystrix.stream, info, health

再次检查网址。

3) 在转向涡轮流之前,请先让涡轮部分工作,所以现在,您可以进行以下更改:

@EnableTurbine // instead of @EnableTurbineStream
@SpringBootApplication
public class HystrixTurbineApplication {

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

另外,使用 TurbineStream:

您可能希望让您的 Hystrix 命令将指标推送到 Turbine。 Spring Cloud 通过消息传递实现了这一点。要在客户端上执行此操作,请添加 对 spring-cloud-netflix-hystrix-stream 和 您选择的 spring-cloud-starter-stream-*。

参考:http://cloud.spring.io/spring-cloud-static/Finchley.SR1/single/spring-cloud.html#_turbine_stream

我希望这会有所帮助。请发表评论以帮助我了解这是否适合您。

【讨论】:

猜你喜欢
  • 2016-03-20
  • 2018-09-22
  • 2016-08-30
  • 1970-01-01
  • 1970-01-01
  • 2020-05-01
  • 1970-01-01
  • 2019-06-15
  • 2012-06-02
相关资源
最近更新 更多