You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2020/08/11 08:34:57 UTC
[shardingsphere-elasticjob] branch master updated: Add Http job doc
(#1356) (#1357)
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 c43c63f Add Http job doc (#1356) (#1357)
c43c63f is described below
commit c43c63fd25e9adb7cf27669ce1d0c8c268636412
Author: Tboy <gu...@immomo.com>
AuthorDate: Tue Aug 11 16:34:42 2020 +0800
Add Http job doc (#1356) (#1357)
---
docs/content/faq/_index.cn.md | 5 +++
docs/content/faq/_index.en.md | 6 ++++
.../elasticjob-lite/configuration/props.cn.md | 16 +++++++++
.../elasticjob-lite/configuration/props.en.md | 15 +++++++++
.../usage/job-api/job-interface.cn.md | 38 +++++++++++++++++++++-
.../usage/job-api/job-interface.en.md | 35 ++++++++++++++++++++
.../elasticjob/http/executor/HttpJobExecutor.java | 2 +-
.../elasticjob/http/props/HttpJobProperties.java | 12 +++----
8 files changed, 121 insertions(+), 8 deletions(-)
diff --git a/docs/content/faq/_index.cn.md b/docs/content/faq/_index.cn.md
index 7e0998d..17d680d 100644
--- a/docs/content/faq/_index.cn.md
+++ b/docs/content/faq/_index.cn.md
@@ -87,3 +87,8 @@ ElasticJob 已将 IP 地址等敏感信息过滤,导出的信息可在公网
回答:
分片待调整表示作业已启动但尚未获得分片时的状态。
+
+## 11. 为什么首次启动存在任务调度延迟的情况?
+
+回答:
+ElasticJob 执行任务会获取本机IP,首次可能存在获取IP较慢的情况。尝试设置-Djava.net.preferIPv4Stack=true.
diff --git a/docs/content/faq/_index.en.md b/docs/content/faq/_index.en.md
index d29fc40..d8875a1 100644
--- a/docs/content/faq/_index.en.md
+++ b/docs/content/faq/_index.en.md
@@ -87,3 +87,9 @@ Make sure that the `Web Console`'s version is consistent with `ElasticJob`, othe
Answer:
Shard to be adjusted indicates the state when the job has started but has not yet obtained the shard.
+
+## 11. Why is there a task scheduling delay in the first startup?
+
+Answer:
+
+ElasticJob will obtain the local IP when performing task scheduling, and it may be slow to obtain the IP for the first time. Try to set -Djava.net.preferIPv4Stack=true.
diff --git a/docs/content/user-manual/elasticjob-lite/configuration/props.cn.md b/docs/content/user-manual/elasticjob-lite/configuration/props.cn.md
index 67ab1eb..8500670 100644
--- a/docs/content/user-manual/elasticjob-lite/configuration/props.cn.md
+++ b/docs/content/user-manual/elasticjob-lite/configuration/props.cn.md
@@ -35,3 +35,19 @@ ElasticJob 提供属性配置的方式为不同类型的作业提供定制化配
| *名称* | *数据类型* | *说明* | *默认值* |
| ------------------- | ----------- | ---------------- | -------- |
| script.command.line | String | 脚本内容或运行路径 | - |
+
+### HTTP作业
+
+类型:HTTP
+
+可配置属性:
+
+| *名称* | *数据类型* | *说明* | *默认值* |
+| ----------------------------------- | ----------- | ------------------ | -------- |
+| http.url | String | http请求url | - |
+| http.method | String | http请求方法 | - |
+| http.data | String | http请求数据 | - |
+| http.connect.timeout.milliseconds | String | http连接超时 | 3000 |
+| http.read.timeout.milliseconds | String | http读超时 | 5000 |
+| http.content.type | String | http请求ContentType | - |
+
diff --git a/docs/content/user-manual/elasticjob-lite/configuration/props.en.md b/docs/content/user-manual/elasticjob-lite/configuration/props.en.md
index 56d7730..ea47d8e 100644
--- a/docs/content/user-manual/elasticjob-lite/configuration/props.en.md
+++ b/docs/content/user-manual/elasticjob-lite/configuration/props.en.md
@@ -35,3 +35,18 @@ Configuration:
| *Name* | *Data Type* | *Description* | *Default Value* |
| -------------------- | ------------- | ----------------------- | ---------------- |
| script.command.line | String | Script content or path | - |
+
+### HTTP Job
+
+Type:`HTTP`
+
+Configuration:
+
+| *Name* | *Data Type* | *Description* | *Default Value* |
+| ---------------------------------- | ----------- | ---------------- | -------- |
+| http.url | String | http request url | - |
+| http.method | String | http request method | - |
+| http.data | String | http request data | - |
+| http.connect.timeout.milliseconds | String | http connect timeout | 3000 |
+| http.read.timeout.milliseconds | String | http read timeout | 5000 |
+| http.content.type | String | http content type | - |
diff --git a/docs/content/user-manual/elasticjob-lite/usage/job-api/job-interface.cn.md b/docs/content/user-manual/elasticjob-lite/usage/job-api/job-interface.cn.md
index 793a355..23af1f9 100644
--- a/docs/content/user-manual/elasticjob-lite/usage/job-api/job-interface.cn.md
+++ b/docs/content/user-manual/elasticjob-lite/usage/job-api/job-interface.cn.md
@@ -13,7 +13,7 @@ ElasticJob 的作业分类基于 class 和 type 两种类型。
基于 class 的作业接口的方法参数 `shardingContext` 包含作业配置、片和运行时信息。
可通过 `getShardingTotalCount()`, `getShardingItem()` 等方法分别获取分片总数,运行在本作业服务器的分片序列号等。
-ElasticJob 目前提供 Simple、Dataflow 这两种基于 class 的作业类型,并提供 Script 这一种基于 type 的作业类型,用户可通过实现 SPI 接口自行扩展作业类型。
+ElasticJob 目前提供 Simple、Dataflow 这两种基于 class 的作业类型,并提供 Script、HTTP 这两种基于 type 的作业类型,用户可通过实现 SPI 接口自行扩展作业类型。
## 简单作业
@@ -103,3 +103,39 @@ echo sharding execution context is $*
```
sharding execution context is {"jobName":"scriptElasticDemoJob","shardingTotalCount":10,"jobParameter":"","shardingItem":0,"shardingParameter":"A"}
```
+
+## HTTP作业
+
+可通过属性配置`http.url`,`http.method`,`http.data`等配置待请求的http信息。
+如果设置了`http.data`, 分片信息也将以`shardingContext`为key传递到url接口,值为json格式。
+
+```java
+
+public class HttpJobMain {
+
+ public static void main(String[] args) {
+
+ new ScheduleJobBootstrap(regCenter, "HTTP", JobConfiguration.newBuilder("javaHttpJob", 1)
+ .setProperty(HttpJobProperties.URI_KEY, "http://xxx.com/execute")
+ .setProperty(HttpJobProperties.METHOD_KEY, "POST")
+ .setProperty(HttpJobProperties.DATA_KEY, "source=ejob")
+ .cron("0/5 * * * * ?").shardingItemParameters("0=Beijing").build()).schedule();
+ }
+}
+```
+```java
+@Controller
+@Slf4j
+public class HttpJobController {
+
+ @RequestMapping(path = "/execute", method = RequestMethod.POST)
+ public void execute(String source, String shardingContext) {
+ log.info("execute from source : {}, shardingContext : {}", source, shardingContext);
+ }
+}
+```
+
+execute接口将输出:
+```
+execute from source : ejob, shardingContext : {"jobName":"scriptElasticDemoJob","shardingTotalCount":3,"jobParameter":"","shardingItem":0,"shardingParameter":"Beijing"}
+```
diff --git a/docs/content/user-manual/elasticjob-lite/usage/job-api/job-interface.en.md b/docs/content/user-manual/elasticjob-lite/usage/job-api/job-interface.en.md
index 7c93c2f..4fa7217 100644
--- a/docs/content/user-manual/elasticjob-lite/usage/job-api/job-interface.en.md
+++ b/docs/content/user-manual/elasticjob-lite/usage/job-api/job-interface.en.md
@@ -104,3 +104,38 @@ When the job runs, it will output:
sharding execution context is {"jobName":"scriptElasticDemoJob","shardingTotalCount":10,"jobParameter":"","shardingItem":0,"shardingParameter":"A"}
```
+## HTTP job
+
+The http information to be requested can be configured through the properties of `http.url`, `http.method`, `http.data`, etc.
+If `http.data` is set, sharding information will also be passed to the url interface with `shardingContext` as the key, and the value is in json format.
+
+```java
+
+public class HttpJobMain {
+
+ public static void main(String[] args) {
+
+ new ScheduleJobBootstrap(regCenter, "HTTP", JobConfiguration.newBuilder("javaHttpJob", 1)
+ .setProperty(HttpJobProperties.URI_KEY, "http://xxx.com/execute")
+ .setProperty(HttpJobProperties.METHOD_KEY, "POST")
+ .setProperty(HttpJobProperties.DATA_KEY, "source=ejob")
+ .cron("0/5 * * * * ?").shardingItemParameters("0=Beijing").build()).schedule();
+ }
+}
+```
+```java
+@Controller
+@Slf4j
+public class HttpJobController {
+
+ @RequestMapping(path = "/execute", method = RequestMethod.POST)
+ public void execute(String source, String shardingContext) {
+ log.info("execute from source : {}, shardingContext : {}", source, shardingContext);
+ }
+}
+```
+
+When the job runs, it will output:
+```
+execute from source : ejob, shardingContext : {"jobName":"scriptElasticDemoJob","shardingTotalCount":3,"jobParameter":"","shardingItem":0,"shardingParameter":"Beijing"}
+```
diff --git a/elasticjob-executor/elasticjob-executor-type/elasticjob-http-executor/src/main/java/org/apache/shardingsphere/elasticjob/http/executor/HttpJobExecutor.java b/elasticjob-executor/elasticjob-executor-type/elasticjob-http-executor/src/main/java/org/apache/shardingsphere/elasticjob/http/executor/HttpJobExecutor.java
index 1833f7b..63b735d 100644
--- a/elasticjob-executor/elasticjob-executor-type/elasticjob-http-executor/src/main/java/org/apache/shardingsphere/elasticjob/http/executor/HttpJobExecutor.java
+++ b/elasticjob-executor/elasticjob-executor-type/elasticjob-http-executor/src/main/java/org/apache/shardingsphere/elasticjob/http/executor/HttpJobExecutor.java
@@ -64,7 +64,7 @@ public final class HttpJobExecutor implements TypedJobItemExecutor {
String data = httpParam.getData();
if (!Strings.isNullOrEmpty(data)) {
StringBuilder builder = new StringBuilder(data);
- builder.append("&").append(HttpJobProperties.TRANSPARENT_SHARDING_CONTEXT_KEY);
+ builder.append("&").append(HttpJobProperties.SHARDING_CONTEXT_KEY);
builder.append("=").append(GsonFactory.getGson().toJson(shardingContext));
data = builder.toString();
DataOutputStream dataOutputStream = new DataOutputStream(connection.getOutputStream());
diff --git a/elasticjob-executor/elasticjob-executor-type/elasticjob-http-executor/src/main/java/org/apache/shardingsphere/elasticjob/http/props/HttpJobProperties.java b/elasticjob-executor/elasticjob-executor-type/elasticjob-http-executor/src/main/java/org/apache/shardingsphere/elasticjob/http/props/HttpJobProperties.java
index 27bcf5f..221e651 100644
--- a/elasticjob-executor/elasticjob-executor-type/elasticjob-http-executor/src/main/java/org/apache/shardingsphere/elasticjob/http/props/HttpJobProperties.java
+++ b/elasticjob-executor/elasticjob-executor-type/elasticjob-http-executor/src/main/java/org/apache/shardingsphere/elasticjob/http/props/HttpJobProperties.java
@@ -38,14 +38,14 @@ public final class HttpJobProperties {
public static final String DATA_KEY = "http.data";
/**
- * Http connect timeout.
+ * Http connect timeout in milliseconds.
*/
- public static final String CONNECT_TIMEOUT_KEY = "http.connect.timeout";
+ public static final String CONNECT_TIMEOUT_KEY = "http.connect.timeout.milliseconds";
/**
- * Http read timeout.
+ * Http read timeout in milliseconds.
*/
- public static final String READ_TIMEOUT_KEY = "http.read.timeout";
+ public static final String READ_TIMEOUT_KEY = "http.read.timeout.milliseconds";
/**
* Http content type.
@@ -53,7 +53,7 @@ public final class HttpJobProperties {
public static final String CONTENT_TYPE_KEY = "http.content.type";
/**
- * Http transparent sharding context.
+ * Http sharding context.
*/
- public static final String TRANSPARENT_SHARDING_CONTEXT_KEY = "shardingContext";
+ public static final String SHARDING_CONTEXT_KEY = "shardingContext";
}