网站高端设计公司,企业文化vi设计,wordpress 移动端,青岛做视频的网站目录
详解
调度中心
执行器
原理
快速入门
源码仓库地址
1.初始化数据库
2.配置调度中心
1.解压源码
2.需改配置文件
3.启动调度中心
3.配置执行器
1.引入pom依赖
2.修改配置文件
3.执行器组件配置
4.部署执行器项目
4.开发第一个任务
BEAN模式#xff08;类…目录
详解
调度中心
执行器
原理
快速入门
源码仓库地址
1.初始化数据库
2.配置调度中心
1.解压源码
2.需改配置文件
3.启动调度中心
3.配置执行器
1.引入pom依赖
2.修改配置文件
3.执行器组件配置
4.部署执行器项目
4.开发第一个任务
BEAN模式类形式
BEAN模式方法形式
GLUE模式(Java)
任务类型
使用场景 详解
XXL-JOB是一个分布式的任务调度平台其核心设计目标是学习简单、开发迅速、轻量级、易扩展现在已经开放源代码并接入多家公司的线上产品线开箱即用。
xxl-job框架主要用于处理分布式的定时任务其主要由调度中心和执行器组成。
调度中心
统一管理任务调度平台上的调度任务负责触发调度执行并且提供任务管理平台。
执行器
接收调度中心的调度并且执行可以直接执行也可以集成到项目中。 调度中心和执行器两个模块分开部署相互分离两者之间通过RPC进行通信其中调度中心主要是提供一个平台管理调度信息发送调度请求自己不承担业务代码而执行器接受调度中心的调度执行业务逻辑。 原理
1.执行器的注册和发现 执行器启动线程每隔30秒向注册表xxl_job_registry请求一次更新执行器的心跳信息调度中心启动线程每隔30秒检测一次xxl_job_registry将超过90秒还没有收到心跳的实例信息从xxl_job_registry删除并更新xxl_job_group服务的实例列表信息。
2.调度中心调用执行器 执行器接收到调度中心的调度信息将调度信息放到对应的任务的等待队列中 执行器的任务处理线程从任务队列中取出调度信息执行业务逻辑将结果放入一个公共的等待队列中 执行器有一个专门的回调线程定时批量从结果队列中取出任务结果并且回调告知调度中心。
快速入门
源码仓库地址
github:https://github.com/xuxueli/xxl-job
gitee:xxl-job: 一个分布式任务调度平台其核心设计目标是开发迅速、学习简单、轻量级、易扩展。现已开放源代码并接入多家公司线上产品线开箱即用。
gitcode:GitCode - 全球开发者的开源社区,开源代码托管平台
中央仓库地址 dependency groupIdcom.xuxueli/groupId artifactIdxxl-job-core/artifactId version${最新稳定版本}/version /dependency 1.初始化数据库
下载项目源码并解压获取 “调度数据库初始化SQL脚本” 并执行即可。
“调度数据库初始化SQL脚本” 位置为/xxl-job/doc/db/tables_xxl_job.sql
2.配置调度中心
1.解压源码 xxl-job-admin调度中心 xxl-job-core公共依赖 xxl-job-executor-samples执行器Sample示例选择合适的版本执行器可直接使用也可以参考其并将现有项目改造成执行器 xxl-job-executor-sample-springbootSpringboot版本通过Springboot管理执行器推荐这种方式 xxl-job-executor-sample-frameless无框架版本 2.需改配置文件
地址/xxl-job/xxl-job-admin/src/main/resources/application.properties
内容说明
### web
server.port8081
server.servlet.context-path/xxl-job-admin### actuator
management.server.servlet.context-path/actuator
management.health.mail.enabledfalse### resources
spring.mvc.servlet.load-on-startup0
spring.mvc.static-path-pattern/static/**
spring.resources.static-locationsclasspath:/static/### freemarker
spring.freemarker.templateLoaderPathclasspath:/templates/
spring.freemarker.suffix.ftl
spring.freemarker.charsetUTF-8
spring.freemarker.request-context-attributerequest
spring.freemarker.settings.number_format0.##########
spring.freemarker.settings.new_builtin_class_resolversafer### mybatis
mybatis.mapper-locationsclasspath:/mybatis-mapper/*Mapper.xml
#mybatis.type-aliases-packagecom.xxl.job.admin.core.model### xxl-job, datasource
spring.datasource.urljdbc:mysql://192.168.1.200:3306/xxl_job?useUnicodetruecharacterEncodingUTF-8autoReconnecttrueserverTimezoneAsia/Shanghai
spring.datasource.usernameroot
spring.datasource.password123456
spring.datasource.driver-class-namecom.mysql.cj.jdbc.Driver### datasource-pool
spring.datasource.typecom.zaxxer.hikari.HikariDataSource
spring.datasource.hikari.minimum-idle10
spring.datasource.hikari.maximum-pool-size30
spring.datasource.hikari.auto-committrue
spring.datasource.hikari.idle-timeout30000
spring.datasource.hikari.pool-nameHikariCP
spring.datasource.hikari.max-lifetime900000
spring.datasource.hikari.connection-timeout10000
spring.datasource.hikari.connection-test-querySELECT 1
spring.datasource.hikari.validation-timeout1000### xxl-job, email
spring.mail.hostsmtp.qq.com
spring.mail.port25
spring.mail.usernamexxxqq.com
spring.mail.fromxxxqq.com
spring.mail.passwordxxx
spring.mail.properties.mail.smtp.authtrue
spring.mail.properties.mail.smtp.starttls.enabletrue
spring.mail.properties.mail.smtp.starttls.requiredtrue
spring.mail.properties.mail.smtp.socketFactory.classjavax.net.ssl.SSLSocketFactory### xxl-job, access token
xxl.job.accessTokendefault_token### xxl-job, i18n (default is zh_CN, and you can choose zh_CN, zh_TC and en)
xxl.job.i18nzh_CN## xxl-job, triggerpool max size
xxl.job.triggerpool.fast.max200
xxl.job.triggerpool.slow.max100### xxl-job, log retention days
xxl.job.logretentiondays30修改项
server.port8081调度中心端口号 server.servlet.context-path/xxl-job-admin调度中心项目地址 spring.datasource.url调度中心数据库地址 spring.datasource.username调度中心数据库用户名称 spring.datasource.password调度中心数据库用户密码 xxl.job.accessToken调度中心通讯TOKEN [选填]非空时启用为提升系统安全性调度中心和执行器进行安全性校验双方AccessToken匹配才允许通讯 xxl.job.logretentiondays30调度中心日志表数据保存天数 [必填]
3.启动调度中心
如果已经正确进行上述配置可将项目编译打包部署。
调度中心访问地址1http://localhost:808/xxl-job-admin (该地址执行器将会使用到作为回调地址)
默认登录账号 “admin/123456”, 登录后运行界面如下图所示。 至此“调度中心”项目已经部署成功。
3.配置执行器
现以 springboot 版本为例
1.引入pom依赖 dependency groupIdcom.xuxueli/groupId artifactIdxxl-job-core/artifactId version${最新稳定版本}/version /dependency 2.修改配置文件
修改springboot项目中application.properties文件
内容说明
# web port
server.port8082
# no web
#spring.main.web-environmentfalse# log config
logging.configclasspath:logback.xml### xxl-job admin address list, such as http://address or http://address01,http://address02
xxl.job.admin.addresseshttp://127.0.0.1:8081/xxl-job-admin### xxl-job, access token
xxl.job.accessTokendefault_token### xxl-job executor appname
xxl.job.executor.appnamexxl-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.ip127.0.0.1
xxl.job.executor.port9999
### xxl-job executor log-path
xxl.job.executor.logpath/data/applogs/xxl-job/jobhandler
### xxl-job executor log-retention-days
xxl.job.executor.logretentiondays30
修改项
server.port8082 项目ip xxl.job.admin.addresses调度中心部署根地址 [选填]如调度中心集群部署存在多个地址则用逗号分隔。 xxl.job.accessToken执行器通讯TOKEN [选填]非空时启用为提升系统安全性调度中心和执行器进行安全性校验双方AccessToken匹配才允许通讯 xxl.job.executor.appname执行器AppName [选填]执行器心跳注册分组依据为空则关闭自动注册 xxl.job.executor.ip127.0.0.1执行器注册 [选填]优先使用该配置作为注册地址为空时使用内嵌服务 ”IP:PORT“ 作为注册地址。 xxl.job.executor.port9999执行器端口号 [选填]小于等于0则自动获取默认端口为9999
3.执行器组件配置
新建执行器组件配置内容说明 Beanpublic XxlJobSpringExecutor xxlJobExecutor() {logger.info( xxl-job config init.);XxlJobSpringExecutor xxlJobSpringExecutor new XxlJobSpringExecutor();xxlJobSpringExecutor.setAdminAddresses(adminAddresses);xxlJobSpringExecutor.setAppname(appname);xxlJobSpringExecutor.setIp(ip);xxlJobSpringExecutor.setPort(port);xxlJobSpringExecutor.setAccessToken(accessToken);xxlJobSpringExecutor.setLogPath(logPath);xxlJobSpringExecutor.setLogRetentionDays(logRetentionDays);return xxlJobSpringExecutor;}
4.部署执行器项目
正确进行上述配置可将执行器项目编译打部署
4.开发第一个任务
BEAN模式类形式
Bean模式任务支持基于类的开发方式每个任务对应一个Java类。不限制项目环境兼容性好。即使是无框架项目如main方法直接启动的项目也可以提供支持。
开发一个继承自com.xxl.job.core.handler.IJobHandler的JobHandler类实现其中任务方法。 Component public class DemoClassHandler extends IJobHandler { Override public ReturnTString execute(String param) throws Exception { XxlJobLogger.log(XXL-JOB, Hello World.); for (int i 0; i 5; i) { XxlJobLogger.log(beat at: i); TimeUnit.SECONDS.sleep(2); } return SUCCESS; } } 编写XxlJobConfig配置文件用于注册定时任务类 BEAN模式方法形式
Bean模式任务支持基于方法的开发方式每个任务对应一个方法。每个任务只需要开发一个方法并添加”XxlJob”注解即可更加方便、快速 XxlJob(demoJobHandler)
public void demoJobHandler() throws Exception {XxlJobHelper.log(XXL-JOB, Hello World.);
}
GLUE模式(Java)
1.新建任务
登录调度中心点击下图所示“新建任务”按钮新建示例任务。然后参考下面截图中任务的参数配置点击保存。 请点击任务右侧 “GLUE” 按钮进入 “GLUE编辑器开发界面” 见下图。“GLUE模式(Java)” 运行模式的任务默认已经初始化了示例任务代码即打印Hello World。 “GLUE模式(Java)” 运行模式的任务实际上是一段继承自IJobHandler的Java类代码它在执行器项目中运行可使用Resource/Autowire注入执行器里中的其他服务 任务类型
1.BEAN模式: 类形式、方法形式
Bean模式任务支持基于方法的开发模式每个任务对应一个方法。 优点: 每个任务只需要开发一个方法并添加**XxlJob注解**即可方便简单快捷支持自动扫描并添加至执行器容器中。 缺点: 要求spring开发环境基本现在项目spring必备。新定时任务的CRUD需要项目的重新构建和项目启动如果遇到未执行完毕的情况可能会多次执行但是保证多次执行和一次执行的结果不影响对系统也不会有影响
2.GLUE模式Java / Shell / Python / Nodejs / Php 定时任务以源码方式维护在调度中心不需要在本地编写任何代码我们在使用过程中经常是在本地编码完毕后直接复制到线上维护中心中 优点: 支持通过Web IDE在线更新实时编译和生效因此不需要指定JobHandler和重启项目 缺点 如果你依赖了某个框架和服务需要先依赖到自己项目中然后在Web IDE中才能依赖否则会执行报错正常可以理解为把代码从项目中搬到线上可以实时编辑但是和自己在本地写代码的要求一样依赖和服务必须全部具备多用于定时任务经常调整的场景中使用
使用场景
实际项目中可能会使用到Xxl-job来作为分布式任务框架执行定时任务的场景都是为了让业务之外的操作变得更加的简单高效。具体如下 日志处理当系统产生大量日志文件时通过XXL-JOB创建定时任务定期将日志文件进行压缩、归档或上传到云存储等操作 脚本执行即使服务已经上线仍然支持多种格式脚本执行 定期数据备份 定期删除旧文件 定时发送邮件等 文章转载自: http://www.morning.kwqcy.cn.gov.cn.kwqcy.cn http://www.morning.dcpbk.cn.gov.cn.dcpbk.cn http://www.morning.lpmjr.cn.gov.cn.lpmjr.cn http://www.morning.bkkgt.cn.gov.cn.bkkgt.cn http://www.morning.rnzgf.cn.gov.cn.rnzgf.cn http://www.morning.dxhdn.cn.gov.cn.dxhdn.cn http://www.morning.wjpsn.cn.gov.cn.wjpsn.cn http://www.morning.nkddq.cn.gov.cn.nkddq.cn http://www.morning.rsxw.cn.gov.cn.rsxw.cn http://www.morning.pnmnl.cn.gov.cn.pnmnl.cn http://www.morning.homayy.com.gov.cn.homayy.com http://www.morning.kggxj.cn.gov.cn.kggxj.cn http://www.morning.mcqhb.cn.gov.cn.mcqhb.cn http://www.morning.hqsnt.cn.gov.cn.hqsnt.cn http://www.morning.qqklk.cn.gov.cn.qqklk.cn http://www.morning.hqwxm.cn.gov.cn.hqwxm.cn http://www.morning.rcntx.cn.gov.cn.rcntx.cn http://www.morning.rcwzf.cn.gov.cn.rcwzf.cn http://www.morning.rgyts.cn.gov.cn.rgyts.cn http://www.morning.rtspr.cn.gov.cn.rtspr.cn http://www.morning.mntxalcb.com.gov.cn.mntxalcb.com http://www.morning.rytps.cn.gov.cn.rytps.cn http://www.morning.pcxgj.cn.gov.cn.pcxgj.cn http://www.morning.jcwt.cn.gov.cn.jcwt.cn http://www.morning.dnmzl.cn.gov.cn.dnmzl.cn http://www.morning.nrlsg.cn.gov.cn.nrlsg.cn http://www.morning.dmrjx.cn.gov.cn.dmrjx.cn http://www.morning.hhqjf.cn.gov.cn.hhqjf.cn http://www.morning.zbpqq.cn.gov.cn.zbpqq.cn http://www.morning.wprxm.cn.gov.cn.wprxm.cn http://www.morning.mhcft.cn.gov.cn.mhcft.cn http://www.morning.rwpjq.cn.gov.cn.rwpjq.cn http://www.morning.gwhjy.cn.gov.cn.gwhjy.cn http://www.morning.qxgmp.cn.gov.cn.qxgmp.cn http://www.morning.zwndt.cn.gov.cn.zwndt.cn http://www.morning.fbzyc.cn.gov.cn.fbzyc.cn http://www.morning.jfqqs.cn.gov.cn.jfqqs.cn http://www.morning.dgmjm.cn.gov.cn.dgmjm.cn http://www.morning.bwygy.cn.gov.cn.bwygy.cn http://www.morning.xnltz.cn.gov.cn.xnltz.cn http://www.morning.twhgn.cn.gov.cn.twhgn.cn http://www.morning.zwdrz.cn.gov.cn.zwdrz.cn http://www.morning.mttck.cn.gov.cn.mttck.cn http://www.morning.rkmsm.cn.gov.cn.rkmsm.cn http://www.morning.mpnff.cn.gov.cn.mpnff.cn http://www.morning.bzlgb.cn.gov.cn.bzlgb.cn http://www.morning.tjsxx.cn.gov.cn.tjsxx.cn http://www.morning.sknbb.cn.gov.cn.sknbb.cn http://www.morning.mrkbz.cn.gov.cn.mrkbz.cn http://www.morning.yjxfj.cn.gov.cn.yjxfj.cn http://www.morning.wptrm.cn.gov.cn.wptrm.cn http://www.morning.wmgjq.cn.gov.cn.wmgjq.cn http://www.morning.qrcsb.cn.gov.cn.qrcsb.cn http://www.morning.sqqhd.cn.gov.cn.sqqhd.cn http://www.morning.rsbqq.cn.gov.cn.rsbqq.cn http://www.morning.yqsr.cn.gov.cn.yqsr.cn http://www.morning.jnkng.cn.gov.cn.jnkng.cn http://www.morning.ghgck.cn.gov.cn.ghgck.cn http://www.morning.ghxkm.cn.gov.cn.ghxkm.cn http://www.morning.bzlgb.cn.gov.cn.bzlgb.cn http://www.morning.rnqyy.cn.gov.cn.rnqyy.cn http://www.morning.xtqr.cn.gov.cn.xtqr.cn http://www.morning.phgz.cn.gov.cn.phgz.cn http://www.morning.sxwfx.cn.gov.cn.sxwfx.cn http://www.morning.svrud.cn.gov.cn.svrud.cn http://www.morning.yodajy.cn.gov.cn.yodajy.cn http://www.morning.zczkm.cn.gov.cn.zczkm.cn http://www.morning.yxlpj.cn.gov.cn.yxlpj.cn http://www.morning.wmhlz.cn.gov.cn.wmhlz.cn http://www.morning.ztfzm.cn.gov.cn.ztfzm.cn http://www.morning.lgznf.cn.gov.cn.lgznf.cn http://www.morning.frnjm.cn.gov.cn.frnjm.cn http://www.morning.lgnbr.cn.gov.cn.lgnbr.cn http://www.morning.kcfnp.cn.gov.cn.kcfnp.cn http://www.morning.fbbpj.cn.gov.cn.fbbpj.cn http://www.morning.rtkz.cn.gov.cn.rtkz.cn http://www.morning.fhlfp.cn.gov.cn.fhlfp.cn http://www.morning.tpnch.cn.gov.cn.tpnch.cn http://www.morning.sthgm.cn.gov.cn.sthgm.cn http://www.morning.drcnn.cn.gov.cn.drcnn.cn