我在我的春季启动应用程序中使用hystrix,但是当我访问 / hystrix-stream 页面时,没有数据。它只显示" ping:"。 在我的 pom.xml 中,我得到了以下内容:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-ribbon</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
我启用了Hystrix和HystrixDashboard。另外,我在我的应用程序中使用功能区。 HystrixCommand看起来像这样:
@HystrixCommand(fallbackMethod = "defaultFallback")
public byte[] doGet() {
return this.restTemplate.getForObject("http://myInstance/api/v3/ressource",byte[].class);
}
public byte[] defaultFallback() {
System.out.println("Now doing fallback!");
return null;
}
当我关闭 myInstance 时,没有调用后备,功能区只显示此失败:
There was an unexpected error (type=Internal Server Error, status=500).
I/O error on POST request for "http:/myInstance/api/v3/ressource": Connection
refused; nested exception is java.net.ConnectException: Connection refused
答案 0 :(得分:0)
您的弹簧靴应用必须启用断路器。
与下一个例子类似:
@EnableCircuitBreaker
@SpringBootApplication
@EnableDiscoveryClient
@EnableWebMvc
public class ClientManagerApp {
public static void main(String[] args) {
SpringApplication.run(ClientManagerApp.class, args);
}
}