Feign configuration

1. Feign configuration source code

public static class FeignClientConfiguration {
    private Level loggerLevel;
    private Integer connectTimeout;
    private Integer readTimeout;
    private Class<Retryer> retryer;
    private Class<ErrorDecoder> errorDecoder;
    private List<Class<RequestInterceptor>> requestInterceptors;
    private Map<String, Collection<String>> defaultRequestHeaders;
    private Map<String, Collection<String>> defaultQueryParameters;
    private Boolean decode404;
    private Class<Decoder> decoder;
    private Class<Encoder> encoder;
    private Class<Contract> contract;
    private ExceptionPropagationPolicy exceptionPropagationPolicy;
}   
Copy the code

2. Configure the Feign attribute

Feign: client: config: # name of the microservice you want to call user-center: connectTimeout: 5000 # readTimeout: 5000 # readTimeout loggerLevel: Full # log level errorDecoder: com. Example. SimpleErrorDecoder # error decoder retryer: Com. Example. # SimpleRetryer retry strategy requestInterceptors: - com. Example. FooRequestInterceptor # interceptor defaultQueryParameters: Query: queryValue defaultRequestHeaders: queryValue header: headerValue decode404: false encoder: Com. Example. # SimpleEncoder encoder decoder: com. Example. SimpleDecoder # decoder contract: com. Example. # SimpleContract contractCopy the code

Configure a global log level

Feign: client: config: # Global configuration Default: loggerLevel: full # Log levelCopy the code

Feign performance optimization

1. Set a connection pool

1.1. Collocation httpclient

A. Introduce dependencies

<dependency>
    <groupId>io.github.openfeign</groupId>
    <artifactId>feign-httpclient</artifactId>
</dependency>
Copy the code

B. to write configuration

Feign: client: config: user-center: # Log level (NONE,BASIC,HEADERS,FULL) loggerLevel: FULL httpClient: # allow feign to use apache httpClient request, default is URLConnection enabled: true # allow Feign maximum number of connections max-connections: 200 # feign Maximum number of connections on a single path max-connections-per-route: 50Copy the code

1.2. Or with okhttp

A. Introduce dependencies

<! <dependency> <groupId>io.github. Openfeign </groupId> <artifactId>feign-okhttp</artifactId> The < version > 11.0 < / version > < / dependency >Copy the code

B. to write configuration

Feign: client: config: user-center: # Log level (NONE,BASIC,HEADERS,FULL) loggerLevel: FULL okhttp: enabled: True # Feign Maximum number of connections max-connections: 200 # feign Maximum number of connections per path max-connections-per-route: 50Copy the code

2. Set the Feign log level to NONE or BASIC