🎨 wx-java-open-spring-boot-starter 增加重试次数配置

This commit is contained in:
Forever杨
2021-04-21 13:27:59 +08:00
committed by GitHub
parent 0a75b0e902
commit 3eabfedd9c
15 changed files with 201 additions and 59 deletions

View File

@ -27,6 +27,10 @@
wx.open.config-storage.http-proxy-port=
wx.open.config-storage.http-proxy-username=
wx.open.config-storage.http-proxy-password=
# 最大重试次数默认5 次,如果小于 0则为 0
wx.open.config-storage.max-retry-times=5
# 重试时间间隔步进默认1000 毫秒,如果小于 0则为 1000
wx.open.config-storage.retry-sleep-millis=1000
```
3. 支持自动注入的类型: `WxOpenService, WxOpenMessageRouter, WxOpenComponentService`

View File

@ -1,7 +1,7 @@
package com.binarywang.spring.starter.wxjava.open.config;
import com.binarywang.spring.starter.wxjava.open.config.storage.WxOpenInJedisConfigStorageConfiguration;
import com.binarywang.spring.starter.wxjava.open.config.storage.WxOpenInMemoryConfigStorageConfiguration;
import com.binarywang.spring.starter.wxjava.open.config.storage.WxOpenInRedisConfigStorageConfiguration;
import com.binarywang.spring.starter.wxjava.open.config.storage.WxOpenInRedisTemplateConfigStorageConfiguration;
import com.binarywang.spring.starter.wxjava.open.config.storage.WxOpenInRedissonConfigStorageConfiguration;
import org.springframework.context.annotation.Configuration;
@ -16,7 +16,7 @@ import org.springframework.context.annotation.Import;
@Import({
WxOpenInMemoryConfigStorageConfiguration.class,
WxOpenInRedisTemplateConfigStorageConfiguration.class,
WxOpenInRedisConfigStorageConfiguration.class,
WxOpenInJedisConfigStorageConfiguration.class,
WxOpenInRedissonConfigStorageConfiguration.class
})
public class WxOpenStorageAutoConfiguration {

View File

@ -0,0 +1,32 @@
package com.binarywang.spring.starter.wxjava.open.config.storage;
import com.binarywang.spring.starter.wxjava.open.properties.WxOpenProperties;
import me.chanjar.weixin.open.api.impl.WxOpenInMemoryConfigStorage;
/**
* @author yl
*/
public abstract class AbstractWxOpenConfigStorageConfiguration {
protected WxOpenInMemoryConfigStorage config(WxOpenInMemoryConfigStorage config, WxOpenProperties properties) {
WxOpenProperties.ConfigStorage configStorageProperties = properties.getConfigStorage();
config.setWxOpenInfo(properties.getAppId(), properties.getSecret(), properties.getToken(), properties.getAesKey());
config.setHttpProxyHost(configStorageProperties.getHttpProxyHost());
config.setHttpProxyUsername(configStorageProperties.getHttpProxyUsername());
config.setHttpProxyPassword(configStorageProperties.getHttpProxyPassword());
if (configStorageProperties.getHttpProxyPort() != null) {
config.setHttpProxyPort(configStorageProperties.getHttpProxyPort());
}
int maxRetryTimes = configStorageProperties.getMaxRetryTimes();
if (configStorageProperties.getMaxRetryTimes() < 0) {
maxRetryTimes = 0;
}
int retrySleepMillis = configStorageProperties.getRetrySleepMillis();
if (retrySleepMillis < 0) {
retrySleepMillis = 1000;
}
config.setRetrySleepMillis(retrySleepMillis);
config.setMaxRetryTimes(maxRetryTimes);
return config;
}
}

View File

@ -27,7 +27,7 @@ import redis.clients.jedis.JedisPoolConfig;
)
@ConditionalOnClass({JedisPool.class, JedisPoolConfig.class})
@RequiredArgsConstructor
public class WxOpenInRedisConfigStorageConfiguration {
public class WxOpenInJedisConfigStorageConfiguration extends AbstractWxOpenConfigStorageConfiguration {
private final WxOpenProperties properties;
private final ApplicationContext applicationContext;
@ -35,16 +35,7 @@ public class WxOpenInRedisConfigStorageConfiguration {
@ConditionalOnMissingBean(WxOpenConfigStorage.class)
public WxOpenConfigStorage wxOpenConfigStorage() {
WxOpenInMemoryConfigStorage config = getWxOpenInRedisConfigStorage();
WxOpenProperties.ConfigStorage configStorageProperties = properties.getConfigStorage();
config.setWxOpenInfo(properties.getAppId(), properties.getSecret(), properties.getToken(), properties.getAesKey());
config.setHttpProxyHost(configStorageProperties.getHttpProxyHost());
config.setHttpProxyUsername(configStorageProperties.getHttpProxyUsername());
config.setHttpProxyPassword(configStorageProperties.getHttpProxyPassword());
if (configStorageProperties.getHttpProxyPort() != null) {
config.setHttpProxyPort(configStorageProperties.getHttpProxyPort());
}
return config;
return this.config(config, properties);
}
private WxOpenInRedisConfigStorage getWxOpenInRedisConfigStorage() {

View File

@ -18,22 +18,13 @@ import org.springframework.context.annotation.Configuration;
matchIfMissing = true, havingValue = "memory"
)
@RequiredArgsConstructor
public class WxOpenInMemoryConfigStorageConfiguration {
public class WxOpenInMemoryConfigStorageConfiguration extends AbstractWxOpenConfigStorageConfiguration {
private final WxOpenProperties properties;
@Bean
@ConditionalOnMissingBean(WxOpenConfigStorage.class)
public WxOpenConfigStorage wxOpenConfigStorage() {
WxOpenInMemoryConfigStorage config = new WxOpenInMemoryConfigStorage();
WxOpenProperties.ConfigStorage configStorageProperties = properties.getConfigStorage();
config.setWxOpenInfo(properties.getAppId(), properties.getSecret(), properties.getToken(), properties.getAesKey());
config.setHttpProxyHost(configStorageProperties.getHttpProxyHost());
config.setHttpProxyUsername(configStorageProperties.getHttpProxyUsername());
config.setHttpProxyPassword(configStorageProperties.getHttpProxyPassword());
if (configStorageProperties.getHttpProxyPort() != null) {
config.setHttpProxyPort(configStorageProperties.getHttpProxyPort());
}
return config;
return this.config(config, properties);
}
}

View File

@ -24,7 +24,7 @@ import org.springframework.data.redis.core.StringRedisTemplate;
)
@ConditionalOnClass(StringRedisTemplate.class)
@RequiredArgsConstructor
public class WxOpenInRedisTemplateConfigStorageConfiguration {
public class WxOpenInRedisTemplateConfigStorageConfiguration extends AbstractWxOpenConfigStorageConfiguration {
private final WxOpenProperties properties;
private final ApplicationContext applicationContext;
@ -32,16 +32,7 @@ public class WxOpenInRedisTemplateConfigStorageConfiguration {
@ConditionalOnMissingBean(WxOpenConfigStorage.class)
public WxOpenConfigStorage wxOpenConfigStorage() {
WxOpenInMemoryConfigStorage config = getWxOpenInRedisTemplateConfigStorage();
WxOpenProperties.ConfigStorage configStorageProperties = properties.getConfigStorage();
config.setWxOpenInfo(properties.getAppId(), properties.getSecret(), properties.getToken(), properties.getAesKey());
config.setHttpProxyHost(configStorageProperties.getHttpProxyHost());
config.setHttpProxyUsername(configStorageProperties.getHttpProxyUsername());
config.setHttpProxyPassword(configStorageProperties.getHttpProxyPassword());
if (configStorageProperties.getHttpProxyPort() != null) {
config.setHttpProxyPort(configStorageProperties.getHttpProxyPort());
}
return config;
return this.config(config, properties);
}
private WxOpenInRedisConfigStorage getWxOpenInRedisTemplateConfigStorage() {

View File

@ -29,7 +29,7 @@ import org.springframework.context.annotation.Configuration;
)
@ConditionalOnClass({Redisson.class, RedissonClient.class})
@RequiredArgsConstructor
public class WxOpenInRedissonConfigStorageConfiguration {
public class WxOpenInRedissonConfigStorageConfiguration extends AbstractWxOpenConfigStorageConfiguration {
private final WxOpenProperties properties;
private final ApplicationContext applicationContext;
@ -37,16 +37,7 @@ public class WxOpenInRedissonConfigStorageConfiguration {
@ConditionalOnMissingBean(WxOpenConfigStorage.class)
public WxOpenConfigStorage wxOpenConfigStorage() {
WxOpenInMemoryConfigStorage config = getWxOpenInRedissonConfigStorage();
WxOpenProperties.ConfigStorage configStorageProperties = properties.getConfigStorage();
config.setWxOpenInfo(properties.getAppId(), properties.getSecret(), properties.getToken(), properties.getAesKey());
config.setHttpProxyHost(configStorageProperties.getHttpProxyHost());
config.setHttpProxyUsername(configStorageProperties.getHttpProxyUsername());
config.setHttpProxyPassword(configStorageProperties.getHttpProxyPassword());
if (configStorageProperties.getHttpProxyPort() != null) {
config.setHttpProxyPort(configStorageProperties.getHttpProxyPort());
}
return config;
return this.config(config, properties);
}
private WxOpenInRedisConfigStorage getWxOpenInRedissonConfigStorage() {

View File

@ -91,6 +91,23 @@ public class WxOpenProperties {
*/
private String httpProxyPassword;
/**
* http 请求重试间隔
* <pre>
* {@link me.chanjar.weixin.mp.api.impl.BaseWxMpServiceImpl#setRetrySleepMillis(int)}
* {@link cn.binarywang.wx.miniapp.api.impl.BaseWxMaServiceImpl#setRetrySleepMillis(int)}
* </pre>
*/
private int retrySleepMillis = 1000;
/**
* http 请求最大重试次数
* <pre>
* {@link me.chanjar.weixin.mp.api.impl.BaseWxMpServiceImpl#setMaxRetryTimes(int)}
* {@link cn.binarywang.wx.miniapp.api.impl.BaseWxMaServiceImpl#setMaxRetryTimes(int)}
* </pre>
*/
private int maxRetryTimes = 5;
}
public enum StorageType {