运维篇
- 运维平台地址:apache/shardingsphere-elasticjob: Distributed scheduled job (github.com)
- 下载下来后,跑起 shardingsphere-elasticjob-lite-ui-frontend和shardingsphere-elasticjob-lite-ui-backend即可
原理片:
失效转移:
当作业执行过程中宕机时,ej 允许将该未完成的作业在另一作业节点上补偿执行。作业本身的幂等性,是保证失效转移正确性的前提
配置:failOver(默认false)
执行机制:
感知执行(通知执行):其他服务器感知到有失效作业需要执行并且自己已完成作业,则会实时拉取失效转移的分片项,并开始补偿执行
询问执行:作业执行完成时会询问注册中心失待执行的失效转移分片向,如果有责开始补偿执行,也称异步执行
错过任务重执行:
当错过执行节点的任务时,在任务完成后,马上执行错过的节点任务
应用片:
基于配置文件配置zk中心、任务、监听
application配置:
spring.datasource.url=jdbc:dm://xxx:5236/GMPS_YTH?zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=utf-8
spring.datasource.username=xxx
spring.datasource.password=xxx
spring.datasource.validation-query=select 1 from dual
spring.datasource.driver-class-name=dm.jdbc.driver.DmDriver
spring.main.allow-circular-references=true
# 开启sql慢日志
mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl
# 该配置就是将带有下划线的表字段映射为驼峰格式的实体类属性
mybatis-plus.configuration.map-underscore-to-camel-case=true
elasticjob.reg-center.server-lists=localhost:20200
elasticjob.reg-center.namespace=elasticjob-example
elasticjob.tracing.type=RDB
#
# blockChainJob
elasticjob.jobs.blockChainJob.elasticJobClass=com.augurit.longhua.job.BlockChainJob
elasticjob.jobs.blockChainJob.cron=0/20 * * * * ?
elasticjob.jobs.blockChainJob.shardingTotalCount=3
elasticjob.jobs.blockChainJob.shardingItemParameters=0=Beijing,1=Shanghai,2=Guangzhou
# 开启overwrite
elasticjob.jobs.blockChainJob.overwrite=true
elasticjob.jobs.blockChainJob.jobErrorHandlerType=LOG
elasticjob.jobs.blockChainJob.misfire=true
elasticjob.jobs.blockChainJob.failover=true
# 任务监听
elasticjob.jobs.blockChainJob.jobListenerTypes=simpleListener
# 添加监听器配置
# blockElasticJob
elasticjob.jobs.blockElasticJob.elasticJobClass=com.augurit.longhua.job.BlockElasticJob
elasticjob.jobs.blockElasticJob.cron=0/15 * * * * ?
elasticjob.jobs.blockElasticJob.shardingTotalCount=3
elasticjob.jobs.blockElasticJob.shardingItemParameters=0=Beijing,1=Shanghai,2=Guangzhou
elasticjob.jobs.blockElasticJob.overwrite=true
elasticjob.jobs.blockElasticJob.jobListenerTypes=simpleListener
#
## dataFlowJob
elasticjob.jobs.dataFlowJob.elasticJobClass=com.augurit.longhua.job.BlockElasticDataFlowJob
elasticjob.jobs.dataFlowJob.cron=0/35 * * * * ?
elasticjob.jobs.dataFlowJob.shardingTotalCount=3
elasticjob.jobs.dataFlowJob.shardingItemParameters=0=Beijing,1=Shanghai,2=Guangzhou
添加作业监听:
- 创建监听类, 需继承ElasticJobListener
-
创建SPI配置文件。再resource下mkdir -p 创建META-INF/services 文件夹
-
配置监听类
新建文件,名称为:org.apache.shardingsphere.elasticjob.infra.listener.ElasticJobListener
文集内容:监听器实现类的 类全路径