无法连接到 Spring Cloud + Hystrix + Turbine 中的 Command Metric Stream - MIME 类型(“text/plain")不是“text/event-stream" [英] Unable to connect to Command Metric Stream in Spring Cloud + Hystrix + Turbine - MIME type ("text/plain") that is not "text/event-stream"
问题描述
我已经通过链接:
HystrixDashboardApplication.java
@EnableTurbine@EnableHystrixDashboard@SpringBootApplication公共类 HystrixDashboardApplication {公共静态无效主(字符串 [] args){SpringApplication.run(HystrixDashboardApplication.class, args);}}
pom.xml
<groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.0.4.RELEASE</version><relativePath/><!-- 从存储库中查找父级 --></父母><属性><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></属性><依赖项><依赖><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId></依赖><依赖><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId></依赖><依赖><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-turbine</artifactId></依赖><依赖><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><范围>测试</范围></依赖></依赖项><依赖管理><依赖项><依赖><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-dependencies</artifactId><version>${spring-cloud.version}</version><type>pom</type><范围>导入</范围></依赖></依赖项></dependencyManagement>
tollrate-billboard
应用有以下代码TollrateBillboardApplication.java
@EnableCircuitBreaker@SpringBootApplication@EnableEurekaClient公共类 TollrateBillboardApplication {公共静态无效主(字符串 [] args){SpringApplication.run(TollrateBillboardApplication.class, args);}}
DashboardController.java
@Controller公共类仪表板控制器{@负载均衡@豆公共 RestTemplate restTemplate(RestTemplateBuilder builder) {返回 builder.build();}@自动连线私人 RestTemplate restTemplate;@HystrixCommand(fallbackMethod = "getTollRateBackup")@RequestMapping("/仪表板")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());返回仪表板";}public String getTollRateBackup(@RequestParam int stationId, Model m) {System.out.println("调用回退操作");m.addAttribute("rate", "1.00");返回仪表板";}}
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=trueeureka.client.fetch-registry=true#http://cloud.spring.io/spring-cloud-static/Finchley.RELEASE/single/spring-cloud.html#_environment_changesmanagement.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": "多视角收费广告牌","link": "http://localhost:8085/turbine.stream?cluster=PLURALSIGHT-TOLLRATE-BILLBOARD"}]EDIT-1::,我使用的是hystrix-turbine"
@EnableTurbineStream@SpringBootApplication公共类 HystrixTurbineApplication {公共静态无效主(字符串 [] args){SpringApplication.run(HystrixTurbineApplication.class, args);}}
现在,我遇到以下错误:
2018-09-03 22:23:45.808 WARN 2820 --- [nio-8085-exec-5] ashboardConfiguration$ProxyStreamServlet :无法打开到 http://localhost:8085/turbine.stream 的连接?cluster=PLURALSIGHT-FASTPASS-CONSOLE:404:HTTP/1.1 4042018-09-03 22:23:45.808 WARN 2820 --- [nio-8085-exec-2] ashboardConfiguration$ProxyStreamServlet:无法打开与 http://localhost:8085/turbine.stream?cluster=PLURALSIGHT-FASTPASS-的连接控制台:404:HTTP/1.1 404
@Sayali 我尝试在自己的系统中重现该错误,但我设法让它正常工作,您可以进行以下检查:
1) 第一个屏幕截图中的 URL 不正确.Hystrix 仪表板中的流 URL 应为:
<块引用><块引用>http://localhost:8085/turbine.stream?cluster=PLURALSIGHT-收费广告牌
该 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,信息,健康
再次检查网址.
3) 在转向涡轮流之前,请先让涡轮部分工作,所以现在,您可以进行以下更改:
@EnableTurbine//代替@EnableTurbineStream@SpringBootApplication公共类 HystrixTurbineApplication {公共静态无效主(字符串 [] 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
我希望这会有所帮助.请发表评论以帮助我知道这是否适合您.
I already went through the link: Unable to connect to Command Metric Stream for Hystrix Dashboard with Spring Cloud and tried few options, but nothing worked out for yet. I am developing Spring Cloud Code + Hystrix + Turbine.
Could you please let me know what is the issue ? I am using 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
application has the following code
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 Command Result:
curl "http://localhost:8085/clusters"
output
[
{
"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::, I am using "hystrix-turbine"
@EnableTurbineStream
@SpringBootApplication
public class HystrixTurbineApplication {
public static void main(String[] args) {
SpringApplication.run(HystrixTurbineApplication.class, args);
}
}
Now, I'm getting below error:
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
@Sayali I tried recreating the error in my own system and I managed to get it working, here are a few checks you can make:
1) The URL in your 1st screenshot is incorrect. Your stream URL in the Hystrix Dashboard should be:
http://localhost:8085/turbine.stream?cluster=PLURALSIGHT-TOLLRATE-BILLBOARD
The url should be pointing to the port of the dashboard application that has @EnableTurbine
annotation in your main class.
2) Check if you are getting a response for:
(use your browser for this)
(this should be coming from the application you have enabled hystrix on using @EnableCircuitBreaker
)
If you're getting pings, then atleast your hystrix stream is accessible.
If not,
Check if you have: org.springframework.boot:spring-boot-starter-actuator
in dependencies and
make sure you have the below property set in application.properties file of the application that has @EnableCircuitBreaker
in the main class:
management.endpoints.web.exposure.include= hystrix.stream, info, health
Check the URL again.
3) Please get the turbine section working before moving to turbine streams, so as of now, you can make the following change:
@EnableTurbine // instead of @EnableTurbineStream
@SpringBootApplication
public class HystrixTurbineApplication {
public static void main(String[] args) {
SpringApplication.run(HystrixTurbineApplication.class, args);
}
}
Also, to use TurbineStream:
you might want to have your Hystrix commands push metrics to Turbine. Spring Cloud enables that with messaging. To do so on the client, add a dependency to spring-cloud-netflix-hystrix-stream and the spring-cloud-starter-stream-* of your choice.
refer: http://cloud.spring.io/spring-cloud-static/Finchley.SR1/single/spring-cloud.html#_turbine_stream
I hope this helps. Please comment to help me know if this worked for you.
这篇关于无法连接到 Spring Cloud + Hystrix + Turbine 中的 Command Metric Stream - MIME 类型(“text/plain")不是“text/event-stream"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!