table of Contents
Feign series (03) Feign works
How 1. Feign is designed
First, look at Feign
the basic usage:
// 1. Feign 动态代理
GitHub github = Feign.builder()
.decoder(new GsonDecoder())
.target(GitHub.class, "https://api.github.com");
// 2. Feign 执行
List<Contributor> contributors = github.contributors("OpenFeign", "feign");
Summary: Feign
into the use of two steps: first, to generate dynamic proxy Feign; second Feign performed.
to sum up:
- The first two steps is to generate a dynamic object: Method A Resolution annotations into MethodMetadata, and ultimately generate Feign dynamic proxy object.
- After calling process steps: The analytical MethodMetadata objects, the method of converting into a Method parameter Request, Client last call transmission request.
2. Feign dynamic proxy
2.1
public Feign build() {
// client 有三种实现 JdkHttp/ApacheHttp/okHttp,默认是 jdk 的实现
SynchronousMethodHandler.Factory synchronousMethodHandlerFactory =
new SynchronousMethodHandler.Factory(client, retryer, requestInterceptors, logger,
logLevel, decode404, closeAfterDecode, propagationPolicy);
ParseHandlersByName handlersByName =
new ParseHandlersByName(contract, options, encoder, decoder, queryMapEncoder,
errorDecoder, synchronousMethodHandlerFactory);
return new ReflectiveFeign(handlersByName, invocationHandlerFactory, queryMapEncoder);
}
3. Feign calling process
The intentions of recording a little bit every day. Perhaps the content is not important, but the habit is very important!