mirror of
https://gitee.com/dromara/sms4j.git
synced 2025-12-06 17:08:40 +08:00
solon的Redis注入加入重试机制
添加一个空接口,用于标定配置类的额外类型
This commit is contained in:
parent
d521b0e8d1
commit
0f0c9c06da
@ -0,0 +1,10 @@
|
||||
package org.dromara.sms4j.api.universal;
|
||||
|
||||
/**
|
||||
* SupplierConfig
|
||||
* <p> 空接口,无含义,只为标定配置类的额外类型
|
||||
* @author :Wind
|
||||
* 2023/5/16 15:14
|
||||
**/
|
||||
public interface SupplierConfig {
|
||||
}
|
||||
@ -6,6 +6,7 @@ import org.dromara.sms4j.comm.enumerate.SupplierType;
|
||||
import org.dromara.sms4j.comm.utils.JDBCTool;
|
||||
import org.dromara.sms4j.comm.utils.SmsUtil;
|
||||
import org.dromara.sms4j.core.config.SupplierFactory;
|
||||
import org.dromara.sms4j.ctyun.config.CtyunConfig;
|
||||
import org.dromara.sms4j.emay.config.EmayConfig;
|
||||
import org.dromara.sms4j.huawei.config.HuaweiConfig;
|
||||
import org.dromara.sms4j.jdcloud.config.JdCloudConfig;
|
||||
@ -48,6 +49,7 @@ public class SupplierSqlConfig {
|
||||
yunPian();
|
||||
cloopen();
|
||||
emay();
|
||||
ctyun();
|
||||
}
|
||||
|
||||
public SupplierSqlConfig() {
|
||||
@ -136,4 +138,14 @@ public class SupplierSqlConfig {
|
||||
EmayConfig emayConfig = SmsUtil.jsonForObject(select.get(SupplierType.EMAY.getName()), EmayConfig.class);
|
||||
SupplierFactory.setEmayConfig(emayConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
* ctyun
|
||||
* <p>数据库读取并设置天翼云短信
|
||||
* @author :Wind
|
||||
*/
|
||||
public static void ctyun(){
|
||||
CtyunConfig ctyunConfig = SmsUtil.jsonForObject(select.get(SupplierType.CTYUN.getName()), CtyunConfig.class);
|
||||
SupplierFactory.setCtyunConfig(ctyunConfig);
|
||||
}
|
||||
}
|
||||
|
||||
@ -12,9 +12,12 @@ import org.dromara.sms4j.tencent.config.TencentConfig;
|
||||
import org.dromara.sms4j.unisms.config.UniConfig;
|
||||
import org.dromara.sms4j.yunpian.config.YunpianConfig;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* SupplierFactory
|
||||
* <p> 差异化配置工厂
|
||||
*
|
||||
* @author :Wind
|
||||
* 2023/4/8 15:02
|
||||
**/
|
||||
@ -22,25 +25,39 @@ public class SupplierFactory {
|
||||
private SupplierFactory() {
|
||||
}
|
||||
|
||||
/** 阿里云差异化配置*/
|
||||
/**
|
||||
* 阿里云差异化配置
|
||||
*/
|
||||
private static AlibabaConfig alibabaConfig;
|
||||
|
||||
/** 华为云差异化配置*/
|
||||
/**
|
||||
* 华为云差异化配置
|
||||
*/
|
||||
private static HuaweiConfig huaweiConfig;
|
||||
|
||||
/** 合一短信差异化配置*/
|
||||
/**
|
||||
* 合一短信差异化配置
|
||||
*/
|
||||
private static UniConfig uniConfig;
|
||||
|
||||
/** 腾讯云短信差异化配置*/
|
||||
/**
|
||||
* 腾讯云短信差异化配置
|
||||
*/
|
||||
private static TencentConfig tencentConfig;
|
||||
|
||||
/** 云片短信差异配置*/
|
||||
/**
|
||||
* 云片短信差异配置
|
||||
*/
|
||||
private static YunpianConfig yunpianConfig;
|
||||
|
||||
/** 京东云短信差异配置 */
|
||||
/**
|
||||
* 京东云短信差异配置
|
||||
*/
|
||||
private static JdCloudConfig jdCloudConfig;
|
||||
|
||||
/** 容联云短信差异配置 */
|
||||
/**
|
||||
* 容联云短信差异配置
|
||||
*/
|
||||
private static CloopenConfig cloopenConfig;
|
||||
|
||||
/**
|
||||
@ -53,57 +70,71 @@ public class SupplierFactory {
|
||||
*/
|
||||
private static CtyunConfig ctyunConfig;
|
||||
|
||||
/** 阿里云配置获取*/
|
||||
/**
|
||||
* 阿里云配置获取
|
||||
*/
|
||||
public static AlibabaConfig getAlibabaConfig() {
|
||||
if (alibabaConfig == null){
|
||||
if (alibabaConfig == null) {
|
||||
alibabaConfig = AlibabaConfig.builder().build();
|
||||
}
|
||||
return alibabaConfig;
|
||||
}
|
||||
|
||||
/** 华为云配置获取*/
|
||||
/**
|
||||
* 华为云配置获取
|
||||
*/
|
||||
public static HuaweiConfig getHuaweiConfig() {
|
||||
if (huaweiConfig == null){
|
||||
if (huaweiConfig == null) {
|
||||
huaweiConfig = HuaweiConfig.builder().build();
|
||||
}
|
||||
return huaweiConfig;
|
||||
}
|
||||
|
||||
/** 合一短信配置获取*/
|
||||
/**
|
||||
* 合一短信配置获取
|
||||
*/
|
||||
public static UniConfig getUniConfig() {
|
||||
if (uniConfig == null){
|
||||
if (uniConfig == null) {
|
||||
uniConfig = UniConfig.builder().build();
|
||||
}
|
||||
return uniConfig;
|
||||
}
|
||||
|
||||
/** 腾讯短信配置获取*/
|
||||
/**
|
||||
* 腾讯短信配置获取
|
||||
*/
|
||||
public static TencentConfig getTencentConfig() {
|
||||
if (tencentConfig == null){
|
||||
if (tencentConfig == null) {
|
||||
tencentConfig = TencentConfig.builder().build();
|
||||
}
|
||||
return tencentConfig;
|
||||
}
|
||||
|
||||
/** 云片短信配置获取*/
|
||||
/**
|
||||
* 云片短信配置获取
|
||||
*/
|
||||
public static YunpianConfig getYunpianConfig() {
|
||||
if (yunpianConfig == null){
|
||||
if (yunpianConfig == null) {
|
||||
yunpianConfig = YunpianConfig.builder().build();
|
||||
}
|
||||
return yunpianConfig;
|
||||
}
|
||||
|
||||
/** 京东云短信配置获取 */
|
||||
/**
|
||||
* 京东云短信配置获取
|
||||
*/
|
||||
public static JdCloudConfig getJdCloudConfig() {
|
||||
if (jdCloudConfig == null){
|
||||
if (jdCloudConfig == null) {
|
||||
jdCloudConfig = JdCloudConfig.builder().build();
|
||||
}
|
||||
return jdCloudConfig;
|
||||
}
|
||||
|
||||
/** 容联云短信配置获取 */
|
||||
/**
|
||||
* 容联云短信配置获取
|
||||
*/
|
||||
public static CloopenConfig getCloopenConfig() {
|
||||
if (cloopenConfig == null){
|
||||
if (cloopenConfig == null) {
|
||||
cloopenConfig = CloopenConfig.builder().build();
|
||||
}
|
||||
return cloopenConfig;
|
||||
@ -129,6 +160,26 @@ public class SupplierFactory {
|
||||
return ctyunConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* setSupplierConfig
|
||||
* <p>通用化set,用于设置
|
||||
* @param t 配置对象
|
||||
* @author :Wind
|
||||
*/
|
||||
public static <T> void setSupplierConfig(T t) {
|
||||
if (t instanceof AlibabaConfig) {
|
||||
setAlibabaConfig((AlibabaConfig) t);
|
||||
} else if (t instanceof HuaweiConfig) {
|
||||
setHuaweiConfig((HuaweiConfig) t);
|
||||
} else if (t instanceof UniConfig) {
|
||||
setUniConfig((UniConfig) t);
|
||||
} else if (t instanceof TencentConfig) {
|
||||
setTencentConfig((TencentConfig) t);
|
||||
} else if (t instanceof YunpianConfig) {
|
||||
setYunpianConfig((YunpianConfig) t);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置 alibabaConfig
|
||||
*/
|
||||
|
||||
@ -5,13 +5,14 @@ import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import org.dromara.sms4j.api.universal.SupplierConfig;
|
||||
import org.dromara.sms4j.comm.config.BaseConfig;
|
||||
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@ToString(callSuper = true)
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class AlibabaConfig extends BaseConfig {
|
||||
public class AlibabaConfig extends BaseConfig implements SupplierConfig {
|
||||
|
||||
/**
|
||||
* 模板变量名称
|
||||
|
||||
@ -5,6 +5,7 @@ import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import org.dromara.sms4j.api.universal.SupplierConfig;
|
||||
import org.dromara.sms4j.comm.config.BaseConfig;
|
||||
|
||||
/**
|
||||
@ -17,7 +18,7 @@ import org.dromara.sms4j.comm.config.BaseConfig;
|
||||
@SuperBuilder
|
||||
@ToString(callSuper = true)
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class CloopenConfig extends BaseConfig {
|
||||
public class CloopenConfig extends BaseConfig implements SupplierConfig {
|
||||
|
||||
/**
|
||||
* 应用 ID
|
||||
|
||||
@ -5,6 +5,7 @@ import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import org.dromara.sms4j.api.universal.SupplierConfig;
|
||||
import org.dromara.sms4j.comm.config.BaseConfig;
|
||||
|
||||
/**
|
||||
@ -18,7 +19,7 @@ import org.dromara.sms4j.comm.config.BaseConfig;
|
||||
@SuperBuilder
|
||||
@ToString(callSuper = true)
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class CtyunConfig extends BaseConfig {
|
||||
public class CtyunConfig extends BaseConfig implements SupplierConfig {
|
||||
|
||||
/**
|
||||
* 模板变量名称
|
||||
|
||||
@ -2,6 +2,7 @@ package org.dromara.sms4j.emay.config;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import org.dromara.sms4j.api.universal.SupplierConfig;
|
||||
|
||||
/**
|
||||
* @author Richard
|
||||
@ -9,7 +10,7 @@ import lombok.Data;
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
public class EmayConfig {
|
||||
public class EmayConfig implements SupplierConfig {
|
||||
/** appKey*/
|
||||
private String appId ;
|
||||
/** appSecret */
|
||||
|
||||
@ -2,10 +2,11 @@ package org.dromara.sms4j.huawei.config;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import org.dromara.sms4j.api.universal.SupplierConfig;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
public class HuaweiConfig {
|
||||
public class HuaweiConfig implements SupplierConfig {
|
||||
|
||||
/** appKey*/
|
||||
private String appKey ;
|
||||
|
||||
@ -5,6 +5,7 @@ import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import org.dromara.sms4j.api.universal.SupplierConfig;
|
||||
import org.dromara.sms4j.comm.config.BaseConfig;
|
||||
|
||||
/**
|
||||
@ -17,7 +18,7 @@ import org.dromara.sms4j.comm.config.BaseConfig;
|
||||
@SuperBuilder
|
||||
@ToString(callSuper = true)
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class JdCloudConfig extends BaseConfig {
|
||||
public class JdCloudConfig extends BaseConfig implements SupplierConfig {
|
||||
|
||||
/**
|
||||
* 地域信息
|
||||
|
||||
@ -5,13 +5,14 @@ import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import org.dromara.sms4j.api.universal.SupplierConfig;
|
||||
import org.dromara.sms4j.comm.config.BaseConfig;
|
||||
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@ToString(callSuper = true)
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class TencentConfig extends BaseConfig {
|
||||
public class TencentConfig extends BaseConfig implements SupplierConfig {
|
||||
|
||||
/**
|
||||
* 短信sdkAppId
|
||||
|
||||
@ -5,13 +5,14 @@ import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import org.dromara.sms4j.api.universal.SupplierConfig;
|
||||
import org.dromara.sms4j.comm.config.BaseConfig;
|
||||
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@ToString(callSuper = true)
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class UniConfig extends BaseConfig {
|
||||
public class UniConfig extends BaseConfig implements SupplierConfig {
|
||||
|
||||
/**
|
||||
* 是否为简易模式
|
||||
|
||||
@ -5,12 +5,13 @@ import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import org.dromara.sms4j.api.universal.SupplierConfig;
|
||||
import org.dromara.sms4j.comm.config.BaseConfig;
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@ToString(callSuper = true)
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class YunpianConfig extends BaseConfig {
|
||||
public class YunpianConfig extends BaseConfig implements SupplierConfig {
|
||||
|
||||
/**
|
||||
* 短信发送后将向这个地址推送(运营商返回的)发送报告
|
||||
|
||||
@ -14,9 +14,23 @@ public class RedisUtils {
|
||||
private RedissonClient redisTemplate;
|
||||
|
||||
public RedisUtils() {
|
||||
Solon.context().getBeanAsync(RedissonClient.class, bean -> {
|
||||
redisTemplate = bean;
|
||||
Thread t = new Thread(()->{
|
||||
//如果获取到的bean为null则等待后重试,最多重试五次
|
||||
for(int i = 0; i < 5 ;i++){
|
||||
RedissonClient bean = Solon.context().getBean(RedissonClient.class);
|
||||
if (Objects.isNull(bean)){
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}else{
|
||||
redisTemplate = bean;
|
||||
return;
|
||||
}
|
||||
}
|
||||
});
|
||||
t.start();
|
||||
}
|
||||
|
||||
public RedisUtils(RedissonClient redisTemplate) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user