This is an automated email from the ASF dual-hosted git repository.
zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere-elasticjob.git
The following commit(s) were added to refs/heads/master by this push:
new 9e34992 Add usage of error-handler for spring-namespace (#1623)
9e34992 is described below
commit 9e34992b720cbc2decdd035e4663c41151bb94b5
Author: Yanjie Zhou <[email protected]>
AuthorDate: Wed Oct 21 11:54:11 2020 +0800
Add usage of error-handler for spring-namespace (#1623)
* Revise java-api then error handler configuration to build
* Add error handel docs for spring-namespace.*.md
---
.../elasticjob-lite/usage/job-api/java-api.cn.md | 8 +-
.../elasticjob-lite/usage/job-api/java-api.en.md | 8 +-
.../usage/job-api/spring-namespace.cn.md | 66 ++++++++++++++++
.../usage/job-api/spring-namespace.en.md | 90 +++++++++++++++++++---
4 files changed, 152 insertions(+), 20 deletions(-)
diff --git
a/docs/content/user-manual/elasticjob-lite/usage/job-api/java-api.cn.md
b/docs/content/user-manual/elasticjob-lite/usage/job-api/java-api.cn.md
index 22356c1..f7a3b63 100644
--- a/docs/content/user-manual/elasticjob-lite/usage/job-api/java-api.cn.md
+++ b/docs/content/user-manual/elasticjob-lite/usage/job-api/java-api.cn.md
@@ -230,8 +230,7 @@ public class JobDemo {
private static void setEmailConfiguration(final JobConfiguration
jobConfig) {
// 设置邮件的配置
- jobConfig.getExtraConfigurations().add(new EmailConfiguration(
- "host", 465, "username", "password", true, "Test elasticJob
error message", "[email protected]", "[email protected],to2xxx.com", "[email protected]",
"[email protected]", false));
+
jobConfig.getExtraConfigurations().add(EmailConfiguration.newBuilder("host",
465, "username", "password", "[email protected]", "[email protected],to2xxx.xx").build());
}
private static CoordinatorRegistryCenter createRegistryCenter() {
@@ -280,7 +279,7 @@ public class JobDemo {
private static void setWechatConfiguration(final JobConfiguration
jobConfig) {
// 设置企业微信的配置
- jobConfig.getExtraConfigurations().add(new
WechatConfiguration("webhook", 3000, 5000));
+
jobConfig.getExtraConfigurations().add(WechatConfiguration.newBuilder("you_webhook").build());
}
private static CoordinatorRegistryCenter createRegistryCenter() {
@@ -330,8 +329,7 @@ public class JobDemo {
private static void setDingtalkConfiguration(final JobConfiguration
jobConfig) {
// 设置钉钉的配置
- jobConfig.getExtraConfigurations().add(new
DingtalkConfiguration("webhook",
- "keyword", "secret", 3000, 5000));
+
jobConfig.getExtraConfigurations().add(DingtalkConfiguration.newBuilder("you_webhook").keyword("keyword").secret("secret").build());
}
private static CoordinatorRegistryCenter createRegistryCenter() {
diff --git
a/docs/content/user-manual/elasticjob-lite/usage/job-api/java-api.en.md
b/docs/content/user-manual/elasticjob-lite/usage/job-api/java-api.en.md
index 3c1125b..793c843 100644
--- a/docs/content/user-manual/elasticjob-lite/usage/job-api/java-api.en.md
+++ b/docs/content/user-manual/elasticjob-lite/usage/job-api/java-api.en.md
@@ -229,8 +229,7 @@ public class JobDemo {
private static void setEmailConfiguration(final JobConfiguration
jobConfig) {
// Set the mail configuration.
- jobConfig.getExtraConfigurations().add(new EmailConfiguration(
- "host", 465, "username", "password", true, "Test elasticJob
error message", "[email protected]", "[email protected],to2xxx.com", "[email protected]",
"[email protected]", false));
+
jobConfig.getExtraConfigurations().add(EmailConfiguration.newBuilder("host",
465, "username", "password", "[email protected]", "[email protected],to2xxx.xx").build());
}
private static CoordinatorRegistryCenter createRegistryCenter() {
@@ -279,7 +278,7 @@ public class JobDemo {
private static void setWechatConfiguration(final JobConfiguration
jobConfig) {
// Set the configuration for the enterprise wechat.
- jobConfig.getExtraConfigurations().add(new
WechatConfiguration("webhook", 3000, 5000));
+
jobConfig.getExtraConfigurations().add(WechatConfiguration.newBuilder("you_webhook").build());
}
private static CoordinatorRegistryCenter createRegistryCenter() {
@@ -328,8 +327,7 @@ public class JobDemo {
private static void setDingtalkConfiguration(final JobConfiguration
jobConfig) {
// Set the configuration of the dingtalk.
- jobConfig.getExtraConfigurations().add(new
DingtalkConfiguration("webhook",
- "keyword", "secret", 3000, 5000));
+
jobConfig.getExtraConfigurations().add(DingtalkConfiguration.newBuilder("you_webhook").keyword("keyword").secret("secret").build());
}
private static CoordinatorRegistryCenter createRegistryCenter() {
diff --git
a/docs/content/user-manual/elasticjob-lite/usage/job-api/spring-namespace.cn.md
b/docs/content/user-manual/elasticjob-lite/usage/job-api/spring-namespace.cn.md
index eb2f98f..a10cb2c 100644
---
a/docs/content/user-manual/elasticjob-lite/usage/job-api/spring-namespace.cn.md
+++
b/docs/content/user-manual/elasticjob-lite/usage/job-api/spring-namespace.cn.md
@@ -70,3 +70,69 @@ ElasticJob-Lite 提供自定义的 Spring 命名空间,可以与 Spring 容器
<elasticjob:snapshot id="jobSnapshot" registry-center-ref="regCenter"
dump-port="9999" />
</beans>
```
+
+
+## 配置错误处理策略
+
+使用 ElasticJob-Lite 过程中当作业发生异常后,可采用以下错误处理策略。
+
+| *错误处理策略名称* | *说明* | *是否内置* | *是否默认*|
*是否需要额外配置* |
+| ----------------------- | --------------------------------- | ------- |
--------| ------------- |
+| 记录日志策略 | 记录作业异常日志,但不中断作业执行 | 是 | 是 |
|
+| 抛出异常策略 | 抛出系统异常并中断作业执行 | 是 | |
|
+| 忽略异常策略 | 忽略系统异常且不中断作业执行 | 是 | |
|
+| 邮件通知策略 | 发送邮件消息通知,但不中断作业执行 | | | 是
|
+| 企业微信通知策略 | 发送企业微信消息通知,但不中断作业执行 | | | 是
|
+| 钉钉通知策略 | 发送钉钉消息通知,但不中断作业执行 | | | 是
|
+
+以下示例用于展示如何通过 Spring 命名空间配置错误处理策略。
+
+
+```xml
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:elasticjob="http://shardingsphere.apache.org/schema/elasticjob"
+ xsi:schemaLocation="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
+ ">
+
+ <!-- 记录日志策略 -->
+ <elasticjob:job ... job-error-handler-type="LOG" />
+
+ <!-- 抛出异常策略 -->
+ <elasticjob:job ... job-error-handler-type="THROW" />
+
+ <!-- 忽略异常策略 -->
+ <elasticjob:job ... job-error-handler-type="IGNORE" />
+
+ <!-- 邮件通知策略 -->
+ <elasticjob:email-error-handler id="emailErrorHandlerConfig" host="host"
port="465" username="username"
+ password="password" use-ssl="true"
subject="ElasticJob error message"
+ from="[email protected]"
to="[email protected],[email protected]"
+ cc="[email protected]" bcc="[email protected]"
+ debug="false"/>
+
+ <elasticjob:job ... job-error-handler-type="EMAIL"
error-handler-config-ref="emailErrorHandlerConfig" />
+
+
+ <!-- 企业微信通知策略 -->
+ <elasticjob:wechat-error-handler id="wechatErrorHandlerConfig"
+ webhook="you_webhook"
+ connect-timeout-millisecond="3000"
+ read-timeout-millisecond="5000"/>
+
+ <elasticjob:job ... job-error-handler-type="WECHAT"
error-handler-config-ref="wechatErrorHandlerConfig" />
+
+ <!-- 钉钉通知策略 -->
+ <elasticjob:dingtalk-error-handler id="dingtalkErrorHandlerConfig"
+ webhook="you_webhook"
+ keyword="keyword" secret="secret"
+ connect-timeout-millisecond="3000"
+ read-timeout-millisecond="5000"/>
+
+ <elasticjob:job ... job-error-handler-type="DINGTALK"
error-handler-config-ref="dingtalkErrorHandlerConfig" />
+</beans>
+```
\ No newline at end of file
diff --git
a/docs/content/user-manual/elasticjob-lite/usage/job-api/spring-namespace.en.md
b/docs/content/user-manual/elasticjob-lite/usage/job-api/spring-namespace.en.md
index f49c070..7b0f147 100644
---
a/docs/content/user-manual/elasticjob-lite/usage/job-api/spring-namespace.en.md
+++
b/docs/content/user-manual/elasticjob-lite/usage/job-api/spring-namespace.en.md
@@ -53,15 +53,85 @@ Please refer to [Operation
Manual](/en/user-manual/elasticjob-lite/operation/dum
The example below is how to configure SnapshotService for open listener port
to dump.
-```java
-public class JobMain {
-
- public static void main(final String[] args) {
- SnapshotService snapshotService = new SnapshotService(regCenter,
9888).listen();
- }
+```xml
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:elasticjob="http://shardingsphere.apache.org/schema/elasticjob"
+ xsi:schemaLocation="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
+ ">
+ <!--Create registry center -->
+ <elasticjob:zookeeper id="regCenter" server-lists="yourhost:2181"
namespace="dd-job" base-sleep-time-milliseconds="1000"
max-sleep-time-milliseconds="3000" max-retries="3" />
- private static CoordinatorRegistryCenter createRegistryCenter() {
- // Create registry center
- }
-}
+ <!--Configure the task snapshot export service -->
+ <elasticjob:snapshot id="jobSnapshot" registry-center-ref="regCenter"
dump-port="9999" />
+</beans>
```
+
+## Configuration error handler strategy
+
+In the process of using ElasticJob-Lite, when the job is abnormal, the
following error handling strategies can be used.
+
+| *Error handler strategy name* | *Description*
| *Built-in* | *Default*| *Extra config* |
+| ---------------------------------------- |
------------------------------------------------------------- | ------- |
--------| -------------- |
+| Log Strategy | Log error and do not interrupt
job | Yes | Yes | |
+| Throw Strategy | Throw system exception and
interrupt job | Yes | |
|
+| Ignore Strategy | Ignore exception and do not
interrupt job | Yes | | |
+| Email Notification Strategy | Send email message notification
and do not interrupt job | | | Yes |
+| Wechat Enterprise Notification Strategy | Send wechat message notification
and do not interrupt job | | | Yes |
+| Dingtalk Notification Strategy | Send dingtalk message
notification and do not interrupt job | | | Yes
|
+
+The following example shows how to configure the error-handling policy through
the Spring namespace.
+
+
+```xml
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:elasticjob="http://shardingsphere.apache.org/schema/elasticjob"
+ xsi:schemaLocation="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
+ ">
+
+ <!-- Log Strategy -->
+ <elasticjob:job ... job-error-handler-type="LOG" />
+
+ <!-- Throw Strategy -->
+ <elasticjob:job ... job-error-handler-type="THROW" />
+
+ <!-- Ignore Strategy -->
+ <elasticjob:job ... job-error-handler-type="IGNORE" />
+
+ <!-- Email Notification Strategy -->
+ <elasticjob:email-error-handler id="emailErrorHandlerConfig" host="host"
port="465" username="username"
+ password="password" use-ssl="true"
subject="ElasticJob error message"
+ from="[email protected]"
to="[email protected],[email protected]"
+ cc="[email protected]" bcc="[email protected]"
+ debug="false"/>
+
+ <elasticjob:job ... job-error-handler-type="EMAIL"
error-handler-config-ref="emailErrorHandlerConfig" />
+
+
+ <!-- Wechat Enterprise Notification Strategy -->
+ <elasticjob:wechat-error-handler id="wechatErrorHandlerConfig"
+ webhook="you_webhook"
+ connect-timeout-millisecond="3000"
+ read-timeout-millisecond="5000"/>
+
+ <elasticjob:job ... job-error-handler-type="WECHAT"
error-handler-config-ref="wechatErrorHandlerConfig" />
+
+ <!-- Dingtalk Notification Strategy -->
+ <elasticjob:dingtalk-error-handler id="dingtalkErrorHandlerConfig"
+ webhook="you_webhook"
+ keyword="keyword" secret="secret"
+ connect-timeout-millisecond="3000"
+ read-timeout-millisecond="5000"/>
+
+ <elasticjob:job ... job-error-handler-type="DINGTALK"
error-handler-config-ref="dingtalkErrorHandlerConfig" />
+</beans>
+```
\ No newline at end of file