W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
Hystrix支持回退的概念:當它們的電路斷開或出現(xiàn)錯誤時執(zhí)行的默認代碼路徑。要為給定的@FeignClient
啟用回退,請將fallback
屬性設置為實現(xiàn)回退的類名稱。您還需要將實現(xiàn)聲明為Spring bean。
@FeignClient(name = "hello", fallback = HystrixClientFallback.class) protected interface HystrixClient { @RequestMapping(method = RequestMethod.GET, value = "/hello") Hello iFailSometimes(); } static class HystrixClientFallback implements HystrixClient { @Override public Hello iFailSometimes() { return new Hello("fallback"); } }
如果需要訪問引起后備觸發(fā)器的原因,則可以使用@FeignClient
中的fallbackFactory
屬性。
@FeignClient(name = "hello", fallbackFactory = HystrixClientFallbackFactory.class) protected interface HystrixClient { @RequestMapping(method = RequestMethod.GET, value = "/hello") Hello iFailSometimes(); } @Component static class HystrixClientFallbackFactory implements FallbackFactory<HystrixClient> { @Override public HystrixClient create(Throwable cause) { return new HystrixClient() { @Override public Hello iFailSometimes() { return new Hello("fallback; reason was: " + cause.getMessage()); } }; } }
Feign中的后備實現(xiàn)以及Hystrix后備如何工作存在局限性。返回com.netflix.hystrix.HystrixCommand
和rx.Observable
的方法當前不支持后備。
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: