SpringCloudOpenFeign源码深度解析
2022-11-01 13:48:30 2 举报
AI智能生成
有钱给点儿,没钱拉倒
作者其他创作
大纲/内容
启动流程
@EnableFeignClients
@Import({FeignClientsRegistrar.class})
registerBeanDefinitions
this.registerDefaultConfiguration(metadata, registry);
getAnnotationAttributes(EnableFeignClients.class.getName())
registerClientConfiguration
genericBeanDefinition(FeignClientSpecification.class)
this.registerFeignClients(metadata, registry);
if
else
this.getScanner()
scanner.addIncludeFilter(new AnnotationTypeFilter(FeignClient.class))
this.getBasePackages(metadata)
scanner.findCandidateComponents(basePackage)
this.registerClientConfiguration(registry, name, attributes.get("configuration"));
this.registerFeignClient(registry, annotationMetadata, attributes);
关系图
new FeignClientFactoryBean()
BeanDefinitionReaderUtils.registerBeanDefinition(holder, registry)
return factoryBean.getObject()
getTarget()
beanFactory.getBean(FeignContext.class) :
FeignAutoConfiguration
FeignContext
OkHttpFeignConfiguration
okhttp3.OkHttpClient
Client
builder = this.feign(context)
Contract
Level
Logger
this.loadBalance
this.getOptional(context, Client.class)
FeignContext.getBean(Client.class)
BlockingLoadBalancerClientAutoConfiguration
new BlockingLoadBalancerClient(loadBalancerClientFactory, properties)
HttpClientFeignLoadBalancerConfiguration
new FeignBlockingLoadBalancerClient
builder.client(client)
Targeter targeter =this.get(context, Targeter.class);
FeignContext.getBean(Client.class)
FeignAutoConfiguration.DefaultFeignTargeterConfiguration
new DefaultTargeter()
targeter.target(this, builder, context, target)
DefaultTargeter.target
Builder.target
Feign.builder()
new ReflectiveFeign
newInstance
feign.ReflectiveFeign.ParseHandlersByName#apply
contract.parseAndValidateMetadata
SpringMvcContract#parseAndValidateMetadata
super.parseAndValidateMetadata(targetType, method);
this.processAnnotationOnClass(data, targetType)
findMergedAnnotation(clz, RequestMapping.class)
this.processAnnotationOnMethod(data, methodAnnotation, method)
data.template().uri(pathValue, true);
this.processAnnotationsOnParameter
this.factory.create(target, methodToHandler)
Proxy.newProxyInstance
调用流程
ReflectiveFeign#invoke
SynchronousMethodHandler#invoke
this.buildTemplateFromArgs.create(argv);
this.resolve(argv, mutable, varBuilder)
resolved.uri(uri.toString())
UriTemplate.create(uri, !this.decodeSlash, this.charset)
resolved.headers(Collections.emptyMap())
this.findOptions(argv);
this.executeAndDecode(template, options);
this.targetRequest(template);
this.logger.logRequest
this.client.execute(request, options)
FeignBlockingLoadBalancerClient#execute
URI.create(request.url());
loadBalancerClient.choose(serviceId, lbRequest)
扩展点
BlockingLoadBalancerClient implements LoadBalancerClient
重写chose方法
loadBalancerClient.reconstructURI(instance, originalUri)
this.buildRequest(request, message)
executeWithLoadBalancerLifecycleProcessing
feignClient.execute(feignRequest, options)
requestScoped.newCall(request).execute()
this.client.dispatcher().finished(this)
this.promoteAndExecute();
0 条评论
下一页