注册中心配置

配置前缀:elasticjob.reg-center

可配置属性:

属性名是否必填
server-lists
namespace
base-sleep-time-milliseconds
max-sleep-time-milliseconds
max-retries
session-timeout-milliseconds
connection-timeout-milliseconds
digest

配置格式参考:

YAML

  1. elasticjob:
  2. regCenter:
  3. serverLists: localhost:6181
  4. namespace: elasticjob-lite-springboot

Properties

  1. elasticjob.reg-center.namespace=elasticjob-lite-springboot
  2. elasticjob.reg-center.server-lists=localhost:6181

作业配置

配置前缀:elasticjob.jobs

可配置属性:

属性名是否必填
elasticJobClass / elasticJobType
cron
jobBootstrapBeanName
sharding-total-count
sharding-item-parameters
job-parameter
monitor-execution
failover
misfire
max-time-diff-seconds
reconcile-interval-minutes
job-sharding-strategy-type
job-executor-service-handler-type
job-error-handler-type
job-listener-types
description
props
disabled
overwrite

elasticJobClass 与 elasticJobType 互斥,每项作业只能有一种类型

如果配置了 cron 属性则为定时调度作业,Starter 会在应用启动时自动启动; 否则为一次性调度作业,需要通过 jobBootstrapBeanName 指定 OneOffJobBootstrap Bean 的名称, 在触发点注入 OneOffJobBootstrap 的实例并手动调用 execute() 方法。

配置格式参考:

YAML

  1. elasticjob:
  2. jobs:
  3. simpleJob:
  4. elasticJobClass: org.apache.shardingsphere.elasticjob.lite.example.job.SpringBootSimpleJob
  5. cron: 0/5 * * * * ?
  6. shardingTotalCount: 3
  7. shardingItemParameters: 0=Beijing,1=Shanghai,2=Guangzhou
  8. scriptJob:
  9. elasticJobType: SCRIPT
  10. cron: 0/10 * * * * ?
  11. shardingTotalCount: 3
  12. props:
  13. script.command.line: "echo SCRIPT Job: "
  14. manualScriptJob:
  15. elasticJobType: SCRIPT
  16. jobBootstrapBeanName: manualScriptJobBean
  17. shardingTotalCount: 9
  18. props:
  19. script.command.line: "echo Manual SCRIPT Job: "

Properties

  1. elasticjob.jobs.simpleJob.elastic-job-class=org.apache.shardingsphere.elasticjob.lite.example.job.SpringBootSimpleJob
  2. elasticjob.jobs.simpleJob.cron=0/5 * * * * ?
  3. elasticjob.jobs.simpleJob.sharding-total-count=3
  4. elasticjob.jobs.simpleJob.sharding-item-parameters=0=Beijing,1=Shanghai,2=Guangzhou
  5. elasticjob.jobs.scriptJob.elastic-job-type=SCRIPT
  6. elasticjob.jobs.scriptJob.cron=0/5 * * * * ?
  7. elasticjob.jobs.scriptJob.sharding-total-count=3
  8. elasticjob.jobs.scriptJob.props.script.command.line=echo SCRIPT Job:
  9. elasticjob.jobs.manualScriptJob.elastic-job-type=SCRIPT
  10. elasticjob.jobs.manualScriptJob.job-bootstrap-bean-name=manualScriptJobBean
  11. elasticjob.jobs.manualScriptJob.sharding-total-count=3
  12. elasticjob.jobs.manualScriptJob.props.script.command.line=echo Manual SCRIPT Job:

事件追踪配置

配置前缀:elasticjob.tracing

属性名可选值是否必填
typeRDB

目前仅提供了 RDB 类型的事件追踪数据源实现。 Spring IoC 容器中存在 DataSource 类型的 bean 且配置数据源类型为 RDB 时会自动配置事件追踪,无须显式创建。

配置格式参考:

YAML

  1. elasticjob:
  2. tracing:
  3. type: RDB

Properties

  1. elasticjob.tracing.type=RDB

作业信息导出配置

配置前缀:elasticjob.dump

属性名缺省值是否必填
enabledtrue
port

Spring Boot 提供了作业信息导出端口快速配置,只需在配置中指定导出所用的端口号即可启用导出功能。 如果没有指定端口号,导出功能不会生效。

配置参考:

YAML

  1. elasticjob:
  2. dump:
  3. port: 9888

Properties

  1. elasticjob.dump.port=9888