mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-10-28 12:37:55 +08:00
🎨 starter模块添加 HttpClient 超时配置
This commit is contained in:
@ -9,6 +9,8 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import me.chanjar.weixin.common.redis.JedisWxRedisOps;
|
||||
import me.chanjar.weixin.common.redis.RedisTemplateWxRedisOps;
|
||||
import me.chanjar.weixin.common.redis.WxRedisOps;
|
||||
import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder;
|
||||
import me.chanjar.weixin.common.util.http.apache.DefaultApacheHttpClientBuilder;
|
||||
import me.chanjar.weixin.mp.config.WxMpConfigStorage;
|
||||
import me.chanjar.weixin.mp.config.WxMpHostConfig;
|
||||
import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
|
||||
@ -122,6 +124,19 @@ public class WxMpStorageAutoConfiguration {
|
||||
config.setSecret(properties.getSecret());
|
||||
config.setToken(properties.getToken());
|
||||
config.setAesKey(properties.getAesKey());
|
||||
WxMpProperties.ConfigStorage storage = properties.getConfigStorage();
|
||||
// 设置自定义的HttpClient超时配置
|
||||
ApacheHttpClientBuilder clientBuilder = config.getApacheHttpClientBuilder();
|
||||
if (clientBuilder == null) {
|
||||
clientBuilder = DefaultApacheHttpClientBuilder.get();
|
||||
}
|
||||
if (clientBuilder instanceof DefaultApacheHttpClientBuilder) {
|
||||
DefaultApacheHttpClientBuilder defaultBuilder = (DefaultApacheHttpClientBuilder) clientBuilder;
|
||||
defaultBuilder.setConnectionTimeout(storage.getConnectionTimeout());
|
||||
defaultBuilder.setSoTimeout(storage.getSoTimeout());
|
||||
defaultBuilder.setConnectionRequestTimeout(storage.getConnectionRequestTimeout());
|
||||
config.setApacheHttpClientBuilder(defaultBuilder);
|
||||
}
|
||||
config.setUseStableAccessToken(wxMpProperties.isUseStableAccessToken());
|
||||
config.setHttpProxyHost(configStorageProperties.getHttpProxyHost());
|
||||
config.setHttpProxyUsername(configStorageProperties.getHttpProxyUsername());
|
||||
|
||||
@ -102,6 +102,21 @@ public class WxMpProperties {
|
||||
*/
|
||||
private String httpProxyPassword;
|
||||
|
||||
/**
|
||||
* 连接超时时间,单位毫秒
|
||||
*/
|
||||
private int connectionTimeout = 5000;
|
||||
|
||||
/**
|
||||
* 读数据超时时间,即socketTimeout,单位毫秒
|
||||
*/
|
||||
private int soTimeout = 1;
|
||||
|
||||
/**
|
||||
* 从连接池获取链接的超时时间,单位毫秒
|
||||
*/
|
||||
private int connectionRequestTimeout = 5000;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user