当前位置:网站首页>Two call processors of feign
Two call processors of feign
2022-07-27 13:19:00 【Hua Weiyun】
Feign The two call processors
feign The calling processor has a default FeignInvocationHandler
and HystrixInvocationHandler, In this article, we will explain these two classes in detail
FeignInvocationHandler
Feign Execution flow of remote call : call FeignInvocationHandler Of invoke Method
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if ("equals".equals(method.getName())) { try { Object otherHandler = args.length > 0 && args[0] != null ? Proxy.getInvocationHandler(args[0]) : null; return equals(otherHandler); } catch (IllegalArgumentException e) { return false; } } else if ("hashCode".equals(method.getName())) { return hashCode(); } else if ("toString".equals(method.getName())) { return toString(); } return dispatch.get(method).invoke(args); }Called in this method SynchronousMethodHandler Method processor invoke Method :dispatch.get(method).invoke(args);
SynchronousMethodHandler Of invoke In the method, we use RestTemplate Complete the remote call and get the result of the call
FeignInvocationHandler There is no abnormal fuse detection and recovery mechanism , either Http Connection pool .
HystrixInvocationHandler
HystrixInvocationHandler Of invoke Method creation HystrixCommand example ,HystrixCommand Of getFallback() Call in method @FeignClient In the annotations fallback Class specified on property to fail back , Execute the processing of business fallback .
@Override protected Object getFallback() { if (fallbackFactory == null) { return super.getFallback(); } try { Object fallback = fallbackFactory.create(getExecutionException()); Object result = fallbackMethodMap.get(method).invoke(fallback, args); if (isReturnsHystrixCommand(method)) { return ((HystrixCommand) result).execute(); } else if (isReturnsObservable(method)) { // Create a cold Observable return ((Observable) result).toBlocking().first(); } else if (isReturnsSingle(method)) { // Create a cold Observable as a Single return ((Single) result).toObservable().toBlocking().first(); } else if (isReturnsCompletable(method)) { ((Completable) result).await(); return null; } else { return result; } } catch (IllegalAccessException e) { // shouldn't happen as method is public due to being an interface throw new AssertionError(e); } catch (InvocationTargetException e) { // Exceptions on fallback are tossed by Hystrix throw new AssertionError(e.getCause()); } }Feign Of JDK The dynamic proxy instance is through Feign.Builder Of target() Method to complete ,target The first step of the method is through its own build() Method construction RefectiveFeign example , And then call RefectiveFeign Of newInstance() Method to create a real instance , about RefectiveFeign The role of , We explained in detail in our last article , I won't go into that here .
How to use HystrixFeign
stay FeignClientsConfiguration We can see in class HystrixFeign replace feign.Feign Conditions
@Configuration @ConditionalOnClass({ HystrixCommand.class, HystrixFeign.class }) protected static class HystrixFeignConfiguration { @Bean @Scope("prototype") @ConditionalOnMissingBean @ConditionalOnProperty(name = "feign.hystrix.enabled") public Feign.Builder feignHystrixBuilder() { return HystrixFeign.builder(); } }There are in the classpath HystrixCommand Classes and HystrixFeign class , And the configuration file has feign.hystrix.enabled, When these two conditions are met, you can use HystrixFeign Replace the original Feign, Yes , It's so easy to use
summary
This article mainly introduces Feign The two call processors ,FeignInvocationHandler and HystrixInvocationHandler,FeignInvocationHandler There is no exception recovery mechanism for the processor ,HystrixInvocationHandler Call handling supports fusing and exception handling ,getFallback() Handle the business processing that failed the call , In addition, you can configure feign.hystrix.enabled Give Way HystrixFeign To replace feign.Feign
边栏推荐
- Application parameters of Southern biotech HRP labeled avidin avidin avidin
- 7-16 daily sword finger offer II 041. Average value of sliding window
- pg同步多张数据表至mysql 有办法简化配置吗?
- Detail the execution process of JDBC query method
- [Nuxt 3] (十二) 项目目录结构 2
- 2022 global Vocational Education Industry Development Report
- Article reproduction: srcnn
- Distributed system architecture theory and components
- ECCV2022 | RU&谷歌提出用CLIP进行zero-shot目标检测!
- Plus SBOM: assembly line BOM pbom
猜你喜欢

Why does the class annotated with @configuration generate cglib proxy?

Will saffron become a safe and effective natural therapy for patients with arthritis?

Map interface

CVPR22 | 关系意识的图神经架构搜索

开源项目丨Taier1.2版本发布,新增工作流、租户绑定简化等多项功能

面试考点:三种图的问题

v-on基础指令

Overview of static inner classes and non static inner classes

Background and framework introduction and basic environment preparation of hucang integrated e-commerce project

爱可可AI前沿推介(7.27)
随机推荐
Summary of common methods of ArrayList
JS date and time format (year, month, day, hour, minute, second, week, quarter, time difference acquisition, date and timestamp conversion function)
clearfix的作用
@Simple use of conditional
xshell7可以登录mysql虚拟机不能登陆mysql
POJ2594 Treasure Exploration【二分图最小路径覆盖】【Floyd】
AMD Adrenalin 22.7.1 驱动更新:OpenGL 性能翻倍,支持微软 Win11 22H2 系统
2021-03-15
CEPH distributed storage performance tuning (6)
Baoli food listed on Shanghai Stock Exchange: annual revenue of 1.578 billion, market value of 5.8 billion
Application parameters of Southern biotech HRP labeled avidin avidin avidin
爬虫
Delay queue performance test
"Game engine light in light out" 4.1 unity shader and OpenGL shader
ECCV2022 | RU&谷歌提出用CLIP进行zero-shot目标检测!
2021-03-15
粘制定位
Set interface
[cute new solution] Fibonacci sequence
Xposed+fdex2 app shelling (black cat complains about app shelling)