Elastic-Job 配置介紹


作業配置

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 本地配置是否可覆蓋注冊中心配置
如果可覆蓋,每次啟動作業都以本地配置為准


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM