Skip to content

Commit

Permalink
Merge branch '3.11.x' into github_master
Browse files Browse the repository at this point in the history
  • Loading branch information
jsonwan committed Dec 13, 2024
2 parents f893700 + ddd42f0 commit 52d573c
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public EsbIamClient(MeterRegistry meterRegistry,
meterRegistry,
IAM_API,
esbProperties.getService().getUrl(),
HttpHelperFactory.getDefaultHttpHelper(
HttpHelperFactory.createHttpHelper(
httpClientBuilder -> httpClientBuilder.addInterceptorLast(getLogBkApiRequestIdInterceptor())
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,28 @@ private static WatchableHttpHelper getWatchableExtHelper(HttpHelper httpHelper)
}

public static WatchableHttpHelper getDefaultHttpHelper() {
return getDefaultHttpHelper(null);
HttpHelper baseHttpHelper = new BaseHttpHelper(DEFAULT_HTTP_CLIENT);
return getWatchableExtHelper(baseHttpHelper);
}

@SuppressWarnings("unused")
public static WatchableHttpHelper getRetryableHttpHelper() {
HttpHelper baseHttpHelper = new BaseHttpHelper(RETRYABLE_HTTP_CLIENT);
return getWatchableExtHelper(baseHttpHelper);
}

public static WatchableHttpHelper getLongRetryableHttpHelper() {
HttpHelper baseHttpHelper = new BaseHttpHelper(LONG_RETRYABLE_HTTP_CLIENT);
return getWatchableExtHelper(baseHttpHelper);
}

public static WatchableHttpHelper getDefaultHttpHelper(JobHttpClientFactory.HttpClientCustomizer customizer) {
/**
* 创建自定义的HttpHelper,每创建一次都会生成一个常驻的连接驱逐线程,请在单例中使用,避免线程泄露
*
* @param customizer 自定义的HttpClient定制器
* @return 自定义的HttpHelper
*/
public static WatchableHttpHelper createHttpHelper(JobHttpClientFactory.HttpClientCustomizer customizer) {
HttpHelper baseHttpHelper = createHttpHelper(
15000,
15000,
Expand All @@ -80,17 +98,20 @@ public static WatchableHttpHelper getDefaultHttpHelper(JobHttpClientFactory.Http
return getWatchableExtHelper(baseHttpHelper);
}

@SuppressWarnings("unused")
public static WatchableHttpHelper getRetryableHttpHelper() {
HttpHelper baseHttpHelper = new BaseHttpHelper(RETRYABLE_HTTP_CLIENT);
return getWatchableExtHelper(baseHttpHelper);
}

public static WatchableHttpHelper getLongRetryableHttpHelper() {
HttpHelper baseHttpHelper = new BaseHttpHelper(LONG_RETRYABLE_HTTP_CLIENT);
return getWatchableExtHelper(baseHttpHelper);
}

/**
* 创建自定义的HttpHelper,每创建一次都会生成一个常驻的连接驱逐线程,请在单例中使用,避免线程泄露
*
* @param connRequestTimeout 连接请求超时时间,单位毫秒
* @param connTimeout 连接超时时间,单位毫秒
* @param socketTimeout socket读写超时时间,单位毫秒
* @param maxConnPerRoute 单个路由最大连接数
* @param maxConnTotal 总的最大连接数
* @param timeToLive 连接驱逐线程存活时间,单位秒
* @param allowRetry 是否允许重试
* @param retryHandler 重试策略
* @param customizer 自定义的HttpClient定制器
* @return 自定义的HttpHelper
*/
public static HttpHelper createHttpHelper(int connRequestTimeout,
int connTimeout,
int socketTimeout,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public BkNoticeClient(MeterRegistry meterRegistry,
meterRegistry,
CommonMetricNames.BK_NOTICE_API,
getBkNoticeUrlSafely(bkApiGatewayProperties),
HttpHelperFactory.getDefaultHttpHelper(
HttpHelperFactory.createHttpHelper(
httpClientBuilder -> httpClientBuilder.addInterceptorLast(getLogBkApiRequestIdInterceptor())
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public CmsiApiClient(EsbProperties esbProperties,
meterRegistry,
ESB_CMSI_API,
esbProperties.getService().getUrl(),
HttpHelperFactory.getDefaultHttpHelper(
HttpHelperFactory.createHttpHelper(
httpClientBuilder -> httpClientBuilder.addInterceptorLast(getLogBkApiRequestIdInterceptor())
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public StandardLoginClient(EsbProperties esbProperties, AppProperties appPropert
meterRegistry,
ESB_BK_LOGIN_API,
esbProperties.getService().getUrl(),
HttpHelperFactory.getDefaultHttpHelper(
HttpHelperFactory.createHttpHelper(
httpClientBuilder -> httpClientBuilder.addInterceptorLast(getLogBkApiRequestIdInterceptor())
)
);
Expand Down

0 comments on commit 52d573c

Please sign in to comment.