Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
[feat] 增加重试次数,和重试间隔配置
  • Loading branch information
foreveryang321 committed Dec 6, 2021
commit 554a8701cd4b46485573451455824d593737dde6
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.binarywang.spring.starter.wxjava.cp.config;

import com.binarywang.spring.starter.wxjava.cp.properties.WxCpProperties;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl;
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
Expand All @@ -15,14 +17,28 @@
* @date 2021/12/6
*/
@Configuration
@RequiredArgsConstructor
public class WxCpServiceAutoConfiguration {
private final WxCpProperties wxCpProperties;

@Bean
@ConditionalOnMissingBean
@ConditionalOnBean(WxCpConfigStorage.class)
public WxCpService wxCpService(WxCpConfigStorage wxCpConfigStorage) {
WxCpService wxCpService = new WxCpServiceImpl();
wxCpService.setWxCpConfigStorage(wxCpConfigStorage);

WxCpProperties.ConfigStorage storage = wxCpProperties.getConfigStorage();
int maxRetryTimes = storage.getMaxRetryTimes();
if (maxRetryTimes < 0) {
maxRetryTimes = 0;
}
int retrySleepMillis = storage.getRetrySleepMillis();
if (retrySleepMillis < 0) {
retrySleepMillis = 1000;
}
wxCpService.setRetrySleepMillis(retrySleepMillis);
wxCpService.setMaxRetryTimes(maxRetryTimes);
return wxCpService;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,24 @@ public static class ConfigStorage implements Serializable {
* http代理密码
*/
private String httpProxyPassword;

/**
* http 请求最大重试次数
* <pre>
* {@link me.chanjar.weixin.cp.api.WxCpService#setMaxRetryTimes(int)}
* {@link me.chanjar.weixin.cp.api.impl.BaseWxCpServiceImpl#setMaxRetryTimes(int)}
* </pre>
*/
private int maxRetryTimes = 5;

/**
* http 请求重试间隔
* <pre>
* {@link me.chanjar.weixin.cp.api.WxCpService#setRetrySleepMillis(int)}
* {@link me.chanjar.weixin.cp.api.impl.BaseWxCpServiceImpl#setRetrySleepMillis(int)}
* </pre>
*/
private int retrySleepMillis = 1000;
}

public enum StorageType {
Expand Down