1. Feign common optimization
1.feign timeout
effect
The default timeout of feign is 1s. When processing some services, an error will be reported over time. Configuring timeout optimization can solve the problem.
Configuration method
Configure in consumer:
method one
ribbon:
connectionTimeout: 5000 #连接超时时间
readTimeout: 5000 #响应超时时间
Method 2
feign:
client:
config:
#default: #把feign-provider替换成default就是配置所有服务
feign-provider: #只feign-provider服务
connectionTimeout: 5000 #连接超时时间
readTimeout: 5000 #响应超时时间
**Note:** There is no need to configure the media type because there is a default value
2. feign log
Configure in consumer:
feign:
client:
config:
default:
loggerLevel: full #输出feign远程调用的日志信息
logging:
level:
com.bjpowernode.feign: debug #log4j的日志级别
**Note:** There is no effect if log4j is not enabled
3. Feign’s gzip compression
effect
Speed up web page loading and save bandwidth.
Configuration method
Configure in consumer:
server:
compression:
enabled: true #开启浏览器---->consumer的gzip压缩
feign:
compression:
request:
enabled: true #开启请求压缩 #开启feign---->provider的zip压缩
response:
enabled: true #开启响应压缩
test
4. http connection pool
effect
Improve performance and save a lot of time.
Configuration method
Introduce dependencies into consumer:
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-httpclient</artifactId>
</dependency>
**Note:** You only need to introduce dependencies in the consumer. There is no need to configure it because it is enabled by default.