Spring Cloud Netflix—如何加入Hystrix
要在項(xiàng)目中包含Hystrix,請(qǐng)使用組org.springframework.cloud和artifact id spring-cloud-starter-hystrix的啟動(dòng)器。有關(guān) 使用當(dāng)前的Spring Cloud發(fā)布列表設(shè)置構(gòu)建系統(tǒng)的詳細(xì)信息,請(qǐng)參閱Spring Cloud項(xiàng)目頁(yè)面。 示例啟動(dòng)應(yīng)用程序:
@SpringBootApplication @EnableCircuitBreaker public class Application {
public static void main(String[] args) {new SpringApplicationBuilder(Application.class).web(true).run(args); } 復(fù)制代碼}
@Component public class StoreIntegration {
@HystrixCommand(fallbackMethod = "defaultStores") public Object getStores(Map<String, Object> parameters) {//do stuff that might fail }public Object defaultStores(Map<String, Object> parameters) {return /* something useful */; } 復(fù)制代碼} @HystrixCommand由名為“javanica”的Netflix contrib庫(kù)提供 。Spring Cloud在連接到Hystrix斷路器的代理中使用該注釋自動(dòng)包裝Spring bean。斷路器計(jì)算何時(shí)打開和關(guān)閉電路,以及在發(fā)生故障時(shí)應(yīng)該做什么。
要配置@HystrixCommand,您可以使用commandProperties屬性列出@HystrixProperty注釋。請(qǐng)參閱 這里 了解更多詳情。有關(guān) 可用屬性的詳細(xì)信息,請(qǐng)參閱Hystrix維基。
源碼來(lái)源:http://minglisoft.cn/honghu/technology.html總結(jié)
以上是生活随笔為你收集整理的Spring Cloud Netflix—如何加入Hystrix的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Linux shell编程(二):she
- 下一篇: SpringCloud采坑之Feign服