无法连接到Spring Cloud + Hystrix + Turbine中的Command Metric Stream - 不是“text / event-stream”的MIME类型(“text / plain”)

问题描述 投票:0回答:1

我已经通过链接:Unable to connect to Command Metric Stream for Hystrix Dashboard with Spring Cloud并尝试了一些选项,但还没有任何结果。我正在开发Spring Cloud Code + Hystrix + Turbine。

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

enter image description here

enter image description here

H YST日系dashboard application.Java

@EnableTurbine
@EnableHystrixDashboard
@SpringBootApplication
public class HystrixDashboardApplication {

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

pom.hml

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

dashboard controller.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 
spring spring-boot spring-cloud hystrix turbine
1个回答
1
投票

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

1)第1张屏幕截图中的网址不正确。 Hystrix仪表板中的流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

再次检查URL。

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

我希望这有帮助。请评论以帮助我知道这是否适合您。

© www.soinside.com 2019 - 2024. All rights reserved.