W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
要將Hystrix包含在您的項目中,請使用起始者,其組ID為org.springframework.cloud
,工件ID為??spring-cloud-starter-netflix-hystrix
。有關(guān)使用當前Spring Cloud版本Train設置構(gòu)建系統(tǒng)的詳細信息,請參見Spring Cloud項目頁面。
以下示例顯示了具有Hystrix斷路器的最小Eureka服務器:
@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將帶有注釋的Spring beans自動包裝在與Hystrix斷路器連接的代理中。斷路器計算何時斷開和閉合電路,以及在發(fā)生故障時應采取的措施。
要配置@HystrixCommand
,可以將commandProperties
屬性與@HystrixProperty
批注一起使用。有關(guān) 更多詳細信息,請參見 此處。有關(guān) 可用屬性的詳細信息,請參見Hystrix Wiki。
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: