作業配置
與Spring
容器配合使用作業,可以將作業Bean
配置為Spring Bean
,可在作業中通過依賴注入使用Spring
容器管理的數據源等對象。可用placeholder
占位符從屬性文件中取值。
Spring命名空間配置
<?xml version="1.0" encoding="UTF-8"?> <!-- - Copyright 1999-2011 Alibaba Group. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. --> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util" xmlns:job="http://www.dangdang.com/schema/ddframe/job" xsi:schemaLocation="http://www.dangdang.com/schema/ddframe/job http://www.dangdang.com/schema/ddframe/job/job.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.3.xsd"> <job:simple id="virtualInstanceChargeJobTrigger" job-ref="virtualInstanceChargeJob" registry-center-ref="zookeeperRegistryCenter" cron="*/30 * * * * ?" sharding-total-count="1" /> </beans>
job:simple命名空間屬性詳細說明
屬性名 | 類型 | 是否必填 | 缺省值 | 描述 |
---|---|---|---|---|
id | String | 是 |
作業名稱 | |
class | String | 否 | 作業實現類,需實現ElasticJob 接口,腳本型作業不需要配置 |
|
registry-center-ref | String | 是 |
注冊中心Bean 的引用,需引用reg:zookeeper 的聲明 |
|
cron | String | 是 |
cron 表達式,用於配置作業觸發時間 |
|
sharding-total-count | int | 是 |
作業分片總數 | |
sharding-item-parameters | String | 否 | 分片序列號和參數用等號分隔,多個鍵值對用逗號分隔 分片序列號從 0 開始,不可大於或等於作業分片總數如: 0=a,1=b,2=c |
|
job-parameter | String | 否 | 作業自定義參數 可以配置多個相同的作業,但是用不同的參數作為不同的調度實例 |
|
monitor-execution | boolean | 否 | true | 監控作業運行時狀態 每次作業執行時間和間隔時間均非常短的情況,建議不監控作業運行時狀態以提升效率。因為是瞬時狀態,所以無必要監控。請用戶自行增加數據堆積監控。並且不能保證數據重復選取,應在作業中實現冪等性。 每次作業執行時間和間隔時間均較長的情況,建議監控作業運行時狀態,可保證數據不會重復選取。 |
monitor-port | int | 否 | -1 | 作業監控端口 建議配置作業監控端口, 方便開發者dump作業信息。 使用方法: echo “dump” | nc 127.0.0.1 9888 |
max-time-diff-seconds | int | 否 | -1 | 最大允許的本機與注冊中心的時間誤差秒數 如果時間誤差超過配置秒數則作業啟動時將拋異常 配置為 -1 表示不校驗時間誤差 |
failover | boolean | 否 | false | 是否開啟失效轉移 僅 monitorExecution 開啟,失效轉移才有效 |
misfire | boolean | 否 | true | 是否開啟錯過任務重新執行 |
job-sharding-strategy-class | String | 否 | true | 作業分片策略實現類全路徑 默認使用平均分配策略 詳情參見:作業分片策略 |
description | String | 否 | 作業描述信息 | |
disabled | boolean | 否 | false | 作業是否禁止啟動 可用於部署作業時,先禁止啟動,部署結束后統一啟動 |
overwrite | boolean | 否 | false | 本地配置是否可覆蓋注冊中心配置 如果可覆蓋,每次啟動作業都以本地配置為准 |