|
|
@ -1,14 +1,21 @@
|
|
|
|
package com.ruoyi.common.job.config;
|
|
|
|
package com.ruoyi.common.job.config;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
|
|
|
import com.ruoyi.common.core.utils.StreamUtils;
|
|
|
|
import com.ruoyi.common.job.config.properties.XxlJobProperties;
|
|
|
|
import com.ruoyi.common.job.config.properties.XxlJobProperties;
|
|
|
|
import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
|
|
|
|
import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
|
|
|
|
import lombok.AllArgsConstructor;
|
|
|
|
import lombok.AllArgsConstructor;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
|
|
|
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
|
|
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
|
|
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
|
|
|
|
|
|
|
import org.springframework.cloud.client.ServiceInstance;
|
|
|
|
|
|
|
|
import org.springframework.cloud.client.discovery.DiscoveryClient;
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* xxl-job config
|
|
|
|
* xxl-job config
|
|
|
|
*
|
|
|
|
*
|
|
|
@ -23,11 +30,23 @@ public class XxlJobConfig {
|
|
|
|
|
|
|
|
|
|
|
|
private final XxlJobProperties xxlJobProperties;
|
|
|
|
private final XxlJobProperties xxlJobProperties;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final DiscoveryClient discoveryClient;
|
|
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
@Bean
|
|
|
|
public XxlJobSpringExecutor xxlJobExecutor() {
|
|
|
|
public XxlJobSpringExecutor xxlJobExecutor() {
|
|
|
|
log.info(">>>>>>>>>>> xxl-job config init.");
|
|
|
|
log.info(">>>>>>>>>>> xxl-job config init.");
|
|
|
|
XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
|
|
|
|
XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
|
|
|
|
xxlJobSpringExecutor.setAdminAddresses(xxlJobProperties.getAdminAddresses());
|
|
|
|
if (StringUtils.isNotBlank(xxlJobProperties.getAdminAppname())) {
|
|
|
|
|
|
|
|
List<ServiceInstance> instances = discoveryClient.getInstances(xxlJobProperties.getAdminAppname());
|
|
|
|
|
|
|
|
if (CollUtil.isEmpty(instances)) {
|
|
|
|
|
|
|
|
throw new RuntimeException("调度中心不存在!");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
String serverList = StreamUtils.join(instances, instance ->
|
|
|
|
|
|
|
|
String.format("http://%s:%s", instance.getHost(), instance.getPort()));
|
|
|
|
|
|
|
|
xxlJobSpringExecutor.setAdminAddresses(serverList);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
xxlJobSpringExecutor.setAdminAddresses(xxlJobProperties.getAdminAddresses());
|
|
|
|
|
|
|
|
}
|
|
|
|
xxlJobSpringExecutor.setAccessToken(xxlJobProperties.getAccessToken());
|
|
|
|
xxlJobSpringExecutor.setAccessToken(xxlJobProperties.getAccessToken());
|
|
|
|
XxlJobProperties.Executor executor = xxlJobProperties.getExecutor();
|
|
|
|
XxlJobProperties.Executor executor = xxlJobProperties.getExecutor();
|
|
|
|
xxlJobSpringExecutor.setAppname(executor.getAppname());
|
|
|
|
xxlJobSpringExecutor.setAppname(executor.getAppname());
|
|
|
|