-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/yinjihuan/elastic-job-spr…
- Loading branch information
Showing
1 changed file
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -145,3 +145,64 @@ public class BeanConfig { | |
|
||
使用注解是比较方便,但很多时候我们需要不同的环境使用不同的配置,测试环境跟生产环境的配置肯定是不一样的,当然你也可以在发布之前将注解中的配置调整好然后发布。 | ||
|
||
为了能够让任务的配置区分环境,还可以在属性文件中配置任务的信息,当属性文件中配置了任务的信息,优先级就比注解中的高。 | ||
|
||
首先还是在任务类上加@ElasticJobConf(name = "MySimpleJob")注解,只需要增加一个name即可,任务名是唯一的。 | ||
|
||
剩下的配置都可以在属性文件中进行配置,格式为elasticJob.任务名.配置属性=属性值 | ||
|
||
``` | ||
elasticJob.MySimpleJob.cron=0/10 * * * * ? | ||
elasticJob.MySimpleJob.overwrite=true | ||
elasticJob.MySimpleJob.shardingTotalCount=1 | ||
elasticJob.MySimpleJob.shardingItemParameters=0=0,1=1 | ||
elasticJob.MySimpleJob.jobParameter=test | ||
elasticJob.MySimpleJob.failover=true | ||
elasticJob.MySimpleJob.misfire=true | ||
elasticJob.MySimpleJob.description=simple job | ||
elasticJob.MySimpleJob.monitorExecution=false | ||
elasticJob.MySimpleJob.listener=com.cxytiandi.job.core.MessageElasticJobListener | ||
elasticJob.MySimpleJob.jobExceptionHandler=com.cxytiandi.job.core.CustomJobExceptionHandler | ||
elasticJob.MySimpleJob.disabled=true | ||
``` | ||
|
||
## Script任务使用说明 | ||
由于Script任务的执行逻辑是在具体的脚本中,是通过scriptCommandLine来指定执行脚本的路径。我这边为了统一的去发现项目中的任务列表,还是需要建一个脚本的Java类,加上ElasticJobConf注解,只是不需要写逻辑而已,示例如下: | ||
|
||
``` | ||
/** | ||
* 脚本任务不需要写逻辑,逻辑在被执行的脚本中,这边只是定义一个任务而已 | ||
* @author yinjihuan | ||
* | ||
*/ | ||
@ElasticJobConf(name = "MyScriptJob") | ||
public class MyScriptJob implements ScriptJob { | ||
public void execute(ShardingContext context) { | ||
} | ||
} | ||
``` | ||
|
||
配置: | ||
|
||
``` | ||
elasticJob.MyScriptJob.cron=0/10 * * * * ? | ||
elasticJob.MyScriptJob.overwrite=true | ||
elasticJob.MyScriptJob.scriptCommandLine=D:\\apache-tomcat-addrepo-allcity\\bin\\startup.bat | ||
``` | ||
|
||
## Spring XML配置代码示例 | ||
|
||
[https://github.com/yinjihuan/spring-cloud/tree/master/fangjia-job](https://github.com/yinjihuan/spring-cloud/tree/master/fangjia-job) | ||
|
||
|
||
# 作者 | ||
- 尹吉欢 [email protected] | ||
- 博客 http://cxytiandi.com/blogs/yinjihuan | ||
|
||
更多技术分享请关注微信公众号:猿天地 | ||
|
||
![image.png](http://upload-images.jianshu.io/upload_images/2685774-da01a73d0cfc3f35.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) |