Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
X
XXL-JOB
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
靳帅
XXL-JOB
Commits
67604587
提交
67604587
authored
12月 04, 2020
作者:
xueli.xue
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
sample upgrade
上级
437c4e14
隐藏空白字符变更
内嵌
并排
正在显示
11 个修改的文件
包含
2 行增加
和
485 行删除
+2
-485
XXL-JOB官方文档.md
doc/XXL-JOB官方文档.md
+1
-2
pom.xml
pom.xml
+1
-1
pom.xml
xxl-job-executor-samples/pom.xml
+0
-2
pom.xml
...b-executor-samples/xxl-job-executor-sample-spring/pom.xml
+0
-60
SampleXxlJob.java
...com/xxl/job/executor/service/jobhandler/SampleXxlJob.java
+0
-253
applicationcontext-xxl-job.xml
...-spring/src/main/resources/applicationcontext-xxl-job.xml
+0
-45
log4j.xml
...l-job-executor-sample-spring/src/main/resources/log4j.xml
+0
-34
logback.xml
...job-executor-sample-spring/src/main/resources/logback.xml
+0
-30
xxl-job-executor.properties
...ple-spring/src/main/resources/xxl-job-executor.properties
+0
-18
web.xml
...ob-executor-sample-spring/src/main/webapp/WEB-INF/web.xml
+0
-38
index.html
...xxl-job-executor-sample-spring/src/main/webapp/index.html
+0
-2
没有找到文件。
doc/XXL-JOB官方文档.md
浏览文件 @
67604587
...
...
@@ -559,7 +559,6 @@ XXL-JOB是一个分布式任务调度平台,其核心设计目标是开发迅
xxl-job-core:公共依赖
xxl-job-executor-samples:执行器Sample示例(选择合适的版本执行器,可直接使用,也可以参考其并将现有项目改造成执行器)
:xxl-job-executor-sample-springboot:Springboot版本,通过Springboot管理执行器,推荐这种方式;
:xxl-job-executor-sample-spring:Spring版本,通过Spring容器管理执行器,比较通用;
:xxl-job-executor-sample-frameless:无框架版本;
...
...
@@ -714,7 +713,7 @@ public XxlJobSpringExecutor xxlJobExecutor() {
如果已经正确进行上述配置,可将执行器项目编译打部署,系统提供多种执行器Sample示例项目,选择其中一个即可,各自的部署方式如下。
xxl-job-executor-sample-springboot:项目编译打包成springboot类型的可执行JAR包,命令启动即可;
xxl-job-executor-sample-
spring:项目编译打包成WAR包,并部署到tomcat中。
xxl-job-executor-sample-
frameless:项目编译打包成JAR包,命令启动即可;
至此“执行器”项目已经部署结束。
...
...
pom.xml
浏览文件 @
67604587
...
...
@@ -24,7 +24,7 @@
<maven.compiler.target>
1.8
</maven.compiler.target>
<maven.test.skip>
true
</maven.test.skip>
<netty-all.version>
4.1.5
3
.Final
</netty-all.version>
<netty-all.version>
4.1.5
4
.Final
</netty-all.version>
<gson.version>
2.8.6
</gson.version>
<spring.version>
5.2.9.RELEASE
</spring.version>
...
...
xxl-job-executor-samples/pom.xml
浏览文件 @
67604587
...
...
@@ -13,7 +13,6 @@
<modules>
<module>
xxl-job-executor-sample-frameless
</module>
<module>
xxl-job-executor-sample-springboot
</module>
<module>
xxl-job-executor-sample-spring
</module>
</modules>
</project>
\ No newline at end of file
xxl-job-executor-samples/xxl-job-executor-sample-spring/pom.xml
deleted
100644 → 0
浏览文件 @
437c4e14
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<parent>
<groupId>
com.xuxueli
</groupId>
<artifactId>
xxl-job-executor-samples
</artifactId>
<version>
2.3.0-SNAPSHOT
</version>
</parent>
<artifactId>
xxl-job-executor-sample-spring
</artifactId>
<packaging>
war
</packaging>
<name>
${project.artifactId}
</name>
<description>
Executor project for spring boot.
</description>
<url>
https://www.xuxueli.com/
</url>
<dependencies>
<!-- spring-webmvc -->
<dependency>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-webmvc
</artifactId>
<version>
${spring.version}
</version>
</dependency>
<!-- Logback -->
<dependency>
<groupId>
org.logback-extensions
</groupId>
<artifactId>
logback-ext-spring
</artifactId>
<version>
0.1.4
</version>
</dependency>
<dependency>
<groupId>
org.slf4j
</groupId>
<artifactId>
jcl-over-slf4j
</artifactId>
<version>
1.7.25
</version>
</dependency>
<!-- xxl-job-core -->
<dependency>
<groupId>
com.xuxueli
</groupId>
<artifactId>
xxl-job-core
</artifactId>
<version>
${project.parent.version}
</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-war-plugin
</artifactId>
<version>
${maven-war-plugin.version}
</version>
<configuration>
<archiveClasses>
false
</archiveClasses>
</configuration>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
xxl-job-executor-samples/xxl-job-executor-sample-spring/src/main/java/com/xxl/job/executor/service/jobhandler/SampleXxlJob.java
deleted
100644 → 0
浏览文件 @
437c4e14
package
com
.
xxl
.
job
.
executor
.
service
.
jobhandler
;
import
com.xxl.job.core.context.XxlJobHelper
;
import
com.xxl.job.core.handler.annotation.XxlJob
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.stereotype.Component
;
import
java.io.BufferedInputStream
;
import
java.io.BufferedReader
;
import
java.io.DataOutputStream
;
import
java.io.InputStreamReader
;
import
java.net.HttpURLConnection
;
import
java.net.URL
;
import
java.util.Arrays
;
import
java.util.concurrent.TimeUnit
;
/**
* XxlJob开发示例(Bean模式)
*
* 开发步骤:
* 1、任务开发:在Spring Bean实例中,开发Job方法;
* 2、注解配置:为Job方法添加注解 "@XxlJob(value="自定义jobhandler名称", init = "JobHandler初始化方法", destroy = "JobHandler销毁方法")",注解value值对应的是调度中心新建任务的JobHandler属性的值。
* 3、执行日志:需要通过 "XxlJobHelper.log" 打印执行日志;
* 4、任务结果:默认任务结果为 "成功" 状态,不需要主动设置;如有诉求,比如设置任务结果为失败,可以通过 "XxlJobHelper.handleFail/handleSuccess" 自主设置任务结果;
*
* @author xuxueli 2019-12-11 21:52:51
*/
@Component
public
class
SampleXxlJob
{
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
SampleXxlJob
.
class
);
/**
* 1、简单任务示例(Bean模式)
*/
@XxlJob
(
"demoJobHandler"
)
public
void
demoJobHandler
()
throws
Exception
{
XxlJobHelper
.
log
(
"XXL-JOB, Hello World."
);
for
(
int
i
=
0
;
i
<
5
;
i
++)
{
XxlJobHelper
.
log
(
"beat at:"
+
i
);
TimeUnit
.
SECONDS
.
sleep
(
2
);
}
// default success
}
/**
* 2、分片广播任务
*/
@XxlJob
(
"shardingJobHandler"
)
public
void
shardingJobHandler
()
throws
Exception
{
// 分片参数
int
shardIndex
=
XxlJobHelper
.
getShardIndex
();
int
shardTotal
=
XxlJobHelper
.
getShardTotal
();
XxlJobHelper
.
log
(
"分片参数:当前分片序号 = {}, 总分片数 = {}"
,
shardIndex
,
shardTotal
);
// 业务逻辑
for
(
int
i
=
0
;
i
<
shardTotal
;
i
++)
{
if
(
i
==
shardIndex
)
{
XxlJobHelper
.
log
(
"第 {} 片, 命中分片开始处理"
,
i
);
}
else
{
XxlJobHelper
.
log
(
"第 {} 片, 忽略"
,
i
);
}
}
}
/**
* 3、命令行任务
*/
@XxlJob
(
"commandJobHandler"
)
public
void
commandJobHandler
()
throws
Exception
{
String
command
=
XxlJobHelper
.
getJobParam
();
int
exitValue
=
-
1
;
BufferedReader
bufferedReader
=
null
;
try
{
// command process
ProcessBuilder
processBuilder
=
new
ProcessBuilder
();
processBuilder
.
command
(
command
);
processBuilder
.
redirectErrorStream
(
true
);
Process
process
=
processBuilder
.
start
();
//Process process = Runtime.getRuntime().exec(command);
BufferedInputStream
bufferedInputStream
=
new
BufferedInputStream
(
process
.
getInputStream
());
bufferedReader
=
new
BufferedReader
(
new
InputStreamReader
(
bufferedInputStream
));
// command log
String
line
;
while
((
line
=
bufferedReader
.
readLine
())
!=
null
)
{
XxlJobHelper
.
log
(
line
);
}
// command exit
process
.
waitFor
();
exitValue
=
process
.
exitValue
();
}
catch
(
Exception
e
)
{
XxlJobHelper
.
log
(
e
);
}
finally
{
if
(
bufferedReader
!=
null
)
{
bufferedReader
.
close
();
}
}
if
(
exitValue
==
0
)
{
// default success
}
else
{
XxlJobHelper
.
handleFail
(
"command exit value("
+
exitValue
+
") is failed"
);
}
}
/**
* 4、跨平台Http任务
* 参数示例:
* "url: http://www.baidu.com\n" +
* "method: get\n" +
* "data: content\n";
*/
@XxlJob
(
"httpJobHandler"
)
public
void
httpJobHandler
()
throws
Exception
{
// param parse
String
param
=
XxlJobHelper
.
getJobParam
();
if
(
param
==
null
||
param
.
trim
().
length
()==
0
)
{
XxlJobHelper
.
log
(
"param["
+
param
+
"] invalid."
);
XxlJobHelper
.
handleFail
();
return
;
}
String
[]
httpParams
=
param
.
split
(
"\n"
);
String
url
=
null
;
String
method
=
null
;
String
data
=
null
;
for
(
String
httpParam:
httpParams
)
{
if
(
httpParam
.
startsWith
(
"url:"
))
{
url
=
httpParam
.
substring
(
httpParam
.
indexOf
(
"url:"
)
+
4
).
trim
();
}
if
(
httpParam
.
startsWith
(
"method:"
))
{
method
=
httpParam
.
substring
(
httpParam
.
indexOf
(
"method:"
)
+
7
).
trim
().
toUpperCase
();
}
if
(
httpParam
.
startsWith
(
"data:"
))
{
data
=
httpParam
.
substring
(
httpParam
.
indexOf
(
"data:"
)
+
5
).
trim
();
}
}
// param valid
if
(
url
==
null
||
url
.
trim
().
length
()==
0
)
{
XxlJobHelper
.
log
(
"url["
+
url
+
"] invalid."
);
XxlJobHelper
.
handleFail
();
return
;
}
if
(
method
==
null
||
!
Arrays
.
asList
(
"GET"
,
"POST"
).
contains
(
method
))
{
XxlJobHelper
.
log
(
"method["
+
method
+
"] invalid."
);
XxlJobHelper
.
handleFail
();
return
;
}
boolean
isPostMethod
=
method
.
equals
(
"POST"
);
// request
HttpURLConnection
connection
=
null
;
BufferedReader
bufferedReader
=
null
;
try
{
// connection
URL
realUrl
=
new
URL
(
url
);
connection
=
(
HttpURLConnection
)
realUrl
.
openConnection
();
// connection setting
connection
.
setRequestMethod
(
method
);
connection
.
setDoOutput
(
isPostMethod
);
connection
.
setDoInput
(
true
);
connection
.
setUseCaches
(
false
);
connection
.
setReadTimeout
(
5
*
1000
);
connection
.
setConnectTimeout
(
3
*
1000
);
connection
.
setRequestProperty
(
"connection"
,
"Keep-Alive"
);
connection
.
setRequestProperty
(
"Content-Type"
,
"application/json;charset=UTF-8"
);
connection
.
setRequestProperty
(
"Accept-Charset"
,
"application/json;charset=UTF-8"
);
// do connection
connection
.
connect
();
// data
if
(
isPostMethod
&&
data
!=
null
&&
data
.
trim
().
length
()>
0
)
{
DataOutputStream
dataOutputStream
=
new
DataOutputStream
(
connection
.
getOutputStream
());
dataOutputStream
.
write
(
data
.
getBytes
(
"UTF-8"
));
dataOutputStream
.
flush
();
dataOutputStream
.
close
();
}
// valid StatusCode
int
statusCode
=
connection
.
getResponseCode
();
if
(
statusCode
!=
200
)
{
throw
new
RuntimeException
(
"Http Request StatusCode("
+
statusCode
+
") Invalid."
);
}
// result
bufferedReader
=
new
BufferedReader
(
new
InputStreamReader
(
connection
.
getInputStream
(),
"UTF-8"
));
StringBuilder
result
=
new
StringBuilder
();
String
line
;
while
((
line
=
bufferedReader
.
readLine
())
!=
null
)
{
result
.
append
(
line
);
}
String
responseMsg
=
result
.
toString
();
XxlJobHelper
.
log
(
responseMsg
);
return
;
}
catch
(
Exception
e
)
{
XxlJobHelper
.
log
(
e
);
XxlJobHelper
.
handleFail
();
return
;
}
finally
{
try
{
if
(
bufferedReader
!=
null
)
{
bufferedReader
.
close
();
}
if
(
connection
!=
null
)
{
connection
.
disconnect
();
}
}
catch
(
Exception
e2
)
{
XxlJobHelper
.
log
(
e2
);
}
}
}
/**
* 5、生命周期任务示例:任务初始化与销毁时,支持自定义相关逻辑;
*/
@XxlJob
(
value
=
"demoJobHandler2"
,
init
=
"init"
,
destroy
=
"destroy"
)
public
void
demoJobHandler2
()
throws
Exception
{
XxlJobHelper
.
log
(
"XXL-JOB, Hello World."
);
}
public
void
init
(){
logger
.
info
(
"init"
);
}
public
void
destroy
(){
logger
.
info
(
"destory"
);
}
}
xxl-job-executor-samples/xxl-job-executor-sample-spring/src/main/resources/applicationcontext-xxl-job.xml
deleted
100644 → 0
浏览文件 @
437c4e14
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns=
"http://www.springframework.org/schema/beans"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xmlns:context=
"http://www.springframework.org/schema/context"
xsi:schemaLocation=
"http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd"
>
<bean
id=
"propertyConfigurer"
class=
"org.springframework.context.support.PropertySourcesPlaceholderConfigurer"
>
<property
name=
"fileEncoding"
value=
"utf-8"
/>
<property
name=
"locations"
>
<list>
<value>
classpath*:xxl-job-executor.properties
</value>
</list>
</property>
</bean>
<!-- ********************************* 基础配置 ********************************* -->
<!-- 配置01、JobHandler 扫描路径 -->
<context:component-scan
base-package=
"com.xxl.job.executor.service.jobhandler"
/>
<!-- 配置02、执行器 -->
<bean
id=
"xxlJobSpringExecutor"
class=
"com.xxl.job.core.executor.impl.XxlJobSpringExecutor"
>
<!-- 执行器注册中心地址[选填],为空则关闭自动注册 -->
<property
name=
"adminAddresses"
value=
"${xxl.job.admin.addresses}"
/>
<!-- 访问令牌[选填],非空则进行匹配校验 -->
<property
name=
"accessToken"
value=
"${xxl.job.accessToken}"
/>
<!-- 执行器AppName[选填],为空则关闭自动注册 -->
<property
name=
"appname"
value=
"${xxl.job.executor.appname}"
/>
<!-- 注册地址[选填],优先使用该配置作为注册地址,为空时使用内嵌服务 ”IP:PORT“ 作为注册地址 -->
<property
name=
"address"
value=
"${xxl.job.executor.address}"
/>
<!-- 执行器IP[选填],为空则自动获取 -->
<property
name=
"ip"
value=
"${xxl.job.executor.ip}"
/>
<!-- 执行器端口号[选填],小于等于0则自动获取 -->
<property
name=
"port"
value=
"${xxl.job.executor.port}"
/>
<!-- 执行器日志路径[选填],为空则使用默认路径 -->
<property
name=
"logPath"
value=
"${xxl.job.executor.logpath}"
/>
<!-- 日志保存天数[选填],值大于3时生效 -->
<property
name=
"logRetentionDays"
value=
"${xxl.job.executor.logretentiondays}"
/>
</bean>
</beans>
\ No newline at end of file
xxl-job-executor-samples/xxl-job-executor-sample-spring/src/main/resources/log4j.xml
deleted
100644 → 0
浏览文件 @
437c4e14
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration PUBLIC "-//log4j/log4j Configuration//EN" "log4j.dtd">
<log4j:configuration
xmlns:log4j=
"http://jakarta.apache.org/log4j/"
threshold=
"null"
debug=
"null"
>
<appender
name=
"CONSOLE"
class=
"org.apache.log4j.ConsoleAppender"
>
<param
name=
"Target"
value=
"System.out"
/>
<layout
class=
"org.apache.log4j.PatternLayout"
>
<param
name=
"ConversionPattern"
value=
"%-d{yyyy-MM-dd HH:mm:ss} xxl-job-executor-sample-spring [%c]-[%t]-[%M]-[%L]-[%p] %m%n"
/>
</layout>
</appender>
<appender
name=
"FILE"
class=
"org.apache.log4j.DailyRollingFileAppender"
>
<param
name=
"file"
value=
"/data/applogs/xxl-job/xxl-job-executor-sample-spring.log"
/>
<param
name=
"append"
value=
"true"
/>
<param
name=
"encoding"
value=
"UTF-8"
/>
<layout
class=
"org.apache.log4j.PatternLayout"
>
<param
name=
"ConversionPattern"
value=
"%-d{yyyy-MM-dd HH:mm:ss} xxl-job-executor-sample-spring [%c]-[%t]-[%M]-[%L]-[%p] %m%n"
/>
</layout>
</appender>
<root>
<level
value=
"INFO"
/>
<appender-ref
ref=
"CONSOLE"
/>
<appender-ref
ref=
"FILE"
/>
</root>
<!--<logger name="com.xxl.job.executor.service.jobhandler" additivity="false">
<level value="INFO" />
<appender-ref ref="CONSOLE" />
<appender-ref ref="FILE" />
</logger>-->
</log4j:configuration>
\ No newline at end of file
xxl-job-executor-samples/xxl-job-executor-sample-spring/src/main/resources/logback.xml
deleted
100644 → 0
浏览文件 @
437c4e14
<?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"
>
<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>
</configuration>
\ No newline at end of file
xxl-job-executor-samples/xxl-job-executor-sample-spring/src/main/resources/xxl-job-executor.properties
deleted
100644 → 0
浏览文件 @
437c4e14
### xxl-job admin address list, such as "http://address" or "http://address01,http://address02"
xxl.job.admin.addresses
=
http://127.0.0.1:8080/xxl-job-admin
### xxl-job, access token
xxl.job.accessToken
=
### xxl-job executor appname
xxl.job.executor.appname
=
xxl-job-executor-sample
### xxl-job executor registry-address: default use address to registry , otherwise use ip:port if address is null
xxl.job.executor.address
=
### xxl-job executor server-info
xxl.job.executor.ip
=
xxl.job.executor.port
=
9999
### xxl-job executor log-path
xxl.job.executor.logpath
=
/data/applogs/xxl-job/jobhandler
### xxl-job executor log-retention-days
xxl.job.executor.logretentiondays
=
30
\ No newline at end of file
xxl-job-executor-samples/xxl-job-executor-sample-spring/src/main/webapp/WEB-INF/web.xml
deleted
100644 → 0
浏览文件 @
437c4e14
<?xml version="1.0" encoding="UTF-8"?>
<web-app
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xmlns=
"http://java.sun.com/xml/ns/javaee"
xmlns:web=
"http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation=
"http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id=
"WebApp_ID"
version=
"2.5"
>
<display-name>
xxl-job-executor-sample-spring
</display-name>
<context-param>
<param-name>
webAppRootKey
</param-name>
<param-value>
xxl-job-executor-sample-spring
</param-value>
</context-param>
<!-- spring -->
<context-param>
<param-name>
contextConfigLocation
</param-name>
<param-value>
classpath*:applicationcontext-*.xml
</param-value>
</context-param>
<!-- logback -->
<context-param>
<param-name>
logbackConfigLocation
</param-name>
<param-value>
classpath:logback.xml
</param-value>
</context-param>
<listener>
<listener-class>
ch.qos.logback.ext.spring.web.LogbackConfigListener
</listener-class>
</listener>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<welcome-file-list>
<welcome-file>
index.html
</welcome-file>
</welcome-file-list>
</web-app>
\ No newline at end of file
xxl-job-executor-samples/xxl-job-executor-sample-spring/src/main/webapp/index.html
deleted
100644 → 0
浏览文件 @
437c4e14
i am alive.
\ No newline at end of file
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论