无法连接到 Command Metric Stream。在 Hystrix 仪表板问题中

Posted

技术标签:

【中文标题】无法连接到 Command Metric Stream。在 Hystrix 仪表板问题中【英文标题】:Unable to connect to Command Metric Stream. in Hystrix Dashboard issue 【发布时间】:2020-05-01 11:39:10 【问题描述】:

在发布这个问题之前,我浏览了许多链接,例如:Unable to connect to Command Metric Stream for Hystrix Dashboard with Spring Cloud 和 Unable to connect to Command Metric Stream in Spring Cloud + Hystrix + Turbine - MIME type ("text/plain") that is not "text/event-stream" 等等,但仍然无法正常工作。

我使用的是 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>

天气应用::

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

天气服务::

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];
    

这里的源代码:https://github.com/javaHelper/spring-cloud-cordinating-services/tree/master/Protecting-Systems-with-Circuit-Breakers

【问题讨论】:

您的源代码链接和问题中的代码似乎不匹配。链接是否正确? 是的,它是一样的。在所有项目和所需依赖项中使用 SPring Boot 2.2.2.RELEASE 时出现问题 还在面对吗?还是解决了。如果没有,我可以下载你的源代码看看有什么问题。 不,还没有解决。请求您了解为什么 RabbitMQ 显示不同队列中的事件和其他问题 您的依赖项似乎无处不在。版本中有很多冲突和重复。尝试清除缓存并重建项目,首先修复依赖问题。将公共依赖项移至其他模块正在使用的模块。 【参考方案1】:

尝试在对我有用的 Hystrix Dashboard 项目中添加以下行。

application.yml

hystrix:
  dashboard:
    proxy-stream-allow-list: "*"

【讨论】:

【参考方案2】:

仪表板项目中将此添加到您的属性中

hystrix:
  dashboard:
    proxy-stream-allow-list: "*"

并且,在 weather-app 中添加这个

management:
  endpoints:
    web:
      exposure:
        include: "*"

然后,打开 http://localhost:8080/hystrix 并添加 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

【讨论】:

【参考方案3】:

我刚刚在application.properties 文件中添加了以下内容,它开始工作了:

management.endpoint.hystrix.stream.enabled=true

【讨论】:

只有这个属性值不会被更正。【参考方案4】:

将以下属性添加到application.properties 文件

management.endpoints.web.exposure.include=*
hystrix.dashboard.proxy-stream-allow-list=*

【讨论】:

【参考方案5】:

您必须提供的 Hystrix Dashboard 流 URL 现在是:

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

【讨论】:

以上是关于无法连接到 Command Metric Stream。在 Hystrix 仪表板问题中的主要内容,如果未能解决你的问题,请参考以下文章

无法使用 Spring Cloud 连接到 Hystrix Dashboard 的 Command Metric Stream

Discord bot无法连接到语音通道(python)

Databricks Connect:无法连接到 azure 上的远程集群,命令:“databricks-connect test”停止

使用 connect 方法连接到一个插槽

FTP总是无法连接到服务器

instruments无法连接,设备查询不到,找不到工程,查询不到对应app