parent
ca3692e5fe
commit
73a3d34ddc
@ -0,0 +1,13 @@
|
|||||||
|
package com.xxl.job.executor;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
public class Application {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(Application.class, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,58 @@
|
|||||||
|
package com.xxl.job.executor.core.config;
|
||||||
|
|
||||||
|
import com.xxl.job.core.executor.XxlJobExecutor;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* xxl-job config
|
||||||
|
*
|
||||||
|
* @author xuxueli 2017-04-28
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
@ComponentScan(basePackages = "com.xxl.job.executor.service.jobhandler")
|
||||||
|
public class XxlJobConfig {
|
||||||
|
private Logger logger = LoggerFactory.getLogger(XxlJobConfig.class);
|
||||||
|
|
||||||
|
@Value("${xxl.job.admin.addresses}")
|
||||||
|
private String adminAddresses;
|
||||||
|
|
||||||
|
@Value("${xxl.job.executor.appname}")
|
||||||
|
private String appName;
|
||||||
|
|
||||||
|
@Value("${xxl.job.executor.ip}")
|
||||||
|
private String ip;
|
||||||
|
|
||||||
|
@Value("${xxl.job.executor.port}")
|
||||||
|
private int port;
|
||||||
|
|
||||||
|
@Value("${xxl.job.accessToken}")
|
||||||
|
private String accessToken;
|
||||||
|
|
||||||
|
@Value("${xxl.job.executor.logpath}")
|
||||||
|
private String logPath;
|
||||||
|
|
||||||
|
@Value("${xxl.job.executor.logretentiondays}")
|
||||||
|
private int logRetentionDays;
|
||||||
|
|
||||||
|
|
||||||
|
@Bean(initMethod = "start", destroyMethod = "destroy")
|
||||||
|
public XxlJobExecutor xxlJobExecutor() {
|
||||||
|
logger.info(">>>>>>>>>>> xxl-job config init.");
|
||||||
|
XxlJobExecutor xxlJobExecutor = new XxlJobExecutor();
|
||||||
|
xxlJobExecutor.setAdminAddresses(adminAddresses);
|
||||||
|
xxlJobExecutor.setAppName(appName);
|
||||||
|
xxlJobExecutor.setIp(ip);
|
||||||
|
xxlJobExecutor.setPort(port);
|
||||||
|
xxlJobExecutor.setAccessToken(accessToken);
|
||||||
|
xxlJobExecutor.setLogPath(logPath);
|
||||||
|
xxlJobExecutor.setLogRetentionDays(logRetentionDays);
|
||||||
|
|
||||||
|
return xxlJobExecutor;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
//package com.xxl.job.executor.mvc.controller;
|
||||||
|
//
|
||||||
|
//import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||||
|
//import org.springframework.stereotype.Controller;
|
||||||
|
//import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
//import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
|
//
|
||||||
|
//@Controller
|
||||||
|
//@EnableAutoConfiguration
|
||||||
|
//public class IndexController {
|
||||||
|
//
|
||||||
|
// @RequestMapping("/")
|
||||||
|
// @ResponseBody
|
||||||
|
// String index() {
|
||||||
|
// return "xxl job executor running.";
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//}
|
@ -0,0 +1,39 @@
|
|||||||
|
package com.xxl.job.executor.service.jobhandler;
|
||||||
|
|
||||||
|
import com.xxl.job.core.biz.model.ReturnT;
|
||||||
|
import com.xxl.job.core.handler.IJobHandler;
|
||||||
|
import com.xxl.job.core.handler.annotation.JobHandler;
|
||||||
|
import com.xxl.job.core.log.XxlJobLogger;
|
||||||
|
import com.xxl.job.core.util.ShardingUtil;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分片广播任务
|
||||||
|
*
|
||||||
|
* @author xuxueli 2017-07-25 20:56:50
|
||||||
|
*/
|
||||||
|
@JobHandler(value="shardingJobHandler")
|
||||||
|
@Service
|
||||||
|
public class ShardingJobHandler extends IJobHandler {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ReturnT<String> execute(String param) throws Exception {
|
||||||
|
|
||||||
|
// 分片参数
|
||||||
|
ShardingUtil.ShardingVO shardingVO = ShardingUtil.getShardingVo();
|
||||||
|
XxlJobLogger.log("分片参数:当前分片序号 = {0}, 总分片数 = {1}", shardingVO.getIndex(), shardingVO.getTotal());
|
||||||
|
|
||||||
|
// 业务逻辑
|
||||||
|
for (int i = 0; i < shardingVO.getTotal(); i++) {
|
||||||
|
if (i == shardingVO.getIndex()) {
|
||||||
|
XxlJobLogger.log("第 {0} 片, 命中分片开始处理", i);
|
||||||
|
} else {
|
||||||
|
XxlJobLogger.log("第 {0} 片, 忽略", i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
# web port
|
||||||
|
server.port=9001
|
||||||
|
|
||||||
|
# log config
|
||||||
|
logging.config=classpath:logback.xml
|
||||||
|
|
||||||
|
|
||||||
|
### xxl-job admin address list, such as "http://address" or "http://address01,http://address02"
|
||||||
|
xxl.job.admin.addresses=http://127.0.0.1:8090
|
||||||
|
#xxl.job.admin.addresses=http://dispatch-center.infincash.com
|
||||||
|
|
||||||
|
### xxl-job executor address
|
||||||
|
xxl.job.executor.appname=executor-001
|
||||||
|
xxl.job.executor.ip=
|
||||||
|
xxl.job.executor.port=9002
|
||||||
|
|
||||||
|
### xxl-job, access token
|
||||||
|
xxl.job.accessToken=
|
||||||
|
|
||||||
|
### xxl-job log path
|
||||||
|
xxl.job.executor.logpath=/data/applogs/xxl-job/jobhandler
|
||||||
|
### xxl-job log retention days
|
||||||
|
xxl.job.executor.logretentiondays=-1
|
@ -0,0 +1,37 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<configuration debug="false" scan="true" scanPeriod="1 seconds">
|
||||||
|
|
||||||
|
<contextName>logback</contextName>
|
||||||
|
<property name="log.path" value="/data/applogs/xxl-job/xxl-job-executor-sample-springboot.log"/>
|
||||||
|
|
||||||
|
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
|
<!-- <filter class="ch.qos.logback.classic.filter.ThresholdFilter" >
|
||||||
|
<level>WARN</level>
|
||||||
|
</filter>-->
|
||||||
|
<encoder>
|
||||||
|
<pattern>%d{HH:mm:ss.SSS} %contextName [%thread] %-5level %logger{36} - %msg%n</pattern>
|
||||||
|
</encoder>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<appender name="file" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||||
|
<file>${log.path}</file>
|
||||||
|
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||||
|
<fileNamePattern>${log.path}.%d{yyyy-MM-dd}.zip</fileNamePattern>
|
||||||
|
</rollingPolicy>
|
||||||
|
<encoder>
|
||||||
|
<pattern>%date %level [%thread] %logger{36} [%file : %line] %msg%n
|
||||||
|
</pattern>
|
||||||
|
</encoder>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<root level="info">
|
||||||
|
<appender-ref ref="console"/>
|
||||||
|
<appender-ref ref="file"/>
|
||||||
|
</root>
|
||||||
|
|
||||||
|
<!--<logger name="com.xxl.job.executor.service.info" level="WARN" additivity="false">
|
||||||
|
<appender-ref ref="console"/>
|
||||||
|
<appender-ref ref="file"/>
|
||||||
|
</logger>-->
|
||||||
|
|
||||||
|
</configuration>
|
@ -0,0 +1,24 @@
|
|||||||
|
package com.xxl.job.executor.test;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
|
import com.xxl.job.executor.Application;
|
||||||
|
import com.xxl.job.executor.service.jobhandler.RiskCountStatisticsJobHandler;
|
||||||
|
|
||||||
|
@RunWith(SpringRunner.class)
|
||||||
|
@SpringBootTest(classes = Application.class ,webEnvironment= SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||||
|
public class XxlJobExecutorExampleBootApplicationTests {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
RiskCountStatisticsJobHandler jobHandler;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test() throws Exception {
|
||||||
|
jobHandler.execute("");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in new issue