【问题标题】:Hystrix Dashboard Issue in Spring BootSpring Boot 中的 Hystrix 仪表板问题
【发布时间】:2017-02-06 18:07:12
【问题描述】:

我是 Hystrix 仪表板的新手。我已经用 Hystrix 编写了示例应用程序。 我想查看 Hystrix 图表(命令度量流)。但我收到以下错误:

Circuit: Unable to connect to Command Metric Stream
Thread Pools: Loading...

我正在将 STS 与 Maven 一起使用。

下面是使用的代码:

简单的服务器微服务应用(Spring boot web 运行在 8085 端口)

package hello;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;

@RestController
@SpringBootApplication
public class BookstoreApplication {

    @RequestMapping(value = "/recommended")
    public String readingList(){
    return "Spring in Action (Manning), Cloud Native Java (O'Reilly), Learning Spring Boot (Packt)";
    }

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

简单的客户端微服务应用程序(Spring boot web 运行在 8095 端口)我已经包含了 Hystrix 和 Hystrix Dashboard 的依赖以及 Web,所以所有的 Hystrix 依赖都在类路径中

package hello;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.net.URI;

@Service
public class BookService {

    private final RestTemplate restTemplate;

    public BookService(RestTemplate rest) {
    this.restTemplate = rest;
    }

    @HystrixCommand(fallbackMethod = "reliable")
    public String readingList() {
    URI uri = URI.create("http://localhost:8090/recommended");

    return this.restTemplate.getForObject(uri, String.class);
    }

    public String reliable() {
    return "Cloud Native Java (O'Reilly)";
    }

}


package hello;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.web.client.RestTemplate;

@EnableHystrixDashboard
@EnableHystrix
@EnableCircuitBreaker
@RestController
@SpringBootApplication
public class ReadingApplication {

    @Autowired
    private BookService bookService;

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

    @RequestMapping("/to-read")
    public String toRead() {
    return bookService.readingList();
    }

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

通过运行上述代码,hystrix 工作正常,当 BooKStoreApplication 宕机时,它会回退方法。

两个网址都工作正常。 正常情况:

http://localhost:8085/recommended
Output: Spring in Action (Manning), Cloud Native Java (O'Reilly), Learning Spring Boot (Packt)

http://localhost:8095/to-read
Output: Spring in Action (Manning), Cloud Native Java (O'Reilly), Learning Spring Boot (Packt)


When BookStoreApplication is down (http://localhost:8085/recommended) accessing http://localhost:8095/to-read returns "Cloud Native Java (O'Reilly)" as expected.

但是当我尝试调用这个 url http://localhost:8095/hystrix 时,我得到了 Hystrix DashBoard 页面并询问流值。

我试过给http://localhost:8095/或http://localhost:8095/to-read,然后点击“Monitor Stream”,它会进入下一页并出现错误:

Circuit: Unable to connect to Command Metric Stream
Thread Pools: Loading...

【问题讨论】:

    标签: spring spring-boot hystrix


    【解决方案1】:

    我也有同样的经历。主要问题是,我的 maven pom.xml 中没有执行器依赖项。所以我无法获取 hystrix 流。

    1. 包括 spring-boot-actuator。
    2. 检查 localhost:8085/health 是否正在运行。
    3. 尝试输入 localhost:8085/hystrix.stream 以在 Hystrix Dashboard 中流式传输值。
    4. 执行服务几次 -> 仪表板应显示监控的方法/命令。

    【讨论】:

      猜你喜欢
      • 2018-05-08
      • 2018-12-12
      • 2020-03-07
      • 2015-04-13
      • 2017-03-06
      • 2020-09-15
      • 2018-07-07
      • 2023-03-12
      • 2020-10-01
      相关资源
      最近更新 更多