W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
Hystrix支持回退的概念:當(dāng)它們的電路斷開(kāi)或出現(xiàn)錯(cuò)誤時(shí)執(zhí)行的默認(rèn)代碼路徑。要為給定的@FeignClient
啟用回退,請(qǐng)將fallback
屬性設(shè)置為實(shí)現(xiàn)回退的類名稱。您還需要將實(shí)現(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"); } }
如果需要訪問(wèn)引起后備觸發(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中的后備實(shí)現(xiàn)以及Hystrix后備如何工作存在局限性。返回com.netflix.hystrix.HystrixCommand
和rx.Observable
的方法當(dāng)前不支持后備。
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: