https://github.com/xuxueli/xxl-job 下载,以2.0.2版本为例,无quartz版本
* 拷入xxl-job-admin ,xxl-job-core两个工程;
* 重命名工程,示例:xxl-job-admin改为dubbo-nacos-job-admin, xxl-job-core改为dubbo-nacos-job-common;
* 修改dubbo-nacos-job-common pom.xml,添加所需要的jar包,及指定xxl-job-rcp jar版本;
* 修改dubbo-nacos-job-admin pom.xml,添加所需要的jar包;
* 修改xxl-job表结构及初始化示例表数据
修改xxl_job_info表:
添加字段:
`executor_dubbo_method` varchar(20) DEFAULT NULL COMMENT 'dubbo服务调用方法名',
`executor_dubbo_version` varchar(8) DEFAULT NULL COMMENT 'dubbo服务版本号',
* 整改dubbo-nacos-job-common工程;
com.xxl.job.core.glue.GlueTypeEnum.java
添加枚举:
DUBBO("DUBBO", false, null, null),
com.xxl.job.core.executor.XxlJobExecutor.java
添加方法,在initAdminBizList方法前面:
public static IJobHandler loadDubboJobHandler(String address, TriggerParam triggerParam){
String cacheKey = triggerParam.getExecutorHandler() + "." + triggerParam.getDubboMethod() + "." + triggerParam.getDubboVersion();
if(jobHandlerRepository.containsKey(cacheKey)){
return jobHandlerRepository.get(cacheKey);
}
IJobHandler jobHandler = new DubboJobHandler(address , triggerParam);
jobHandlerRepository.put(cacheKey, jobHandler);
return jobHandler;
}
com.xxl.job.core.biz.model.TriggerParam.java
添加属性:
private String executorDubboMethod;
private String executorDubboVersion;
com.xxl.job.core.handler.impl包下添加类
新建类:com.xxl.job.core.handler.impl.DubboJobHandler.java
com.xxl.job.core.biz.impl.ExecutorBizImpl.java
添加属性:
/* dubbo nacos address , example=nacos://127.0.0.1:8848 */
private String address = "";
添加两个构架方法:
public ExecutorBizImpl() {
}
public ExecutorBizImpl(String address) {
this.address = address;
}
添加逻辑,com.xxl.job.core.biz.impl.ExecutorBizImpl#run方法里面,添加Dubbo的执行路由:
if (GlueTypeEnum.DUBBO == glueTypeEnum) {
jobHandler = XxlJobExecutor.loadDubboJobHandler(address, triggerParam);
if (logger.isDebugEnabled()) {
logger.debug("# jobHandler.hashCode()={}", jobHandler.hashCode());
}
} else if (GlueTypeEnum.BEAN == glueTypeEnum) {
com.xxl.job.core.log.XxlJobFileAppender.java
修改日志输出保存路径:
private static String logBasePath = "/Users/vincent/logs/jobhandler";
* 整改dubbo-nacos-job-admin工程 ;
com.xxl.job.admin.core.model.XxlJobInfo.java
添加属性:
private String executorDubboMethod; // 执行器,dubbo服务调用方法名
private String executorDubboVersion; // 执行器,dubbo服务版本号
src/main/resources/mybatis-mapper/XxlJobInfoMapper.xml
映射相关字段:
executor_dubbo_method —> executorDubboMethod
executor_dubbo_version —> executorDubboVersion
com.xxl.job.admin.core.conf.XxlJobScheduler.java
添加方法:
/**
* 创建dubbo执行器
* @param address
* @return ExecutorBiz
* @throws Exception
*/
public static ExecutorBiz getDubboEecutorBiz(String address) throws Exception {
// valid
if (address == null || address.trim().length() == 0) {
return null;
}
// load-cache
address = address.trim();
// String key = "zk.address." + address;
String key = "nacos.address." + address;
ExecutorBiz executorBiz = executorBizRepository.get(key);
if (executorBiz != null) {
return executorBiz;
}
executorBiz = new ExecutorBizImpl(address);
if (logger.isDebugEnabled()) {
logger.debug("# key={}, address={}", key, address);
}
executorBizRepository.put(key, executorBiz);
return executorBiz;
}
com.xxl.job.admin.core.trigger.XxlJobTrigger.java
修改方法逻辑,com.xxl.job.admin.core.trigger.XxlJobTrigger#processTrigger方法
添加executetorDubboMethod,executorDubboVersion传值映射
triggerParam.setExecutorDubboMethod(jobInfo.getExecutorDubboMethod());
triggerParam.setExecutorDubboVersion(jobInfo.getExecutorDubboVersion());
修改方法逻辑,com.xxl.job.admin.core.trigger.XxlJobTrigger#runExecutor方法 ,添加dubbo路由判断
GlueTypeEnum glueTypeEnum = GlueTypeEnum.match(triggerParam.getGlueType());
try {
ExecutorBiz executorBiz = null;
if (GlueTypeEnum.DUBBO == glueTypeEnum) {
executorBiz = XxlJobScheduler.getDubboEecutorBiz(address);
} else {
executorBiz = XxlJobScheduler.getExecutorBiz(address);
}
runResult = executorBiz.run(triggerParam);
} catch (Exception e) {
logger.error(">>>>>>>>>>> xxl-job trigger error, please check if the executor[{}] is running.", address, e);
runResult = new ReturnT
}
com.xxl.job.admin.core.thread.JobRegistryMonitorHelper.java
添加update xxl_job_group表的判断逻辑,大概是在78行左右
//group.setAddressList(addressListStr);
if (StringUtils.isNotBlank(addressListStr)) {
group.setAddressList(addressListStr);
}
com.xxl.job.admin.XxlJobAdminApplication.java
添加注解:
@EnableDubbo
dubbo-nacos-xxl-job-admin/src/main/resources/application.properties
添加与修改属性:
### spring main
spring.main.allow-bean-definition-overriding=true
spring.main.application.name=dubbo-nacos-job
### datasource
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/test?Unicode=true&characterEncoding=UTF-8
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
spring.datasource.hikari.connection-init-sql=set names utf8mb4
spring.datasource.druid.initial-size=8
spring.datasource.druid.min-idle=1
spring.datasource.druid.max-active=20
spring.datasource.druid.max-wait=60000
spring.datasource.druid.time-between-eviction-runsMillis=60000
spring.datasource.druid.min-evictable-idle-timeMillis=300000
spring.datasource.druid.validation-query=select 1 FROM DUAL
spring.datasource.druid.test-while-idle=true
spring.datasource.druid.test-on-borrow=false
spring.datasource.druid.test-on-return=false
spring.datasource.druid.pool-prepared-statements=true
spring.datasource.druid.max-open-prepared-statements=20
spring.datasource.druid.max-pool-prepared-statement-per-connection-size=20
spring.datasource.druid.filters=stat
spring.datasource.druid.connection-properties=druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
spring.datasource.druid.use-global-data-source-stat=true
### dubbo
dubbo.application.id=dubbo-nacos-xxl-job-admin
dubbo.application.name=dubbo-nacos-xxl-job-admin
dubbo.protocol.id = dubbo
dubbo.protocol.name = dubbo
dubbo.protocol.port = 20880
#dubbo.protocol.port=-1
dubbo.scan=com
dubbo.reference.check=false
dubbo.consumer.check=false
dubbo.consumer.timeout=30000
dubbo.registry.id=dubbo-nacos-provider
dubbo.registry.address=nacos://127.0.0.1:8848
src/main/resources/static/js/jobinfo.index.1.js
修改方法逻辑,添加对dubbo支持,大概425行,改为如下:
// glueType change
$(".glueType").change(function(){
// executorHandler
var $executorHandler = $(this).parents("form").find("input[name='executorHandler']");
var $dubboDiv = $(this).parents("form").find("div[name='dubboDiv']");
var glueType = $(this).val();
if ('BEAN' != glueType && 'DUBBO' != glueType) {
$executorHandler.val("");
$executorHandler.attr("readonly","readonly");
$dubboDiv.hide();
} else {
$executorHandler.removeAttr("readonly");
if('BEAN' == glueType){
$dubboDiv.hide();
}else{
$dubboDiv.show();
}
}
});
修改代码添加,添加对dubbo支持,大概481行,改为如下:
$("#updateModal .form input[name='executorDubboMethod']").val( row.executorDubboMethod );
$("#updateModal .form input[name='executorDubboVersion']").val(row.executorDubboVersion);
src/main/resources/templates/jobinfo/jobinfo.index.ftl
添加dubbo支持,新增代码块修改:
添加dubbo支持,编码方法代码块:
com.xxl.job.admin.core.thread.JobRegistryMonitorHelper.java
添加判断逻辑:
//group.setAddressList(addressListStr);
if (StringUtils.isNotBlank(addressListStr)) {
group.setAddressList(addressListStr);
}
com.xxl.job.admin.service.impl.XxlJobServiceImpl.java
添加字段映射关系,com.xxl.job.admin.service.impl.XxlJobServiceImpl#update
exists_jobInfo.setExecutorDubboMethod(jobInfo.getExecutorDubboMethod());
exists_jobInfo.setExecutorDubboVersion(jobInfo.getExecutorDubboVersion());
具体源码:https://github.com/wangxinforme/dubbo-nacos