|
@@ -7,6 +7,7 @@ import com.shkpr.service.bespokegateway.core.domain.CallingEndpoint;
|
|
|
import com.shkpr.service.bespokegateway.core.domain.IntegrationKey;
|
|
import com.shkpr.service.bespokegateway.core.domain.IntegrationKey;
|
|
|
import com.shkpr.service.bespokegateway.core.domain.IntegrationKeyLoader;
|
|
import com.shkpr.service.bespokegateway.core.domain.IntegrationKeyLoader;
|
|
|
import com.shkpr.service.bespokegateway.core.properties.CallingProperties;
|
|
import com.shkpr.service.bespokegateway.core.properties.CallingProperties;
|
|
|
|
|
+import com.shkpr.service.bespokegateway.core.properties.SchedulingProperties;
|
|
|
import org.apache.commons.collections4.MapUtils;
|
|
import org.apache.commons.collections4.MapUtils;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
|
@@ -26,12 +27,18 @@ import java.util.concurrent.ConcurrentHashMap;
|
|
|
@Component
|
|
@Component
|
|
|
public class IntegrationKeyManager {
|
|
public class IntegrationKeyManager {
|
|
|
/**
|
|
/**
|
|
|
|
|
+ * 刷新密钥任务
|
|
|
|
|
+ */
|
|
|
|
|
+ private static final String REFRESH_ALL_KEYS_SCHEDULING = "refresh-all-keys";
|
|
|
|
|
+ /**
|
|
|
* log
|
|
* log
|
|
|
*/
|
|
*/
|
|
|
private static final String CLASS_NAME = "IntegrationKeyManager";
|
|
private static final String CLASS_NAME = "IntegrationKeyManager";
|
|
|
private static final String BIZ_TYPE = LogFlagBusiType.BUSI_ALL.toStrValue();
|
|
private static final String BIZ_TYPE = LogFlagBusiType.BUSI_ALL.toStrValue();
|
|
|
|
|
|
|
|
final
|
|
final
|
|
|
|
|
+ SchedulingProperties schedulingProperties;
|
|
|
|
|
+ final
|
|
|
ThreadPoolTaskExecutor taskScheduler;
|
|
ThreadPoolTaskExecutor taskScheduler;
|
|
|
final
|
|
final
|
|
|
CallingProperties callingProperties;
|
|
CallingProperties callingProperties;
|
|
@@ -41,7 +48,8 @@ public class IntegrationKeyManager {
|
|
|
//密钥缓存
|
|
//密钥缓存
|
|
|
private final Map<String, IntegrationKey> keyCache = new ConcurrentHashMap<>();
|
|
private final Map<String, IntegrationKey> keyCache = new ConcurrentHashMap<>();
|
|
|
|
|
|
|
|
- public IntegrationKeyManager(ThreadPoolTaskExecutor taskScheduler, CallingProperties callingProperties, List<IntegrationKeyLoader> loaders) {
|
|
|
|
|
|
|
+ public IntegrationKeyManager(SchedulingProperties schedulingProperties, ThreadPoolTaskExecutor taskScheduler, CallingProperties callingProperties, List<IntegrationKeyLoader> loaders) {
|
|
|
|
|
+ this.schedulingProperties = schedulingProperties;
|
|
|
this.taskScheduler = taskScheduler;
|
|
this.taskScheduler = taskScheduler;
|
|
|
this.callingProperties = callingProperties;
|
|
this.callingProperties = callingProperties;
|
|
|
// 注册所有密钥加载器
|
|
// 注册所有密钥加载器
|
|
@@ -53,7 +61,8 @@ public class IntegrationKeyManager {
|
|
|
*/
|
|
*/
|
|
|
@PostConstruct
|
|
@PostConstruct
|
|
|
public void init() {
|
|
public void init() {
|
|
|
- taskScheduler.execute(this::refreshAllKeys);
|
|
|
|
|
|
|
+ if (schedulingProperties.isTaskActive(REFRESH_ALL_KEYS_SCHEDULING))
|
|
|
|
|
+ taskScheduler.execute(this::refreshAllKeys);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -61,7 +70,8 @@ public class IntegrationKeyManager {
|
|
|
*/
|
|
*/
|
|
|
@Scheduled(cron = "0 0 0 * * ?")
|
|
@Scheduled(cron = "0 0 0 * * ?")
|
|
|
public void minuteTask() {
|
|
public void minuteTask() {
|
|
|
- taskScheduler.execute(this::refreshAllKeys);
|
|
|
|
|
|
|
+ if (schedulingProperties.isTaskActive(REFRESH_ALL_KEYS_SCHEDULING))
|
|
|
|
|
+ taskScheduler.execute(this::refreshAllKeys);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|