Hystrix
Hystrix是Netflix的库。Hystrix隔离服务之间的访问点,停止服务之间的级联故障,并提供后备选项。
例如,当你调用一个第三方应用程序,它需要更多的时间来发送响应。因此,Hystrix控件将转到后备方法,并将自定义响应返回到您的应用程序。
在本章中,您将看到如何在Spring Boot应用程序中实现Hystrix。
首先,我们需要在构建配置文件中添加Spring Cloud Starter Hystrix依赖项。
Maven用户可以在pom.xml文件中添加以下依赖项-
Maven用户可以将以下依赖项添加到文件中。
-
-
<dependency>
-
<groupId></groupId>
-
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
-
</dependency>
对于Gradle用户,在文件中添加以下依赖项。
implementation ':spring-cloud-starter-hystrix'
现在,将@EnableHystrix注解添加到主Spring Boot应用程序类文件中,@EnableHystrix注解用于将Hystrix功能启用到您的Spring Boot应用程序中。
下面给出了主要的Spring Boot应用程序类文件代码-
-
-
package com.;
-
-
import ;
-
import ;
-
import ;
-
-
@SpringBootApplication
-
@EnableHystrix
-
public class HystrixappApplication {
-
public static void main(String[] args) {
-
(, args);
-
}
-
}
更多的Spring Boot Hystrix 知识