无法连接到命令指标流.在 Hystrix 仪表板问题中 [英] Unable to connect to Command Metric Stream. in Hystrix Dashboard issue
问题描述
在发布这个问题之前,我浏览了许多链接,例如:
hystrix-dashboard::
HystrixDashboardApplication.java
@SpringBootApplication@EnableHystrixDashboard公共类 HystrixDashboardApplication {公共静态无效主(字符串 [] args){SpringApplication.run(HystrixDashboardApplication.class, args);}}
bootstrap.properties
management.endpoints.web.exposure.include=hystrix.streammanagement.endpoints.web.base-path=/eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka
pom.xml
<modelVersion>4.0.0</modelVersion><父母><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.2.2.RELEASE</version><relativePath/><!-- 从存储库中查找父级 --></父母><groupId>com.example</groupId><artifactId>spring-boot-jdbcBatchUpdate</artifactId><version>0.0.1-SNAPSHOT</version><name>hystrix-dashboard</name><description>Spring Boot 的演示项目</description><属性><java.version>1.8</java.version><spring-cloud.version>Hoxton.SR1</spring-cloud.version><maven-jar-plugin.version>3.1.1</maven-jar-plugin.version></属性><依赖项><依赖><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId></依赖><依赖><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><范围>测试</范围><排除事项><排除><groupId>org.junit.vintage</groupId><artifactId>junit-vintage-engine</artifactId></排除></排除项></依赖><依赖><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId></依赖></依赖项><依赖管理><依赖项><依赖><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-dependencies</artifactId><version>${spring-cloud.version}</version><type>pom</type><范围>导入</范围></依赖></依赖项></dependencyManagement><构建><插件><插件><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></插件></plugins></build></项目>
天气应用::
WeatherService.java
@Service公共类天气服务{@注入私人 RestTemplate restTemplate;@HystrixCommand(fallbackMethod="unknown")公共字符串 getWeather() {return restTemplate.getForEntity("http://weather-service/weather", String.class).getBody();}公共字符串未知(){System.out.println("~~~~~~~~~");返回未知";}}
WeatherAppApplication.java
@EnableDiscoveryClient@EnableCircuitBreaker@RestController@SpringBootApplication公共类 WeatherAppApplication {@注入私人 WeatherService 天气服务;公共静态无效主(字符串 [] args){SpringApplication.run(WeatherAppApplication.class, args);}@豆@负载均衡公共 RestTemplate restTemplate() {返回新的 RestTemplate();}@GetMapping(value = "/当前/天气")公共字符串 getWeather() {return "当前天气是 " + weatherService.getWeather();}}
application.properties
server.port=8000spring.application.name=天气应用eureka.client.service-url.defaultZone=http://localhost:8761/eureka
天气服务::
application.properties
server.port=9000spring.application.name=天气服务eureka.client.service-url.defaultZone=http://localhost:8761/eureka
WeatherServiceApplication.java
@RestController@EnableDiscoveryClient@SpringBootApplication公共类 WeatherServiceApplication {private String[] weather = new String[] {"sunny", "cloudy", "rainy", "windy"};公共静态无效主(字符串 [] args){SpringApplication.run(WeatherServiceApplication.class, args);}@GetMapping(value="/weather")公共字符串 getWeather() {int rand = ThreadLocalRandom.current().nextInt(0, 4);返回天气[rand];}}
在仪表板项目中将此添加到您的属性
hystrix:仪表板:代理流允许列表:*";
并且,在weather-app中添加这个
管理:端点:网络:曝光:包括:*"
然后,打开 http://localhost:8080/hystrix 并添加 http://localhost:8000/actuator/hystrix.stream
<块引用>https://github.com/adetiamarhadi/spring-cloud-hystrix-仪表板.githttps://github.com/adetiamarhadi/spring-cloud-hystrix-weather-app.git
Before posting this question, I went through numerous links like : Unable to connect to Command Metric Stream for Hystrix Dashboard with Spring Cloud and Unable to connect to Command Metric Stream in Spring Cloud + Hystrix + Turbine - MIME type ("text/plain") that is not "text/event-stream" and so on, but still things are not working for me.
I am using Spring Boot V2.2.2.RELEASE.
2020-01-14 22:52:23.805 INFO 8436 --- [io-8080-exec-10] ashboardConfiguration$ProxyStreamServlet :
Proxy opening connection to: http://localhost:8000/hystrix.stream
2020-01-14 22:52:23.806 INFO 8436 --- [nio-8080-exec-2] ashboardConfiguration$ProxyStreamServlet :
Proxy opening connection to: http://localhost:8000/hystrix.stream
2020-01-14 22:52:24.442 WARN 8436 --- [io-8080-exec-10] ashboardConfiguration$ProxyStreamServlet : Failed opening connection to http://localhost:8000/hystrix.stream : 404 : HTTP/1.1 404
2020-01-14 22:52:24.442 WARN 8436 --- [nio-8080-exec-2] ashboardConfiguration$ProxyStreamServlet : Failed opening connection to http://localhost:8000/hystrix.stream : 404 : HTTP/1.1 404
2020-01-14 22:52:37.391 INFO 8436 --- [nio-8080-exec-8] ashboardConfiguration$ProxyStreamServlet :
Proxy opening connection to: http://localhost:8080/hystrix.stream
2020-01-14 22:52:37.397 INFO 8436 --- [nio-8080-exec-9] ashboardConfiguration$ProxyStreamServlet :
Proxy opening connection to: http://localhost:8080/hystrix.stream
2020-01-14 22:52:37.488 WARN 8436 --- [nio-8080-exec-8] ashboardConfiguration$ProxyStreamServlet : Failed opening connection to http://localhost:8080/hystrix.stream : 404 : HTTP/1.1 404
2020-01-14 22:52:37.488 WARN 8436 --- [nio-8080-exec-9] ashboardConfiguration$ProxyStreamServlet : Failed opening connection to http://localhost:8080/hystrix.stream : 404 : HTTP/1.1 404
hystrix-dashboard::
HystrixDashboardApplication.java
@SpringBootApplication
@EnableHystrixDashboard
public class HystrixDashboardApplication {
public static void main(String[] args) {
SpringApplication.run(HystrixDashboardApplication.class, args);
}
}
bootstrap.properties
management.endpoints.web.exposure.include=hystrix.stream
management.endpoints.web.base-path=/
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>spring-boot-jdbcBatchUpdate</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>hystrix-dashboard</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Hoxton.SR1</spring-cloud.version>
<maven-jar-plugin.version>3.1.1</maven-jar-plugin.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</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>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
weather-app::
WeatherService.java
@Service
public class WeatherService {
@Inject
private RestTemplate restTemplate;
@HystrixCommand(fallbackMethod="unknown")
public String getWeather() {
return restTemplate.getForEntity("http://weather-service/weather", String.class).getBody();
}
public String unknown() {
System.out.println("~~~~~~~~~");
return "unknown";
}
}
WeatherAppApplication.java
@EnableDiscoveryClient
@EnableCircuitBreaker
@RestController
@SpringBootApplication
public class WeatherAppApplication {
@Inject
private WeatherService weatherService;
public static void main(String[] args) {
SpringApplication.run(WeatherAppApplication.class, args);
}
@Bean
@LoadBalanced
public RestTemplate restTemplate() {
return new RestTemplate();
}
@GetMapping(value = "/current/weather")
public String getWeather() {
return "The current weather is " + weatherService.getWeather();
}
}
application.properties
server.port=8000
spring.application.name=weather-app
eureka.client.service-url.defaultZone=http://localhost:8761/eureka
weather-service::
application.properties
server.port=9000
spring.application.name=weather-service
eureka.client.service-url.defaultZone=http://localhost:8761/eureka
WeatherServiceApplication.java
@RestController
@EnableDiscoveryClient
@SpringBootApplication
public class WeatherServiceApplication {
private String[] weather = new String[] {"sunny", "cloudy", "rainy", "windy"};
public static void main(String[] args) {
SpringApplication.run(WeatherServiceApplication.class, args);
}
@GetMapping(value="/weather")
public String getWeather() {
int rand = ThreadLocalRandom.current().nextInt(0, 4);
return weather[rand];
}
}
Source Code here: https://github.com/javaHelper/spring-cloud-cordinating-services/tree/master/Protecting-Systems-with-Circuit-Breakers
in dashboard project add this to your properties
hystrix:
dashboard:
proxy-stream-allow-list: "*"
and, in weather-app add this
management:
endpoints:
web:
exposure:
include: "*"
then, open http://localhost:8080/hystrix and add http://localhost:8000/actuator/hystrix.stream
https://github.com/adetiamarhadi/spring-cloud-hystrix-dashboard.git https://github.com/adetiamarhadi/spring-cloud-hystrix-weather-app.git
这篇关于无法连接到命令指标流.在 Hystrix 仪表板问题中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!