我是Hystrix仪表板的新手。我用Hystrix编写了示例应用程序。 我想查看Hystrix图表(命令度量流)。但我得到以下错误:Spring Boot中的Hystrix仪表板问题
Circuit: Unable to connect to Command Metric Stream
Thread Pools: Loading...
我正在使用STS与Maven。
下面是使用的代码:
简单的服务器的microService申请(春季启动网络在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);
}
}
简单的客户端的microService申请(春季启动网络端口8095上运行),我已经包括猬与网络一起豪猪仪表板的相关性,因此,所有的豪猪依赖是在类路径
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,我正在豪猪仪表板页面,索取流值。
我试图给http://localhost:8095/或http://localhost:8095/to-read,并点击“监控流”,它是要下一个页面出现错误:
Circuit: Unable to connect to Command Metric Stream
Thread Pools: Loading...