导向
公司的开发人员说xxl-job写定时任务挺好用、简单的,于是乎去了解了一番,但是学习过程中却也遇到了一些不顺利的事情,以下是这两天所拿下的bug及其前后所部署的操作
了解xxl-job
架构图
介绍
轻量级分布式任务调度平台
主要基于spring quartz 框架搭建的, 修改了任务调度的模式,采用RPC调用来实现执行器的注册和任务的调度
官方文档及demo
链接: https://www.xuxueli.com/xxl-job/.
初始xxl-job 定时任务框架
先将上图的数据库脚本在数据库运行即可,如下图:
然后将我们的xxl-job-admin 模块从整个demo工程拉取下来,如:
部署调度中心(xxl-job-admin),访问调度中心的管理控制页面:可以直接在idea 中启动程序,也可以将程序打包(maven package),用 “java -jar jar包名称 -d”等后台启动调度中心;
接下来为大家演示:
修改对应的application.properties 文件如下:
修改如图配置即可
代码也贴上
### web
server.port=8080
server.servlet.context-path=/xxl-job-admin
### actuator
management.server.servlet.context-path=/actuator
management.health.mail.enabled=false
### resources
spring.mvc.servlet.load-on-startup=0
spring.mvc.static-path-pattern=/static/**
spring.resources.static-locations=classpath:/static/
### freemarker
spring.freemarker.templateLoaderPath=classpath:/templates/
spring.freemarker.suffix=.ftl
spring.freemarker.charset=UTF-8
spring.freemarker.request-context-attribute=request
spring.freemarker.settings.number_format=0.##########
### mybatis
mybatis.mapper-locations=classpath:/mybatis-mapper/*Mapper.xml
#mybatis.type-aliases-package=com.xxl.job.admin.core.model
### xxl-job, datasource
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/xxl_job?useUnicode=true&characterEncoding=utf-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=myroot
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
### datasource-pool
spring.datasource.type=org.apache.tomcat.jdbc.pool.DataSource
spring.datasource.tomcat.max-wait=10000
spring.datasource.tomcat.max-active=30
spring.datasource.tomcat.test-on-borrow=true
spring.datasource.tomcat.validation-query=SELECT 1
spring.datasource.tomcat.validation-interval=30000
### xxl-job, email 修改为你的邮箱名
spring.mail.host=smtp.qq.co