单个数据源
配置:
server:
port: 9091
xxl:
job:
admin:
# 调度中心部署跟地址 [选填]:如调度中心集群部署存在多个地址则用逗号分隔。执行器将会使用该地址进行"执行器心跳注册"和"任务结果回调";为空则关闭自动注册;
addresses: http://localhost:9090/job-admin
# 执行器通讯TOKEN [选填]:非空时启用;
accessToken: ''
executor:
# 执行器AppName [选填]:执行器心跳注册分组依据;为空则关闭自动注册
appname: test-job-executor
# 执行器注册 [选填]:优先使用该配置作为注册地址,为空时使用内嵌服务 ”IP:PORT“ 作为注册地址。从而更灵活的支持容器类型执行器动态IP和动态映射端口问题。
address:
# 执行器IP [选填]:默认为空表示自动获取IP,多网卡时可手动设置指定IP,该IP不会绑定Host仅作为通讯实用;地址信息用于 "执行器注册" 和 "调度中心请求并触发任务";
ip:
# 执行器端口号 [选填]:小于等于0则自动获取;默认端口为9999,单机部署多个执行器时,注意要配置不同执行器端口;
port: 0
# 执行器运行日志文件存储磁盘路径 [选填] :需要对该路径拥有读写权限;为空则使用默认路径;
logpath: /data/applogs/xxl-job/jobhandler
# 执行器日志文件保存天数 [选填] : 过期日志自动清理, 限制值大于等于3时生效; 否则, 如-1, 关闭自动清理功能;
logretentiondays: 10
spring:
application:
name: test-job-executor
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/test?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai
username: root
password: 111
hikari:
auto-commit: true
connection-test-query: SELECT 1
connection-timeout: 10000
idle-timeout: 30000
max-lifetime: 900000
maximum-pool-size: 30
minimum-idle: 10
pool-name: HikariCP
type: com.zaxxer.hikari.HikariDataSource
main:
allow-bean-definition-overriding: true
redis:
database: 0
host: localhost
jedis:
pool:
max-active: -1
max-idle: 10
max-wait: -1
min-idle: 0
password: redis
port: 6379
timeout: 60000
# cluster:
# nodes:
mybatis-plus:
configuration:
cache-enabled: true
map-underscore-to-camel-case: true
global-config:
db-config:
id-type: AUTO
logic-delete-value: 0
logic-not-delete-value: 1
table-underline: true
mapper-locations: classpath*:/mapper/**/*.xml
type-aliases-package: com.test.*.entity
分库分表多数据源:使用job-admin统一管理各job-executor,每个job-executor连接各自的数据源
配置:
#db 连接池
spring.datasource.url = jdbc:mysql://localhost:3306/my_service?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai
spring.datasource.username = root
spring.datasource.password = 111
spring.datasource.driver-class-name = com.mysql.jdbc.Driver
# mybatis-plus
mybatis-plus.mapper-locations = classpath*:/mapper/**/*.xml
mybatis-plus.type-aliases-package = com.test.*.entity
mybatis-plus.global-config.db-config.id-type = ID_WORKER
mybatis-plus.global-config.db-config.table-underline = true
mybatis-plus.global-config.db-config.logic-delete-value = 0
mybatis-plus.global-config.db-config.logic-not-delete-value = 1
mybatis-plus.configuration.map-underscore-to-camel-case = true
mybatis-plus.configuration.cache-enabled = true
# xxlJob
xxl.job.admin.addresses = http://localhost:9090/job-admin
xxl.job.accessToken =
xxl.job.executor.appname = sys-job-executor
xxl.job.executor.address =
xxl.job.executor.ip =
xxl.job.executor.port = 0
xxl.job.executor.logpath = /data/applogs/xxl-job/jobhandler
xxl.job.executor.logretentiondays = 10
注意使用多个执行器名称多个端口号:
job-admin采用手动注册方式管理多个job-executor,可防止注册节点冲突,任务执行失败的问题