| <?xml version="1.0" encoding="utf-8" standalone="yes"?> |
| <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> |
| <channel> |
| <title>ElasticJob</title> |
| <link>https://shardingsphere.apache.org/elasticjob/current/cn/</link> |
| <description>Recent content on ElasticJob</description> |
| <generator>Hugo -- gohugo.io</generator> |
| <language>en-us</language> |
| |
| <atom:link href="https://shardingsphere.apache.org/elasticjob/current/cn/index.xml" rel="self" type="application/rss+xml" /> |
| |
| |
| <item> |
| <title>ElasticJob-Lite</title> |
| <link>https://shardingsphere.apache.org/elasticjob/current/cn/quick-start/elasticjob-lite/</link> |
| <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> |
| |
| <guid>https://shardingsphere.apache.org/elasticjob/current/cn/quick-start/elasticjob-lite/</guid> |
| <description>引入 Maven 依赖 &lt;dependency&gt; &lt;groupId&gt;org.apache.shardingsphere.elasticjob&lt;/groupId&gt; &lt;artifactId&gt;elasticjob-lite-core&lt;/artifactId&gt; &lt;version&gt;${latest.release.version}&lt;/version&gt; &lt;/dependency&gt; 作业开发 public class MyJob implements SimpleJob { @Override public void execute(ShardingContext context) { switch (context.getShardingItem()) { case 0: // do something by sharding item 0 break; case 1: // do something by sharding item 1 break; case 2: // do something by sharding item 2 break; // case n: ... } } } 作业配置 JobConfiguration jobConfig = JobConfiguration.newBuilder(&#34;MyJob&#34;, 3).</description> |
| </item> |
| |
| <item> |
| <title>Java API</title> |
| <link>https://shardingsphere.apache.org/elasticjob/current/cn/user-manual/elasticjob-lite/configuration/java-api/</link> |
| <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> |
| |
| <guid>https://shardingsphere.apache.org/elasticjob/current/cn/user-manual/elasticjob-lite/configuration/java-api/</guid> |
| <description>注册中心配置 用于注册和协调作业分布式行为的组件,目前仅支持 ZooKeeper。 |
| 类名称:org.apache.shardingsphere.elasticjob.reg.zookeeper.ZookeeperConfiguration |
| 可配置属性: |
| 属性名 构造器注入 serverLists 是 namespace 是 baseSleepTimeMilliseconds 否 maxSleepTimeMilliseconds 否 maxRetries 否 sessionTimeoutMilliseconds 否 connectionTimeoutMilliseconds 否 digest 否 作业配置 类名称:org.apache.shardingsphere.elasticjob.api.JobConfiguration |
| 可配置属性: |
| 属性名 构造器注入 jobName 是 shardingTotalCount 是 cron 否 shardingItemParameters 否 jobParameter 否 monitorExecution 否 failover 否 misfire 否 maxTimeDiffSeconds 否 reconcileIntervalMinutes 否 jobShardingStrategyType 否 jobExecutorServiceHandlerType 否 jobErrorHandlerType 否 jobListenerTypes 否 description 否 props 否 disabled 否 overwrite 否 </description> |
| </item> |
| |
| <item> |
| <title>作业分片策略</title> |
| <link>https://shardingsphere.apache.org/elasticjob/current/cn/dev-manual/sharding/</link> |
| <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> |
| |
| <guid>https://shardingsphere.apache.org/elasticjob/current/cn/dev-manual/sharding/</guid> |
| <description>作业分片策略,用于将作业在分布式环境下分解成为任务使用。 |
| SPI 名称 详细说明 JobShardingStrategy 作业分片策略 已知实现类 详细说明 AverageAllocationJobShardingStrategy 根据分片项平均分片 OdevitySortByNameJobShardingStrategy 根据作业名称哈希值的奇偶数决定按照作业服务器 IP 升序或是降序的方式分片 RotateServerByNameJobShardingStrategy 根据作业名称轮询分片 </description> |
| </item> |
| |
| <item> |
| <title>作业分片策略</title> |
| <link>https://shardingsphere.apache.org/elasticjob/current/cn/user-manual/elasticjob-lite/configuration/built-in-strategy/sharding/</link> |
| <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> |
| |
| <guid>https://shardingsphere.apache.org/elasticjob/current/cn/user-manual/elasticjob-lite/configuration/built-in-strategy/sharding/</guid> |
| <description>平均分片策略 类型:AVG_ALLOCATION |
| 根据分片项平均分片。 |
| 如果作业服务器数量与分片总数无法整除,多余的分片将会顺序的分配至每一个作业服务器。 |
| 举例说明: |
| 如果 3 台作业服务器且分片总数为9,则分片结果为:1=[0,1,2], 2=[3,4,5], 3=[6,7,8]; 如果 3 台作业服务器且分片总数为8,则分片结果为:1=[0,1,6], 2=[2,3,7], 3=[4,5]; 如果 3 台作业服务器且分片总数为10,则分片结果为:1=[0,1,2,9], 2=[3,4,5], 3=[6,7,8]。 奇偶分片策略 类型:ODEVITY |
| 根据作业名称哈希值的奇偶数决定按照作业服务器 IP 升序或是降序的方式分片。 |
| 如果作业名称哈希值是偶数,则按照 IP 地址进行升序分片; 如果作业名称哈希值是奇数,则按照 IP 地址进行降序分片。 可用于让服务器负载在多个作业共同运行时分配的更加均匀。 |
| 举例说明: |
| 如果 3 台作业服务器,分片总数为2且作业名称的哈希值为偶数,则分片结果为:1 = [0], 2 = [1], 3 = []; 如果 3 台作业服务器,分片总数为2且作业名称的哈希值为奇数,则分片结果为:3 = [0], 2 = [1], 1 = []。 轮询分片策略 类型:ROUND_ROBIN |
| 根据作业名称轮询分片。</description> |
| </item> |
| |
| <item> |
| <title>作业开发</title> |
| <link>https://shardingsphere.apache.org/elasticjob/current/cn/user-manual/elasticjob-lite/usage/job-api/job-interface/</link> |
| <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> |
| |
| <guid>https://shardingsphere.apache.org/elasticjob/current/cn/user-manual/elasticjob-lite/usage/job-api/job-interface/</guid> |
| <description>ElasticJob-Lite 和 ElasticJob-Cloud 提供统一作业接口,开发者仅需对业务作业进行一次开发,之后可根据不同的配置以及部署至不同环境。 |
| ElasticJob 的作业分类基于 class 和 type 两种类型。 基于 class 的作业需要开发者自行通过实现接口的方式织入业务逻辑; 基于 type 的作业则无需编码,只需要提供相应配置即可。 |
| 基于 class 的作业接口的方法参数 shardingContext 包含作业配置、片和运行时信息。 可通过 getShardingTotalCount(), getShardingItem() 等方法分别获取分片总数,运行在本作业服务器的分片序列号等。 |
| ElasticJob 目前提供 Simple、Dataflow 这两种基于 class 的作业类型,并提供 Script、HTTP 这两种基于 type 的作业类型,用户可通过实现 SPI 接口自行扩展作业类型。 |
| 简单作业 意为简单实现,未经任何封装的类型。需实现 SimpleJob 接口。 该接口仅提供单一方法用于覆盖,此方法将定时执行。 与Quartz原生接口相似,但提供了弹性扩缩容和分片等功能。 |
| public class MyElasticJob implements SimpleJob { @Override public void execute(ShardingContext context) { switch (context.getShardingItem()) { case 0: // do something by sharding item 0 break; case 1: // do something by sharding item 1 break; case 2: // do something by sharding item 2 break; // case n: .</description> |
| </item> |
| |
| <item> |
| <title>使用 Java API</title> |
| <link>https://shardingsphere.apache.org/elasticjob/current/cn/user-manual/elasticjob-lite/usage/event-trace/java-api/</link> |
| <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> |
| |
| <guid>https://shardingsphere.apache.org/elasticjob/current/cn/user-manual/elasticjob-lite/usage/event-trace/java-api/</guid> |
| <description>ElasticJob-Lite 在配置中提供了 TracingConfiguration,目前支持数据库方式配置。 开发者也可以通过 SPI 自行扩展。 |
| // 初始化数据源 DataSource dataSource = ...; // 定义日志数据库事件溯源配置 TracingConfiguration tracingConfig = new TracingConfiguration&lt;&gt;(&#34;RDB&#34;, dataSource); // 初始化注册中心 CoordinatorRegistryCenter regCenter = ...; // 初始化作业配置 JobConfiguration jobConfig = ...; new ScheduleJobBootstrap(regCenter, jobConfig, tracingConfig).schedule(); </description> |
| </item> |
| |
| <item> |
| <title>开发指南</title> |
| <link>https://shardingsphere.apache.org/elasticjob/current/cn/user-manual/elasticjob-cloud/usage/dev-guide/</link> |
| <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> |
| |
| <guid>https://shardingsphere.apache.org/elasticjob/current/cn/user-manual/elasticjob-cloud/usage/dev-guide/</guid> |
| <description>作业开发 ElasticJob-Lite 和 ElasticJob-Cloud 提供统一作业接口,开发者仅需对业务作业进行一次开发,之后可根据不同的配置以及部署至不同环境。 |
| 作业开发详情请参见 ElasticJob-Lite 使用手册。 |
| 作业启动 需定义 main 方法并调用 JobBootstrap.execute(),例子如下: |
| public class MyJobDemo { public static void main(final String[] args) { JobBootstrap.execute(new MyJob()); } } </description> |
| </item> |
| |
| <item> |
| <title>监听器开发</title> |
| <link>https://shardingsphere.apache.org/elasticjob/current/cn/user-manual/elasticjob-lite/usage/job-listener/listener-interface/</link> |
| <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> |
| |
| <guid>https://shardingsphere.apache.org/elasticjob/current/cn/user-manual/elasticjob-lite/usage/job-listener/listener-interface/</guid> |
| <description>常规监听器 若作业处理作业服务器的文件,处理完成后删除文件,可考虑使用每个节点均执行清理任务。 此类型任务实现简单,且无需考虑全局分布式任务是否完成,应尽量使用此类型监听器。 |
| public class MyJobListener implements ElasticJobListener { @Override public void beforeJobExecuted(ShardingContexts shardingContexts) { // do something ... } @Override public void afterJobExecuted(ShardingContexts shardingContexts) { // do something ... } @Override public String getType() { return &#34;simpleJobListener&#34;; } } 分布式监听器 若作业处理数据库数据,处理完成后只需一个节点完成数据清理任务即可。 此类型任务处理复杂,需同步分布式环境下作业的状态同步,提供了超时设置来避免作业不同步导致的死锁,应谨慎使用。 |
| public class MyDistributeOnceJobListener extends AbstractDistributeOnceElasticJobListener { public TestDistributeOnceElasticJobListener(long startTimeoutMills, long completeTimeoutMills) { super(startTimeoutMills, completeTimeoutMills); } @Override public void doBeforeJobExecutedAtLastStarted(ShardingContexts shardingContexts) { // do something ... } @Override public void doAfterJobExecutedAtLastCompleted(ShardingContexts shardingContexts) { // do something .</description> |
| </item> |
| |
| <item> |
| <title>调度模型</title> |
| <link>https://shardingsphere.apache.org/elasticjob/current/cn/features/schedule-model/</link> |
| <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> |
| |
| <guid>https://shardingsphere.apache.org/elasticjob/current/cn/features/schedule-model/</guid> |
| <description>与大部分的作业平台不同,ElasticJob 的调度模型划分为支持线程级别调度的进程内调度 ElasticJob-Lite,和进程级别调度的 ElasticJob-Cloud。 |
| 进程内调度 ElasticJob-Lite 是面向进程内的线程级调度框架。通过它,作业能够透明化的与业务应用系统相结合。 它能够方便的与 Spring 、Dubbo 等 Java 框架配合使用,在作业中可自由使用 Spring 注入的 Bean,如数据源连接池、Dubbo 远程服务等,更加方便的贴合业务开发。 |
| 进程级调度 ElasticJob-Cloud 拥有进程内调度和进程级别调度两种方式。 由于 ElasticJob-Cloud 能够对作业服务器的资源进行控制,因此其作业类型可划分为常驻任务和瞬时任务。 常驻任务类似于 ElasticJob-Lite,是进程内调度;瞬时任务则完全不同,它充分的利用了资源分配的削峰填谷能力,是进程级的调度,每次任务的会启动全新的进程处理。</description> |
| </item> |
| |
| <item> |
| <title>部署指南</title> |
| <link>https://shardingsphere.apache.org/elasticjob/current/cn/user-manual/elasticjob-cloud/operation/deploy-guide/</link> |
| <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> |
| |
| <guid>https://shardingsphere.apache.org/elasticjob/current/cn/user-manual/elasticjob-cloud/operation/deploy-guide/</guid> |
| <description>调度器部署步骤 启动 ElasticJob-Cloud-Scheduler 和 Mesos 指定作为注册中心的 ZooKeeper 启动 Mesos Master 和 Mesos Agent 解压 elasticjob-cloud-scheduler-${version}.tar.gz 执行 bin\start.sh 脚本启动 elasticjob-cloud-scheduler 作业部署步骤 确保 ZooKeeper, Mesos Master/Agent 以及 ElasticJob-Cloud-Scheduler 已正确启动 将打包作业的 tar.gz 文件放至网络可访问的位置,如:ftp或http。打包的 tar.gz 文件中 main 方法需要调用 ElasticJob-Cloud 提供的 JobBootstrap.execute 方法 使用 curl 命令调用 RESTful API 发布应用及注册作业。详情请参见:配置指南 调度器配置步骤 可修改 conf\elasticjob-cloud-scheduler.properties 文件变更系统配置。 |
| 配置项说明: |
| 属性名称 是否必填 默认值 描述 hostname 是 服务器真实的 IP 或 hostname,不能是 127.</description> |
| </item> |
| |
| <item> |
| <title>部署指南</title> |
| <link>https://shardingsphere.apache.org/elasticjob/current/cn/user-manual/elasticjob-lite/operation/deploy-guide/</link> |
| <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> |
| |
| <guid>https://shardingsphere.apache.org/elasticjob/current/cn/user-manual/elasticjob-lite/operation/deploy-guide/</guid> |
| <description>应用部署 启动 ElasticJob-Lite 指定注册中心的 ZooKeeper。 运行包含 ElasticJob-Lite 和业务代码的 jar 文件。不限于 jar 或 war 的启动方式。 当作业服务器配置多网卡时,可通过设置系统变量 elasticjob.preferred.network.interface 指定网卡地址。ElasticJob 默认获取网卡列表中第一个非回环可用 IPV4 地址。 运维平台和 RESTFul API 部署(可选) 解压缩 elasticjob-lite-console-${version}.tar.gz 并执行 bin\start.sh。 打开浏览器访问 http://localhost:8899/ 即可访问控制台。8899 为默认端口号,可通过启动脚本输入 -p 自定义端口号。 访问 RESTFul API 方法同控制台。 elasticjob-lite-console-${version}.tar.gz 可通过 mvn install 编译获取。 </description> |
| </item> |
| |
| <item> |
| <title>ElasticJob-Cloud</title> |
| <link>https://shardingsphere.apache.org/elasticjob/current/cn/quick-start/elasticjob-cloud/</link> |
| <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> |
| |
| <guid>https://shardingsphere.apache.org/elasticjob/current/cn/quick-start/elasticjob-cloud/</guid> |
| <description>引入 Maven 依赖 &lt;dependency&gt; &lt;groupId&gt;org.apache.shardingsphere.elasticjob&lt;/groupId&gt; &lt;artifactId&gt;elasticjob-cloud-executor&lt;/artifactId&gt; &lt;version&gt;${latest.release.version}&lt;/version&gt; &lt;/dependency&gt; 作业开发 public class MyJob implements SimpleJob { @Override public void execute(ShardingContext context) { switch (context.getShardingItem()) { case 0: // do something by sharding item 0 break; case 1: // do something by sharding item 1 break; case 2: // do something by sharding item 2 break; // case n: ... } } } 作业启动 需定义 main 方法并调用 JobBootstrap.execute(),例子如下:</description> |
| </item> |
| |
| <item> |
| <title>Spring Boot Starter</title> |
| <link>https://shardingsphere.apache.org/elasticjob/current/cn/user-manual/elasticjob-lite/configuration/spring-boot-starter/</link> |
| <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> |
| |
| <guid>https://shardingsphere.apache.org/elasticjob/current/cn/user-manual/elasticjob-lite/configuration/spring-boot-starter/</guid> |
| <description>注册中心配置 配置前缀:elasticjob.reg-center |
| 可配置属性: |
| 属性名 是否必填 server-lists 是 namespace 是 base-sleep-time-milliseconds 否 max-sleep-time-milliseconds 否 max-retries 否 session-timeout-milliseconds 否 connection-timeout-milliseconds 否 digest 否 配置格式参考: |
| YAML |
| elasticjob: regCenter: serverLists: localhost:6181 namespace: elasticjob-lite-springboot Properties |
| elasticjob.reg-center.namespace=elasticjob-lite-springboot 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 互斥,每项作业只能有一种类型</description> |
| </item> |
| |
| <item> |
| <title>使用 Java API</title> |
| <link>https://shardingsphere.apache.org/elasticjob/current/cn/user-manual/elasticjob-lite/usage/job-api/java-api/</link> |
| <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> |
| |
| <guid>https://shardingsphere.apache.org/elasticjob/current/cn/user-manual/elasticjob-lite/usage/job-api/java-api/</guid> |
| <description>作业配置 ElasticJob-Lite 采用构建器模式创建作业配置对象。 代码示例如下: |
| JobConfiguration jobConfig = JobConfiguration.newBuilder(&#34;myJob&#34;, 3).cron(&#34;0/5 * * * * ?&#34;).shardingItemParameters(&#34;0=Beijing,1=Shanghai,2=Guangzhou&#34;).build(); 作业启动 ElasticJob-Lite 调度器分为定时调度和一次性调度两种类型。 每种调度器启动时均需要注册中心配置、作业对象(或作业类型)以及作业配置这 3 个参数。 |
| 定时调度 public class JobDemo { public static void main(String[] args) { // 调度基于 class 类型的作业 new ScheduleJobBootstrap(createRegistryCenter(), new MyJob(), createJobConfiguration()).schedule(); // 调度基于 type 类型的作业 new ScheduleJobBootstrap(createRegistryCenter(), &#34;MY_TYPE&#34;, createJobConfiguration()).schedule(); } private static CoordinatorRegistryCenter createRegistryCenter() { CoordinatorRegistryCenter regCenter = new ZookeeperRegistryCenter(new ZookeeperConfiguration(&#34;zk_host:2181&#34;, &#34;elastic-job-demo&#34;)); regCenter.init(); return regCenter; } private static JobConfiguration createJobConfiguration() { // 创建作业配置 .</description> |
| </item> |
| |
| <item> |
| <title>使用 Java API</title> |
| <link>https://shardingsphere.apache.org/elasticjob/current/cn/user-manual/elasticjob-lite/usage/job-listener/java-api/</link> |
| <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> |
| |
| <guid>https://shardingsphere.apache.org/elasticjob/current/cn/user-manual/elasticjob-lite/usage/job-listener/java-api/</guid> |
| <description>常规监听器 public class JobMain { public static void main(String[] args) { new ScheduleJobBootstrap(createRegistryCenter(), createJobConfiguration()).schedule(); } private static CoordinatorRegistryCenter createRegistryCenter() { CoordinatorRegistryCenter regCenter = new ZookeeperRegistryCenter(new ZookeeperConfiguration(&#34;zk_host:2181&#34;, &#34;elastic-job-demo&#34;)); regCenter.init(); return regCenter; } private static JobConfiguration createJobConfiguration() { JobConfiguration jobConfiguration = JobConfiguration.newBuilder(&#34;test&#34;, 2) .jobListenerTypes(&#34;simpleListener&#34;, &#34;distributeListener&#34;).build(); } } 分布式监听器 public class JobMain { public static void main(String[] args) { new ScheduleJobBootstrap(createRegistryCenter(), createJobConfiguration()).schedule(); } private static CoordinatorRegistryCenter createRegistryCenter() { CoordinatorRegistryCenter regCenter = new ZookeeperRegistryCenter(new ZookeeperConfiguration(&#34;zk_host:2181&#34;, &#34;elastic-job-demo&#34;)); regCenter.</description> |
| </item> |
| |
| <item> |
| <title>使用 Spring Boot Starter</title> |
| <link>https://shardingsphere.apache.org/elasticjob/current/cn/user-manual/elasticjob-lite/usage/event-trace/spring-boot-starter/</link> |
| <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> |
| |
| <guid>https://shardingsphere.apache.org/elasticjob/current/cn/user-manual/elasticjob-lite/usage/event-trace/spring-boot-starter/</guid> |
| <description>ElasticJob-Lite 的 Spring Boot Starter 集成了 TracingConfiguration 自动配置, 开发者只需注册一个 DataSource 到 Spring 容器中并在配置文件指定事件追踪数据源类型, Starter 就会自动创建一个 TracingConfiguration 实例并注册到 Spring 容器中。 |
| 引入 Maven 依赖 引入 spring-boot-starter-jdbc 注册数据源或自行创建一个 DataSource Bean。 |
| &lt;dependency&gt; &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt; &lt;artifactId&gt;spring-boot-starter-jdbc&lt;/artifactId&gt; &lt;version&gt;${springboot.version}&lt;/version&gt; &lt;/dependency&gt; 配置 spring: datasource: url: jdbc:h2:mem:job_event_storage driver-class-name: org.h2.Driver username: sa password: elasticjob: tracing: type: RDB 作业启动 指定事件追踪数据源类型为 RDB,TracingConfiguration 会自动注册到容器中,如果与 elasticjob-lite-spring-boot-starter 配合使用, 开发者无需进行其他额外的操作,作业启动器会自动使用创建的 TracingConfiguration。</description> |
| </item> |
| |
| <item> |
| <title>导出作业信息</title> |
| <link>https://shardingsphere.apache.org/elasticjob/current/cn/user-manual/elasticjob-lite/operation/dump/</link> |
| <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> |
| |
| <guid>https://shardingsphere.apache.org/elasticjob/current/cn/user-manual/elasticjob-lite/operation/dump/</guid> |
| <description>使用 ElasticJob-Lite 过程中可能会碰到一些分布式问题,导致作业运行不稳定。 |
| 由于无法在生产环境调试,通过 dump 命令可以把作业内部相关信息导出,方便开发者调试分析; 另外为了不泄露隐私,已将相关信息中的 IP 地址以 ip1, ip2&hellip; 的形式过滤,可以在互联网上公开传输环境信息,便于进一步完善 ElasticJob。 |
| 开启监听端口 使用 Java 开启导出端口配置请参见Java API 使用指南。 使用 Spring 开启导出端口配置请参见Spring 使用指南。 |
| 执行导出命令 导出命令完全参照 ZooKeeper 的四字命令理念。 |
| 导出至标准输出 |
| echo &#34;dump@jobName&#34; | nc &lt;任意一台作业服务器IP&gt; 9888 导出至文件 |
| echo &#34;dump@jobName&#34; | nc &lt;任意一台作业服务器IP&gt; 9888 &gt; job_debug.txt </description> |
| </item> |
| |
| <item> |
| <title>弹性调度</title> |
| <link>https://shardingsphere.apache.org/elasticjob/current/cn/features/elastic/</link> |
| <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> |
| |
| <guid>https://shardingsphere.apache.org/elasticjob/current/cn/features/elastic/</guid> |
| <description>弹性调度是 ElasticJob 最重要的功能,也是这款产品名称的由来。 它是一款能够让任务通过分片进行水平扩展的任务处理系统。 |
| 分片 ElasticJob 中任务分片项的概念,使得任务可以在分布式的环境下运行,每台任务服务器只运行分配给该服务器的分片。 随着服务器的增加或宕机,ElasticJob 会近乎实时的感知服务器数量的变更,从而重新为分布式的任务服务器分配更加合理的任务分片项,使得任务可以随着资源的增加而提升效率。 |
| 任务的分布式执行,需要将一个任务拆分为多个独立的任务项,然后由分布式的服务器分别执行某一个或几个分片项。 |
| 举例说明,如果作业分为 4 片,用两台服务器执行,则每个服务器分到 2 片,分别负责作业的 50% 的负载,如下图所示。 |
| 分片项 ElasticJob 并不直接提供数据处理的功能,而是将分片项分配至各个运行中的作业服务器,开发者需要自行处理分片项与业务的对应关系。 分片项为数字,始于 0 而终于分片总数减 1。 |
| 个性化分片参数 个性化参数可以和分片项匹配对应关系,用于将分片项的数字转换为更加可读的业务代码。 |
| 例如:按照地区水平拆分数据库,数据库 A 是北京的数据;数据库 B 是上海的数据;数据库 C 是广州的数据。 如果仅按照分片项配置,开发者需要了解 0 表示北京;1 表示上海;2 表示广州。 合理使用个性化参数可以让代码更可读,如果配置为 0=北京,1=上海,2=广州,那么代码中直接使用北京,上海,广州的枚举值即可完成分片项和业务逻辑的对应关系。 |
| 资源最大限度利用 ElasticJob 提供最灵活的方式,最大限度的提高执行作业的吞吐量。 当新增加作业服务器时,ElasticJob 会通过注册中心的临时节点的变化感知到新服务器的存在,并在下次任务调度的时候重新分片,新的服务器会承载一部分作业分片,如下图所示。 |
| 将分片项设置为大于服务器的数量,最好是大于服务器倍数的数量,作业将会合理的利用分布式资源,动态的分配分片项。 |
| 例如:3 台服务器,分成 10 片,则分片项分配结果为服务器 A = 0,1,2;服务器 B = 3,4,5;服务器 C = 6,7,8,9。 如果服务器 C 崩溃,则分片项分配结果为服务器 A = 0,1,2,3,4; 服务器 B = 5,6,7,8,9。 在不丢失分片项的情况下,最大限度的利用现有资源提高吞吐量。</description> |
| </item> |
| |
| <item> |
| <title>本地运行模式</title> |
| <link>https://shardingsphere.apache.org/elasticjob/current/cn/user-manual/elasticjob-cloud/usage/local-executor/</link> |
| <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> |
| |
| <guid>https://shardingsphere.apache.org/elasticjob/current/cn/user-manual/elasticjob-cloud/usage/local-executor/</guid> |
| <description>在开发 ElasticJob-Cloud 作业时,开发人员可以脱离 Mesos 环境,在本地运行和调试作业。 可以利用本地运行模式充分的调试业务功能以及单元测试,完成之后再部署至 Mesos 集群。 |
| 本地运行作业无需安装 Mesos 环境。 |
| // 创建作业配置 JobConfiguration jobConfig = JobConfiguration.newBuilder(&#34;myJob&#34;, 3).cron(&#34;0/5 * * * * ?&#34;).build(); // 配置当前运行的作业的分片项 int shardingItem = 0; // 创建本地执行器 new LocalTaskExecutor(new MyJob(), jobConfig, shardingItem).execute(); </description> |
| </item> |
| |
| <item> |
| <title>线程池策略</title> |
| <link>https://shardingsphere.apache.org/elasticjob/current/cn/dev-manual/thread-pool/</link> |
| <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> |
| |
| <guid>https://shardingsphere.apache.org/elasticjob/current/cn/dev-manual/thread-pool/</guid> |
| <description>线程池策略,用于执行作业的线程池创建。 |
| SPI 名称 详细说明 JobExecutorServiceHandler 作业执行线程池策略 已知实现类 详细说明 CPUUsageJobExecutorServiceHandler 根据 CPU 核数 * 2 创建作业处理线程池 SingleThreadJobExecutorServiceHandler 使用单线程处理作业 </description> |
| </item> |
| |
| <item> |
| <title>线程池策略</title> |
| <link>https://shardingsphere.apache.org/elasticjob/current/cn/user-manual/elasticjob-lite/configuration/built-in-strategy/thread-pool/</link> |
| <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> |
| |
| <guid>https://shardingsphere.apache.org/elasticjob/current/cn/user-manual/elasticjob-lite/configuration/built-in-strategy/thread-pool/</guid> |
| <description>CPU 资源策略 类型:CPU |
| 根据 CPU 核数 * 2 创建作业处理线程池。 |
| 单线程策略 类型:SINGLE_THREAD |
| 使用单线程处理作业。</description> |
| </item> |
| |
| <item> |
| <title>高可用</title> |
| <link>https://shardingsphere.apache.org/elasticjob/current/cn/user-manual/elasticjob-cloud/operation/high-availability/</link> |
| <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> |
| |
| <guid>https://shardingsphere.apache.org/elasticjob/current/cn/user-manual/elasticjob-cloud/operation/high-availability/</guid> |
| <description>介绍 调度器的高可用是通过运行几个指向同一个 ZooKeeper 集群的 ElasticJob-Cloud-Scheduler 实例来实现的。 ZooKeeper 用于在当前主 ElasticJob-Cloud-Scheduler 实例失败的情况下执行领导者选举。 通过至少两个调度器实例来构成集群,集群中只有一个调度器实例提供服务,其他实例处于待命状态。 当该实例失败时,集群会选举剩余实例中的一个来继续提供服务。 |
| 配置 每个 ElasticJob-Cloud-Scheduler 实例必须使用相同的 ZooKeeper 集群。 例如,如果 ZooKeeper 的 Quorum 为 zk://1.2.3.4:2181,2.3.4.5:2181,3.4.5.6:2181/elasticjob-cloud,则 elasticjob-cloud-scheduler.properties 中 ZooKeeper 相关配置为: |
| # ElasticJob-Cloud's ZooKeeper address zk_servers=1.2.3.4:2181,2.3.4.5:2181,3.4.5.6:2181 # ElasticJob-Cloud's ZooKeeper namespace zk_namespace=elasticjob-cloud </description> |
| </item> |
| |
| <item> |
| <title>Spring 命名空间</title> |
| <link>https://shardingsphere.apache.org/elasticjob/current/cn/user-manual/elasticjob-lite/configuration/spring-namespace/</link> |
| <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> |
| |
| <guid>https://shardingsphere.apache.org/elasticjob/current/cn/user-manual/elasticjob-lite/configuration/spring-namespace/</guid> |
| <description>使用 Spring 命名空间需在 pom.xml 文件中添加 elasticjob-lite-spring 模块的依赖。 |
| &lt;dependency&gt; &lt;groupId&gt;org.apache.shardingsphere.elasticjob&lt;/groupId&gt; &lt;artifactId&gt;elasticjob-lite-spring-namespace&lt;/artifactId&gt; &lt;version&gt;${latest.release.version}&lt;/version&gt; &lt;/dependency&gt; 命名空间:http://shardingsphere.apache.org/schema/elasticjob/elasticjob.xsd |
| 注册中心配置 &lt;elasticjob:zookeeper /&gt; |
| 可配置属性: |
| 属性名 是否必填 id 是 server-lists 是 namespace 是 base-sleep-time-milliseconds 否 max-sleep-time-milliseconds 否 max-retries 否 session-timeout-milliseconds 否 connection-timeout-milliseconds 否 digest 否 作业配置 &lt;elasticjob:job /&gt; |
| 可配置属性: |
| 属性名 是否必填 id 是 class 否 job-ref 否 registry-center-ref 是 tracing-ref 否 cron 是 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 否 事件追踪配置 &lt;elasticjob:rdb-event-trace /&gt;</description> |
| </item> |
| |
| <item> |
| <title>作业运行状态监控</title> |
| <link>https://shardingsphere.apache.org/elasticjob/current/cn/user-manual/elasticjob-lite/operation/execution-monitor/</link> |
| <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> |
| |
| <guid>https://shardingsphere.apache.org/elasticjob/current/cn/user-manual/elasticjob-lite/operation/execution-monitor/</guid> |
| <description>通过监听 ElasticJob-Lite 的 ZooKeeper 注册中心的几个关键节点即可完成作业运行状态监控功能。 |
| 监听作业服务器存活 监听 job_name\instances\job_instance_id 节点是否存在。该节点为临时节点,如果作业服务器下线,该节点将删除。</description> |
| </item> |
| |
| <item> |
| <title>使用 Spring Boot Starter</title> |
| <link>https://shardingsphere.apache.org/elasticjob/current/cn/user-manual/elasticjob-lite/usage/job-api/spring-boot-starter/</link> |
| <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> |
| |
| <guid>https://shardingsphere.apache.org/elasticjob/current/cn/user-manual/elasticjob-lite/usage/job-api/spring-boot-starter/</guid> |
| <description>ElasticJob-Lite 提供自定义的 Spring Boot Starter,可以与 Spring Boot 配合使用。 基于 ElasticJob Spring Boot Starter 使用 ElasticJob ,用户无需手动创建 CoordinatorRegistryCenter、JobBootstrap 等实例, 只需实现核心作业逻辑并辅以少量配置,即可利用轻量、无中心化的 ElasticJob 解决分布式调度问题。 |
| 作业配置 实现作业逻辑 作业逻辑实现与 ElasticJob 的其他使用方式并没有较大的区别,只需将当前作业注册为 Spring 容器中的 bean。 |
| 线程安全问题 |
| Bean 默认是单例的,如果该作业实现会在同一个进程内被创建出多个 JobBootstrap 的实例, 可以考虑设置 Scope 为 prototype。 |
| @Component public class SpringBootDataflowJob implements DataflowJob&lt;Foo&gt; { @Override public List&lt;Foo&gt; fetchData(final ShardingContext shardingContext) { // 获取数据 } @Override public void processData(final ShardingContext shardingContext, final List&lt;Foo&gt; data) { // 处理数据 } } 配置协调服务与作业 在配置文件中指定 ElasticJob 所使用的 Zookeeper。配置前缀为 elasticjob.</description> |
| </item> |
| |
| <item> |
| <title>使用 Spring 命名空间</title> |
| <link>https://shardingsphere.apache.org/elasticjob/current/cn/user-manual/elasticjob-lite/usage/event-trace/spring-namespace/</link> |
| <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> |
| |
| <guid>https://shardingsphere.apache.org/elasticjob/current/cn/user-manual/elasticjob-lite/usage/event-trace/spring-namespace/</guid> |
| <description>引入 Maven 依赖 引入 elasticjob-lite-spring |
| &lt;dependency&gt; &lt;groupId&gt;org.apache.shardingsphere.elasticjob&lt;/groupId&gt; &lt;artifactId&gt;elasticjob-lite-spring-namespace&lt;/artifactId&gt; &lt;version&gt;${elasticjob.latest.version}&lt;/version&gt; &lt;/dependency&gt; 配置 &lt;?xml version=&#34;1.0&#34; encoding=&#34;UTF-8&#34;?&gt; &lt;beans xmlns=&#34;http://www.springframework.org/schema/beans&#34; xmlns:xsi=&#34;http://www.w3.org/2001/XMLSchema-instance&#34; xmlns:elasticjob=&#34;http://shardingsphere.apache.org/schema/elasticjob&#34; xsi:schemaLocation=&#34;http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://shardingsphere.apache.org/schema/elasticjob http://shardingsphere.apache.org/schema/elasticjob/elasticjob.xsd &#34;&gt; &lt;!--配置作业注册中心 --&gt; &lt;elasticjob:zookeeper id=&#34;regCenter&#34; server-lists=&#34;yourhost:2181&#34; namespace=&#34;my-job&#34; base-sleep-time-milliseconds=&#34;1000&#34; max-sleep-time-milliseconds=&#34;3000&#34; max-retries=&#34;3&#34; /&gt; &lt;!-- 配置作业 Bean --&gt; &lt;bean id=&#34;myJob&#34; class=&#34;xxx.MyJob&#34; /&gt; &lt;!-- 配置数据源 --&gt; &lt;bean id=&#34;tracingDataSource&#34; class=&#34;org.apache.commons.dbcp.BasicDataSource&#34; destroy-method=&#34;close&#34;&gt; &lt;property name=&#34;driverClassName&#34; value=&#34;${driver.class.name}&#34; /&gt; &lt;property name=&#34;url&#34; value=&#34;${url}&#34; /&gt; &lt;property name=&#34;username&#34; value=&#34;${username}&#34; /&gt; &lt;property name=&#34;password&#34; value=&#34;${password}&#34; /&gt; &lt;/bean&gt; &lt;!-- 配置事件追踪 --&gt; &lt;elasticjob:rdb-event-trace id=&#34;elasticJobTrace&#34; data-source-ref=&#34;elasticJobTracingDataSource&#34; /&gt; &lt;!</description> |
| </item> |
| |
| <item> |
| <title>使用 Spring 命名空间</title> |
| <link>https://shardingsphere.apache.org/elasticjob/current/cn/user-manual/elasticjob-lite/usage/job-listener/spring-namespace/</link> |
| <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> |
| |
| <guid>https://shardingsphere.apache.org/elasticjob/current/cn/user-manual/elasticjob-lite/usage/job-listener/spring-namespace/</guid> |
| <description>监听器配置 &lt;?xml version=&#34;1.0&#34; encoding=&#34;UTF-8&#34;?&gt; &lt;beans xmlns=&#34;http://www.springframework.org/schema/beans&#34; xmlns:xsi=&#34;http://www.w3.org/2001/XMLSchema-instance&#34; xmlns:elasticjob=&#34;http://shardingsphere.apache.org/schema/elasticjob&#34; xsi:schemaLocation=&#34;http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://shardingsphere.apache.org/schema/elasticjob http://shardingsphere.apache.org/schema/elasticjob/elasticjob.xsd &#34;&gt; &lt;!--配置作业注册中心 --&gt; &lt;elasticjob:zookeeper id=&#34;regCenter&#34; server-lists=&#34;yourhost:2181&#34; namespace=&#34;my-job&#34; base-sleep-time-milliseconds=&#34;1000&#34; max-sleep-time-milliseconds=&#34;3000&#34; max-retries=&#34;3&#34; /&gt; &lt;!-- 配置作业 Bean --&gt; &lt;bean id=&#34;myJob&#34; class=&#34;xxx.MyJob&#34; /&gt; &lt;elasticjob:job id=&#34;${myJob.id}&#34; job-ref=&#34;myJob&#34; registry-center-ref=&#34;regCenter&#34; sharding-total-count=&#34;3&#34; cron=&#34;0/1 * * * * ?&#34; job-listener-types=&#34;simpleJobListener,distributeOnceJobListener&#34;&gt; &lt;/elasticjob:job&gt; &lt;/beans&gt; 作业启动 将配置 Spring 命名空间的 xml 通过 Spring 启动,作业将自动加载。</description> |
| </item> |
| |
| <item> |
| <title>资源分配</title> |
| <link>https://shardingsphere.apache.org/elasticjob/current/cn/features/resource/</link> |
| <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> |
| |
| <guid>https://shardingsphere.apache.org/elasticjob/current/cn/features/resource/</guid> |
| <description>资源分配功能为 ElasticJob-Cloud 所特有的功能。 |
| 作业运行模式 ElasticJob-Cloud 分为瞬时作业和常驻作业 2 种运行模式。 |
| 瞬时作业 在每一次作业执行完毕后立刻释放资源,保证利用现有资源错峰执行。 资源分配和容器启动均占用一定时长,且作业执行时资源不一定充足,因此作业执行会有延迟。 瞬时作业适用于间隔时间长,资源消耗多且对执行时间无严格要求的作业。 |
| 常驻作业 无论在运行时还是等待运行时,均一直占用分配的资源,可节省过多容器启动和资源分配的开销,适用于间隔时间短,资源需求量稳定的作业。 |
| 调度器 ElasticJob-Cloud 基于 Mesos 的 Framework 开发,用于资源调度和应用分发,需要独立启动并提供服务。 |
| 作业应用 指作业打包部署后的应用,描述了作业启动需要用到的 CPU、内存、启动脚本及应用下载路径等基本信息。 每个作业应用可以包含一个或多个作业。 |
| 作业 即实际运行的具体任务,和 ElasticJob-Lite 共用同样的作业生态。 在注册作业之前必须先注册作业应用。 |
| 资源 指作业启动或运行需要用到的 CPU、内存。 配置在作业应用维度表示整个应用启动需要用的资源; 配置在作业维度表示每个作业运行需要的资源。 作业启动需要的资源为指定作业应用需要的资源与作业需要资源的总和。</description> |
| </item> |
| |
| <item> |
| <title>运维平台</title> |
| <link>https://shardingsphere.apache.org/elasticjob/current/cn/user-manual/elasticjob-cloud/operation/web-console/</link> |
| <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> |
| |
| <guid>https://shardingsphere.apache.org/elasticjob/current/cn/user-manual/elasticjob-cloud/operation/web-console/</guid> |
| <description>运维平台内嵌于 elasticjob-cloud-scheduler 的 jar 包中,无需额外启动 WEB 服务器。 可通过修改配置文件中 http_port 参数来调整启动端口,默认端口为 8899,访问地址为 http://{your_scheduler_ip}:8899。 |
| 登录 提供两种账户,管理员及访客,管理员拥有全部操作权限,访客仅拥有察看权限。 默认管理员用户名和密码是 root/root,访客用户名和密码是 guest/guest,可通过 conf\auth.properties 修改管理员及访客用户名及密码。 |
| 功能列表 应用管理(发布、修改、查看) 作业管理(注册、修改、查看以及删除) 作业状态查看(待运行、运行中、待失效转移) 作业历史查看(运行轨迹、执行状态、历史仪表盘) 设计理念 运维平台采用纯静态 HTML + JavaScript 方式与后台的 RESTful API 交互,通过读取作业注册中心展示作业配置和状态,数据库展现作业运行轨迹及执行状态,或更新作业注册中心数据修改作业配置。</description> |
| </item> |
| |
| <item> |
| <title>错误处理策略</title> |
| <link>https://shardingsphere.apache.org/elasticjob/current/cn/dev-manual/error-handler/</link> |
| <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> |
| |
| <guid>https://shardingsphere.apache.org/elasticjob/current/cn/dev-manual/error-handler/</guid> |
| <description>错误处理策略,用于作业失败时的处理策略。 |
| SPI 名称 详细说明 JobErrorHandler 作业执行错误处理策略 已知实现类 详细说明 LogJobErrorHandler 记录作业异常日志,但不中断作业执行 ThrowJobErrorHandler 抛出系统异常并中断作业执行 IgnoreJobErrorHandler 忽略系统异常且不中断作业执行 EmailJobErrorHandler 发送邮件消息通知,但不中断作业执行 WechatJobErrorHandler 发送企业微信消息通知,但不中断作业执行 DingtalkJobErrorHandler 发送钉钉消息通知,但不中断作业执行 </description> |
| </item> |
| |
| <item> |
| <title>错误处理策略</title> |
| <link>https://shardingsphere.apache.org/elasticjob/current/cn/user-manual/elasticjob-lite/configuration/built-in-strategy/error-handler/</link> |
| <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> |
| |
| <guid>https://shardingsphere.apache.org/elasticjob/current/cn/user-manual/elasticjob-lite/configuration/built-in-strategy/error-handler/</guid> |
| <description>记录日志策略 类型:LOG |
| 默认内置:是 |
| 记录作业异常日志,但不中断作业执行。 |
| 抛出异常策略 类型:THROW |
| 默认内置:是 |
| 抛出系统异常并中断作业执行。 |
| 忽略异常策略 类型:IGNORE |
| 默认内置:是 |
| 忽略系统异常且不中断作业执行。 |
| 邮件通知策略 类型:EMAIL |
| 默认内置:否 |
| 发送邮件消息通知,但不中断作业执行。 |
| Maven 坐标: |
| &lt;dependency&gt; &lt;groupId&gt;org.apache.shardingsphere.elasticjob&lt;/groupId&gt; &lt;artifactId&gt;elasticjob-error-handler-email&lt;/artifactId&gt; &lt;version&gt;${latest.release.version}&lt;/version&gt; &lt;/dependency&gt; 可配置属性: |
| 属性名 说明 默认值 email.host TODO 无 email.port TODO 无 email.username TODO 无 email.password TODO 无 email.useSsl TODO 无 email.subject TODO ElasticJob error message email.from TODO 无 email.</description> |
| </item> |
| |
| <item> |
| <title>作业类名称提供策略</title> |
| <link>https://shardingsphere.apache.org/elasticjob/current/cn/dev-manual/job-class-provider/</link> |
| <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> |
| |
| <guid>https://shardingsphere.apache.org/elasticjob/current/cn/dev-manual/job-class-provider/</guid> |
| <description>作业类名称提供策略,用于在不同的容器环境下提供准确的作业类名称。 |
| SPI 名称 详细说明 JobClassNameProvider 作业类名称提供策略 已知实现类 详细说明 DefaultJobClassNameProvider 标准环境下的作业类名称提供策略 SpringProxyJobClassNameProvider Spring 容器环境下的作业类名称提供策略 </description> |
| </item> |
| |
| <item> |
| <title>使用 Spring 命名空间</title> |
| <link>https://shardingsphere.apache.org/elasticjob/current/cn/user-manual/elasticjob-lite/usage/job-api/spring-namespace/</link> |
| <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> |
| |
| <guid>https://shardingsphere.apache.org/elasticjob/current/cn/user-manual/elasticjob-lite/usage/job-api/spring-namespace/</guid> |
| <description>ElasticJob-Lite 提供自定义的 Spring 命名空间,可以与 Spring 容器配合使用。 开发者能够便捷的在作业中通过依赖注入使用 Spring 容器管理的数据源等对象,并使用占位符从属性文件中取值。 |
| 作业配置 &lt;?xml version=&#34;1.0&#34; encoding=&#34;UTF-8&#34;?&gt; &lt;beans xmlns=&#34;http://www.springframework.org/schema/beans&#34; xmlns:xsi=&#34;http://www.w3.org/2001/XMLSchema-instance&#34; xmlns:elasticjob=&#34;http://shardingsphere.apache.org/schema/elasticjob&#34; xsi:schemaLocation=&#34;http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://shardingsphere.apache.org/schema/elasticjob http://shardingsphere.apache.org/schema/elasticjob/elasticjob.xsd &#34;&gt; &lt;!--配置作业注册中心 --&gt; &lt;elasticjob:zookeeper id=&#34;regCenter&#34; server-lists=&#34;yourhost:2181&#34; namespace=&#34;my-job&#34; base-sleep-time-milliseconds=&#34;1000&#34; max-sleep-time-milliseconds=&#34;3000&#34; max-retries=&#34;3&#34; /&gt; &lt;!-- 配置作业 Bean --&gt; &lt;bean id=&#34;myJob&#34; class=&#34;xxx.MyJob&#34;&gt; &lt;property name=&#34;fooService&#34; ref=&#34;xxx.FooService&#34; /&gt; &lt;/bean&gt; &lt;!-- 配置基于 class 的作业调度 --&gt; &lt;elasticjob:job id=&#34;${myJob.id}&#34; job-ref=&#34;myJob&#34; registry-center-ref=&#34;regCenter&#34; sharding-total-count=&#34;${myJob.shardingTotalCount}&#34; cron=&#34;${myJob.cron}&#34; /&gt; &lt;!-- 配置基于 type 的作业调度 --&gt; &lt;elasticjob:job id=&#34;${myScriptJob.id}&#34; job-type=&#34;SCRIPT&#34; registry-center-ref=&#34;regCenter&#34; sharding-total-count=&#34;${myScriptJob.shardingTotalCount}&#34; cron=&#34;${myScriptJob.cron}&#34;&gt; &lt;props&gt; &lt;prop key=&#34;script.command.line&#34;&gt;${myScriptJob.scriptCommandLine}&lt;/prop&gt; &lt;/props&gt; &lt;/elasticjob:job&gt; &lt;/beans&gt; 作业启动 将配置 Spring 命名空间的 xml 通过 Spring 启动,作业将自动加载。</description> |
| </item> |
| |
| <item> |
| <title>失效转移</title> |
| <link>https://shardingsphere.apache.org/elasticjob/current/cn/features/failover/</link> |
| <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> |
| |
| <guid>https://shardingsphere.apache.org/elasticjob/current/cn/features/failover/</guid> |
| <description>ElasticJob 不会在本次执行过程中进行重新分片,而是等待下次调度之前才开启重新分片流程。 当作业执行过程中服务器宕机,失效转移允许将该次未完成的任务在另一作业节点上补偿执行。 |
| 失效转移需要与监听作业运行时状态同时开启才可生效。 |
| 概念 失效转移是当前执行作业的临时补偿执行机制,在下次作业运行时,会通过重分片对当前作业分配进行调整。 举例说明,若作业以每小时为间隔执行,每次执行耗时 30 分钟。如下如图所示。 |
| 图中表示作业分别于 12:00,13:00 和 14:00 执行。图中显示的当前时间点为 13:00 的作业执行中。 |
| 如果作业的其中一个分片服务器在 13:10 的时候宕机,那么剩余的 20 分钟应该处理的业务未得到执行,并且需要在 14:00 时才能再次开始执行下一次作业。 也就是说,在不开启失效转移的情况下,位于该分片的作业有 50 分钟空档期。如下如图所示。 |
| 在开启失效转移功能之后,ElasticJob 的其他服务器能够在感知到宕机的作业服务器之后,补偿执行该分片作业。如下图所示。 |
| 在资源充足的情况下,作业仍然能够在 13:30 完成执行。 |
| 执行机制 当作业执行节点宕机时,会触发失效转移流程。ElasticJob 根据触发时的分布式作业执行的不同状况来决定失效转移的执行时机。 |
| 通知执行 当其他服务器感知到有失效转移的作业需要处理时,且该作业服务器已经完成了本次任务,则会实时的拉取待失效转移的分片项,并开始补偿执行。 也称为实时执行。 |
| 问询执行 作业服务在本次任务执行结束后,会向注册中心问询待执行的失效转移分片项,如果有,则开始补偿执行。 也称为异步执行。 |
| 适用场景 开启失效转移功能,ElasticJob 会监控作业每一分片的执行状态,并将其写入注册中心,供其他节点感知。 |
| 在一次运行耗时较长且间隔较长的作业场景,失效转移是提升作业运行实时性的有效手段; 对于间隔较短的作业,会产生大量与注册中心的网络通信,对集群的性能产生影响。 而且间隔较短的作业并未见得关注单次作业的实时性,可以通过下次作业执行的重分片使所有的分片正确执行,因此不建议短间隔作业开启失效转移。 |
| 另外需要注意的是,作业本身的幂等性,是保证失效转移正确性的前提。</description> |
| </item> |
| |
| <item> |
| <title>表结构说明</title> |
| <link>https://shardingsphere.apache.org/elasticjob/current/cn/user-manual/elasticjob-lite/usage/event-trace/table-structure/</link> |
| <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> |
| |
| <guid>https://shardingsphere.apache.org/elasticjob/current/cn/user-manual/elasticjob-lite/usage/event-trace/table-structure/</guid> |
| <description>事件追踪的 event_trace_rdb_url 属性对应库自动创建 JOB_EXECUTION_LOG 和 JOB_STATUS_TRACE_LOG 两张表以及若干索引。 |
| JOB_EXECUTION_LOG 字段含义 字段名称 字段类型 是否必填 描述 id VARCHAR(40) 是 主键 job_name VARCHAR(100) 是 作业名称 task_id VARCHAR(1000) 是 任务名称,每次作业运行生成新任务 hostname VARCHAR(255) 是 主机名称 ip VARCHAR(50) 是 主机IP sharding_item INT 是 分片项 execution_source VARCHAR(20) 是 作业执行来源。可选值为NORMAL_TRIGGER, MISFIRE, FAILOVER failure_cause VARCHAR(2000) 否 执行失败原因 is_success BIT 是 是否执行成功 start_time TIMESTAMP 是 作业开始执行时间 complete_time TIMESTAMP 否 作业结束执行时间 JOB_EXECUTION_LOG 记录每次作业的执行历史。 分为两个步骤:</description> |
| </item> |
| |
| <item> |
| <title>运维平台</title> |
| <link>https://shardingsphere.apache.org/elasticjob/current/cn/user-manual/elasticjob-lite/operation/web-console/</link> |
| <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> |
| |
| <guid>https://shardingsphere.apache.org/elasticjob/current/cn/user-manual/elasticjob-lite/operation/web-console/</guid> |
| <description>解压缩 elasticjob-lite-console-${version}.tar.gz 并执行 bin\start.sh。 打开浏览器访问 http://localhost:8899/ 即可访问控制台。 8899 为默认端口号,可通过启动脚本输入 -p 自定义端口号。 |
| 登录 控制台提供两种账户:管理员及访客。 管理员拥有全部操作权限,访客仅拥有察看权限。 默认管理员用户名和密码是 root/root,访客用户名和密码是 guest/guest,可通过 conf\auth.properties 修改管理员及访客用户名及密码。 |
| 功能列表 登录安全控制 注册中心、事件追踪数据源管理 快捷修改作业设置 作业和服务器维度状态查看 操作作业禁用\启用、停止和删除等生命周期 事件追踪查询 设计理念 运维平台和 ElasticJob-Lite 并无直接关系,是通过读取作业注册中心数据展现作业状态,或更新注册中心数据修改全局配置。 |
| 控制台只能控制作业本身是否运行,但不能控制作业进程的启动,因为控制台和作业本身服务器是完全分离的,控制台并不能控制作业服务器。 |
| 不支持项 添加作业 作业在首次运行时将自动添加。 ElasticJob-Lite 以 jar 方式启动,并无作业分发功能。 如需完全通过运维平台发布作业,请使用 ElasticJob-Cloud。</description> |
| </item> |
| |
| <item> |
| <title>作业属性配置</title> |
| <link>https://shardingsphere.apache.org/elasticjob/current/cn/user-manual/elasticjob-lite/configuration/props/</link> |
| <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> |
| |
| <guid>https://shardingsphere.apache.org/elasticjob/current/cn/user-manual/elasticjob-lite/configuration/props/</guid> |
| <description>简介 ElasticJob 提供属性配置的方式为不同类型的作业提供定制化配置。 |
| 作业类型 简单作业 接口名称:org.apache.shardingsphere.elasticjob.simple.job.SimpleJob |
| 可配置属性:无 |
| 数据流作业 接口名称:org.apache.shardingsphere.elasticjob.dataflow.job.DataflowJob |
| 可配置属性: |
| 名称 数据类型 说明 默认值 streaming.process boolean 是否开启流式处理 false 脚本作业 类型:SCRIPT |
| 可配置属性: |
| 名称 数据类型 说明 默认值 script.command.line String 脚本内容或运行路径 - HTTP作业 类型:HTTP |
| 可配置属性: |
| 名称 数据类型 说明 默认值 http.url String http请求url - http.method String http请求方法 - http.</description> |
| </item> |
| |
| <item> |
| <title>线路规划</title> |
| <link>https://shardingsphere.apache.org/elasticjob/current/cn/dev-manual/roadmap/</link> |
| <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> |
| |
| <guid>https://shardingsphere.apache.org/elasticjob/current/cn/dev-manual/roadmap/</guid> |
| <description>Kernel Unified Job Config API Core Config Type Config Root Config Job Types Simple Dataflow Script Http(3.0.0-beta 提供) Event Trace Event Publisher Database Event Listener Other Event Listener Unified Schedule API Unified Resource API ElasticJob-Lite Distributed Features High Availability Elastic scale in/out Failover Misfire Idempotency Reconcile Registry Center ZooKeeper Other Registry Center Supported Lifecycle Management Add/Remove Pause/Resume Disable/Enable Shutdown Restful API Web Console Job Dependency Listener DAG Spring Integrate Namespace Bean Injection Spring Boot Starter(3.</description> |
| </item> |
| |
| <item> |
| <title>错过任务重执行</title> |
| <link>https://shardingsphere.apache.org/elasticjob/current/cn/features/misfire/</link> |
| <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> |
| |
| <guid>https://shardingsphere.apache.org/elasticjob/current/cn/features/misfire/</guid> |
| <description>ElasticJob 不允许作业在同一时间内叠加执行。 当作业的执行时长超过其运行间隔,错过任务重执行能够保证作业在完成上次的任务后继续执行逾期的作业。 |
| 概念 错过任务重执行功能可以使逾期未执行的作业在之前作业执行完成之后立即执行。 举例说明,若作业以每小时为间隔执行,每次执行耗时 30 分钟。如下如图所示。 |
| 图中表示作业分别于 12:00,13:00 和 14:00 执行。图中显示的当前时间点为 13:00 的作业执行中。 |
| 如果 12:00 开始执行的作业在 13:10 才执行完毕,那么本该由 13:00 触发的作业则错过了触发时间,需要等待至 14:00 的下次作业触发。 如下如图所示。 |
| 在开启错过任务重执行功能之后,ElasticJob 将会在上次作业执行完毕后,立刻触发执行错过的作业。如下图所示。 |
| 在 13:00 和 14:00 之间错过的作业将会重新执行。 |
| 适用场景 在一次运行耗时较长且间隔较长的作业场景,错过任务重执行是提升作业运行实时性的有效手段; 对于未见得关注单次作业的实时性的短间隔的作业来说,开启错过任务重执行并无必要。</description> |
| </item> |
| |
| <item> |
| <title>作业开放生态</title> |
| <link>https://shardingsphere.apache.org/elasticjob/current/cn/features/job-type/</link> |
| <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> |
| |
| <guid>https://shardingsphere.apache.org/elasticjob/current/cn/features/job-type/</guid> |
| <description>灵活定制化作业是 ElasticJob 3.x 版本的最重要设计变革。 新版本基于 Apache ShardingSphere 可插拔架构的设计理念,打造了全新作业 API。 意在使开发者能够更加便捷且相互隔离的方式拓展作业类型,打造 ElasticJob 作业的生态圈。 |
| ElasticJob 提供了对作业的弹性伸缩、分布式治理等功能的同时,并未限定作业的类型。 它通过灵活的作业 API,将作业解耦为作业接口和执行器接口。 用户可以定制化全新的作业类型,诸如脚本执行、HTTP 服务执行(3.0.0-beta 提供)、大数据类作业、文件类作业等。 目前 ElasticJob 内置了简单作业、数据流作业和脚本执行作业,并且完全开放了扩展接口,开发者可以通过 SPI 的方式引入新的作业类型,并且可以便捷的回馈至社区。 |
| 作业接口 ElasticJob 的作业可划分为基于 class 类型和基于 type 类型两种。 |
| Class 类型的作业由开发者直接使用,需要由开发者实现该作业接口实现业务逻辑。典型代表:Simple 类型、Dataflow 类型。 Type 类型的作业只需提供类型名称即可,开发者无需实现该作业接口,而是通过外置配置的方式使用。典型代表:Script 类型、HTTP 类型。 |
| 执行器接口 用于执行用户定义的作业接口,通过 Java 的 SPI 机制织入 ElasticJob生态。</description> |
| </item> |
| |
| </channel> |
| </rss> |