當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
Spring Cloud Netflix—如何加入Hystrix
生活随笔
收集整理的這篇文章主要介紹了
Spring Cloud Netflix—如何加入Hystrix
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
要在項目中包含Hystrix,請使用組org.springframework.cloud和artifact id spring-cloud-starter-hystrix的啟動器。有關 使用當前的Spring Cloud發(fā)布列表設置構建系統(tǒng)的詳細信息,請參閱Spring Cloud項目頁面。 示例啟動應用程序:
@SpringBootApplication @EnableCircuitBreaker public class Application {
public static void main(String[] args) {new SpringApplicationBuilder(Application.class).web(true).run(args); } 復制代碼}
@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 */; } 復制代碼} @HystrixCommand由名為“javanica”的Netflix contrib庫提供 。Spring Cloud在連接到Hystrix斷路器的代理中使用該注釋自動包裝Spring bean。斷路器計算何時打開和關閉電路,以及在發(fā)生故障時應該做什么。
要配置@HystrixCommand,您可以使用commandProperties屬性列出@HystrixProperty注釋。請參閱 這里 了解更多詳情。有關 可用屬性的詳細信息,請參閱Hystrix維基。
源碼來源:http://minglisoft.cn/honghu/technology.html總結
以上是生活随笔為你收集整理的Spring Cloud Netflix—如何加入Hystrix的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Linux shell编程(二):she
- 下一篇: 数据库01-范式总结