Skip to content

Commit

Permalink
fix BaseLoggingInterceptor
Browse files Browse the repository at this point in the history
  • Loading branch information
chentianming11 committed Apr 30, 2022
1 parent f50cfbb commit a7c7a94
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 15 deletions.
28 changes: 15 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,18 +147,20 @@ public class TestService {

## 配置项说明

`retrofit-spring-boot-starter`支持了多个可配置的属性,用来应对不同的业务场景。**
`retrofit-spring-boot-starter`支持了多个可配置的属性,用来应对不同的业务场景,具体可支持的配置项及默认值如下:

**注意:应用只需要配置要更改的配置项即可!**

```yaml
retrofit:
# 连接池配置
pool:
# test1连接池配置
test1:
# default连接池
default:
# 最大空闲连接数
max-idle-connections: 3
max-idle-connections: 5
# 连接保活时间(秒)
keep-alive-second: 100
keep-alive-second: 300

# 是否禁用void返回值类型
disable-void-return-type: false
Expand All @@ -182,17 +184,17 @@ retrofit:
# 全局日志打印级别
global-log-level: info
# 全局日志打印策略
global-log-strategy: body
global-log-strategy: basic


# 重试配置
retry:
# 是否启用全局重试
enable-global-retry: true
enable-global-retry: false
# 全局重试间隔时间
global-interval-ms: 1
global-interval-ms: 100
# 全局最大重试次数
global-max-retries: 1
global-max-retries: 2
# 全局重试规则
global-retry-rules:
- response_status_not_2xx
Expand All @@ -203,17 +205,17 @@ retrofit:
# 熔断降级配置
degrade:
# 是否启用熔断降级
enable: true
enable: false
# 熔断降级实现方式
degrade-type: sentinel
# 熔断资源名称解析器
resource-name-parser: com.github.lianjiatech.retrofit.spring.boot.degrade.DefaultResourceNameParser
# 全局连接超时时间
global-connect-timeout-ms: 5000
global-connect-timeout-ms: 10000
# 全局读取超时时间
global-read-timeout-ms: 5000
global-read-timeout-ms: 10000
# 全局写入超时时间
global-write-timeout-ms: 5000
global-write-timeout-ms: 10000
# 全局完整调用超时时间
global-call-timeout-ms: 0
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ private synchronized OkHttpClient getOkHttpClient(Class<?> retrofitClientInterfa
"logStrategy cannot all be configured as LogStrategy.NULL!");

BaseLoggingInterceptor loggingInterceptor = constructor.newInstance(logLevel, logStrategy);
okHttpClientBuilder.addNetworkInterceptor(loggingInterceptor);
okHttpClientBuilder.addInterceptor(loggingInterceptor);
}

List<NetworkInterceptor> networkInterceptors = retrofitConfigBean.getNetworkInterceptors();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.github.lianjiatech.retrofit.spring.boot.interceptor;

import okhttp3.Interceptor;

/**
* @author 陈添明
*/
public abstract class BaseLoggingInterceptor implements NetworkInterceptor {
public abstract class BaseLoggingInterceptor implements Interceptor {

/**
* 日志打印级别
Expand Down
66 changes: 66 additions & 0 deletions src/test/resources/default-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
retrofit:
# 连接池配置
pool:
# default连接池
default:
# 最大空闲连接数
max-idle-connections: 5
# 连接保活时间(秒)
keep-alive-second: 300

# 是否禁用void返回值类型
disable-void-return-type: false


# 全局转换器工厂
global-converter-factories:
- com.github.lianjiatech.retrofit.spring.boot.core.BasicTypeConverterFactory
- retrofit2.converter.jackson.JacksonConverterFactory
# 全局调用适配器工厂
global-call-adapter-factories:
- com.github.lianjiatech.retrofit.spring.boot.core.BodyCallAdapterFactory
- com.github.lianjiatech.retrofit.spring.boot.core.ResponseCallAdapterFactory

# 日志打印配置
log:
# 启用日志打印
enable: true
# 日志打印拦截器
logging-interceptor: com.github.lianjiatech.retrofit.spring.boot.interceptor.DefaultLoggingInterceptor
# 全局日志打印级别
global-log-level: info
# 全局日志打印策略
global-log-strategy: basic


# 重试配置
retry:
# 是否启用全局重试
enable-global-retry: false
# 全局重试间隔时间
global-interval-ms: 100
# 全局最大重试次数
global-max-retries: 2
# 全局重试规则
global-retry-rules:
- response_status_not_2xx
- occur_io_exception
# 重试拦截器
retry-interceptor: com.github.lianjiatech.retrofit.spring.boot.retry.DefaultRetryInterceptor

# 熔断降级配置
degrade:
# 是否启用熔断降级
enable: false
# 熔断降级实现方式
degrade-type: sentinel
# 熔断资源名称解析器
resource-name-parser: com.github.lianjiatech.retrofit.spring.boot.degrade.DefaultResourceNameParser
# 全局连接超时时间
global-connect-timeout-ms: 10000
# 全局读取超时时间
global-read-timeout-ms: 10000
# 全局写入超时时间
global-write-timeout-ms: 10000
# 全局完整调用超时时间
global-call-timeout-ms: 0

0 comments on commit a7c7a94

Please sign in to comment.