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/07/20 05:05:40 UTC

[shardingsphere-elasticjob] branch master updated: Update spring-boot-starter usage (#1185)

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 bb2e70e  Update spring-boot-starter usage (#1185)
bb2e70e is described below

commit bb2e70e8b324e08e45a16395b11246d18bf283c6
Author: Liang Zhang <te...@163.com>
AuthorDate: Mon Jul 20 13:05:31 2020 +0800

    Update spring-boot-starter usage (#1185)
    
    * Update job spring-boot-starter usage
    
    * Update event trace spring-boot-starter usage
---
 .../usage/event-trace/spring-boot-starter.cn.md    | 10 +++---
 .../usage/event-trace/spring-boot-starter.en.md    | 10 +++---
 .../usage/event-trace/spring-namespace.cn.md       | 14 +++++++-
 .../usage/event-trace/spring-namespace.en.md       | 14 ++++++--
 .../usage/job-api/spring-boot-starter.cn.md        | 24 ++++----------
 .../usage/job-api/spring-boot-starter.en.md        | 37 ++++++++--------------
 .../elasticjob-tracing-spring-boot-starter/pom.xml |  5 ++-
 7 files changed, 56 insertions(+), 58 deletions(-)

diff --git a/docs/content/user-manual/elasticjob-lite/usage/event-trace/spring-boot-starter.cn.md b/docs/content/user-manual/elasticjob-lite/usage/event-trace/spring-boot-starter.cn.md
index acab7e1..d92d86a 100644
--- a/docs/content/user-manual/elasticjob-lite/usage/event-trace/spring-boot-starter.cn.md
+++ b/docs/content/user-manual/elasticjob-lite/usage/event-trace/spring-boot-starter.cn.md
@@ -8,7 +8,7 @@ ElasticJob-Lite 提供了自动配置 TracingConfiguration 的 Tracing Spring Bo
 开发者只需注册一个 DataSource 到 Spring 容器中,
 Starter 就会自动创建一个 TracingConfiguration 并注册到 Spring 容器中。
 
-## 引入 elasticjob-tracing-spring-boot-starter
+## 引入 Maven 依赖
 
 ```xml
 <dependency>
@@ -18,9 +18,8 @@ Starter 就会自动创建一个 TracingConfiguration 并注册到 Spring 容器
 </dependency>
 ```
 
-## 借助 spring-boot-starter-jdbc 注册 DataSource
+引入 spring-boot-starter-jdbc 注册数据源。
 
-引入依赖:
 ```xml
 <dependency>
     <groupId>org.springframework.boot</groupId>
@@ -29,7 +28,8 @@ Starter 就会自动创建一个 TracingConfiguration 并注册到 Spring 容器
 </dependency>
 ```
 
-配置 DataSource:
+## 配置
+
 ```yaml
 spring:
   datasource:
@@ -39,7 +39,7 @@ spring:
     password:
 ```
 
-## 使用
+## 作业启动
 
 TracingConfiguration 会自动注册到容器中,如果与 elasticjob-lite-spring-boot-starter 配合使用,
 开发者无需进行其他额外的操作,作业启动器会自动使用创建的 TracingConfiguration。
diff --git a/docs/content/user-manual/elasticjob-lite/usage/event-trace/spring-boot-starter.en.md b/docs/content/user-manual/elasticjob-lite/usage/event-trace/spring-boot-starter.en.md
index 5a481f0..6617c87 100644
--- a/docs/content/user-manual/elasticjob-lite/usage/event-trace/spring-boot-starter.en.md
+++ b/docs/content/user-manual/elasticjob-lite/usage/event-trace/spring-boot-starter.en.md
@@ -8,7 +8,7 @@ ElasticJob-Lite provides a Spring Boot Starter to configure TracingConfiguration
 What developers need to do is register a bean of DataSource into the Spring IoC Container.
 Then the Starter will create an instance of TracingConfiguration and register it into the container.
 
-## Introduce elasticjob-tracing-spring-boot-starter dependency
+## Import Maven Dependency
 
 ```xml
 <dependency>
@@ -18,9 +18,8 @@ Then the Starter will create an instance of TracingConfiguration and register it
 </dependency>
 ```
 
-## Register DataSource via spring-boot-starter-jdbc
+Import spring-boot-starter-jdbc for DataSource register.
 
-Introduce dependency:
 ```xml
 <dependency>
     <groupId>org.springframework.boot</groupId>
@@ -29,7 +28,8 @@ Introduce dependency:
 </dependency>
 ```
 
-Configure DataSource:
+## Configuration
+
 ```yaml
 spring:
   datasource:
@@ -39,7 +39,7 @@ spring:
     password:
 ```
 
-## Usage
+## Job Start
 
 TracingConfiguration will be registered into the IoC container imperceptibly.
 If elasticjob-lite-spring-boot-starter was introduced, developers need to do nothing else. 
diff --git a/docs/content/user-manual/elasticjob-lite/usage/event-trace/spring-namespace.cn.md b/docs/content/user-manual/elasticjob-lite/usage/event-trace/spring-namespace.cn.md
index 3180343..7af9e27 100644
--- a/docs/content/user-manual/elasticjob-lite/usage/event-trace/spring-namespace.cn.md
+++ b/docs/content/user-manual/elasticjob-lite/usage/event-trace/spring-namespace.cn.md
@@ -4,7 +4,19 @@ weight = 3
 chapter = true
 +++
 
-## 事件追踪配置
+## 引入 Maven 依赖
+
+引入 elasticjob-lite-spring
+
+```xml
+<dependency>
+    <groupId>org.apache.shardingsphere.elasticjob</groupId>
+    <artifactId>elasticjob-lite-spring</artifactId>
+    <version>${elasticjob.latest.version}</version>
+</dependency>
+```
+
+## 配置
 
 ```xml
 <?xml version="1.0" encoding="UTF-8"?>
diff --git a/docs/content/user-manual/elasticjob-lite/usage/event-trace/spring-namespace.en.md b/docs/content/user-manual/elasticjob-lite/usage/event-trace/spring-namespace.en.md
index 6a63807..e88bbf7 100644
--- a/docs/content/user-manual/elasticjob-lite/usage/event-trace/spring-namespace.en.md
+++ b/docs/content/user-manual/elasticjob-lite/usage/event-trace/spring-namespace.en.md
@@ -4,7 +4,17 @@ weight = 3
 chapter = true
 +++
 
-## Event tracing configuration
+## Import Maven Dependency
+
+```xml
+<dependency>
+    <groupId>org.apache.shardingsphere.elasticjob</groupId>
+    <artifactId>elasticjob-lite-spring</artifactId>
+    <version>${elasticjob.latest.version}</version>
+</dependency>
+```
+
+## Configuration
 
 ```xml
 <?xml version="1.0" encoding="UTF-8"?>
@@ -37,7 +47,7 @@ chapter = true
 </beans>
 ```
 
-## Job start
+## Job Start
 
 If the Spring container start, the `XML` that configures the Spring namespace will be loaded, and the job will be automatically started.
 
diff --git a/docs/content/user-manual/elasticjob-lite/usage/job-api/spring-boot-starter.cn.md b/docs/content/user-manual/elasticjob-lite/usage/job-api/spring-boot-starter.cn.md
index a20d9c3..e5dd94f 100644
--- a/docs/content/user-manual/elasticjob-lite/usage/job-api/spring-boot-starter.cn.md
+++ b/docs/content/user-manual/elasticjob-lite/usage/job-api/spring-boot-starter.cn.md
@@ -15,30 +15,19 @@ ElasticJob-Lite 提供自定义的 Spring Boot Starter,可以与 Spring Boot 
 作业逻辑实现与 ElasticJob 的其他使用方式并没有较大的区别,只需将当前作业注册为 Spring 容器中的 bean。
 
 **线程安全问题**
+
 Bean 默认是单例的,如果该作业实现会在同一个进程内被创建出多个 `JobBootstrap` 的实例,
 可以考虑设置 Scope 为 `prototype`。
 
 ```java
 @Component
 public class SpringBootDataflowJob implements DataflowJob<Foo> {
-
+    
     @Override
     public List<Foo> fetchData(final ShardingContext shardingContext) {
-        switch (context.getShardingItem()) {
-            case 0:
-                List<Foo> data = // 获取“分片0”需要处理的数据
-                return data;
-            case 1:
-                List<Foo> data = // 获取“分片1”需要处理的数据
-                return data;
-            case 2:
-                List<Foo> data = // 获取“分片2”需要处理的数据
-                return data;
-            // case n: ...
-        }
-
+        // 获取数据
     }
-
+    
     @Override
     public void processData(final ShardingContext shardingContext, final List<Foo> data) {
         // 处理数据
@@ -55,6 +44,7 @@ public class SpringBootDataflowJob implements DataflowJob<Foo> {
 Starter 会根据该配置自动创建 `OneOffJobBootstrap` 或 `ScheduleJobBootstrap` 的实例并注册到 Spring 容器中。
 
 配置参考:
+
 ```yaml
 elasticjob:
   regCenter:
@@ -76,7 +66,6 @@ elasticjob:
             script.command.line: "echo SCRIPT Job: "
 ```
 
-
 ## 作业启动
 
 ### 定时调度
@@ -89,12 +78,11 @@ elasticjob:
 通过 `execute()` 方法执行作业。
 
 **关于@DependsOn注解**
+
 JobBootstrap 由 Starter 动态创建,如果依赖方的实例化时间早于 Starter 创建 JobBootstrap,将无法注入 JobBoostrap 的实例。
 
 也可以通过 ApplicationContext 获取 JobBootstrap 的 Bean。
 
-此处欢迎各位开发者提出改进方案。
-
 ```java
 @RestController
 @DependsOn("org.apache.shardingsphere.elasticjob.lite.boot.ElasticJobLiteAutoConfiguration")
diff --git a/docs/content/user-manual/elasticjob-lite/usage/job-api/spring-boot-starter.en.md b/docs/content/user-manual/elasticjob-lite/usage/job-api/spring-boot-starter.en.md
index b0ea6d1..3b81262 100644
--- a/docs/content/user-manual/elasticjob-lite/usage/job-api/spring-boot-starter.en.md
+++ b/docs/content/user-manual/elasticjob-lite/usage/job-api/spring-boot-starter.en.md
@@ -12,36 +12,26 @@ What developers need to solve distributed scheduling problem are job implementat
 
 ### Implements ElasticJob
 
-Job implementation is similar to other usage of ElasticJob. The difference is that jobs will be registered into the Spring IoC container.
+Job implementation is similar to other usage of ElasticJob. 
+The difference is that jobs will be registered into the Spring IoC container.
 
 **Thread-Safety Issue**
-Bean is singleton by default. Consider setting Bean Scope to `prototype` if the instance of ElasticJob would be used by more than a JobBootstrap.
+
+Bean is singleton by default. 
+Consider setting Bean Scope to `prototype` if the instance of ElasticJob would be used by more than a JobBootstrap.
 
 ```java
 @Component
 public class SpringBootDataflowJob implements DataflowJob<Foo> {
-
+    
     @Override
     public List<Foo> fetchData(final ShardingContext shardingContext) {
-        switch (context.getShardingItem()) {
-            case 0:
-                List<Foo> data = // get data from database by sharding item 0
-                return data;
-            case 1:
-                List<Foo> data = // get data from database by sharding item 1
-                return data;
-            case 2:
-                List<Foo> data = // get data from database by sharding item 2
-                return data;
-            // case n: ...
-        }
-
+        // fetch data
     }
-
+    
     @Override
     public void processData(final ShardingContext shardingContext, final List<Foo> data) {
         // process data
-        // ...
     }
 }
 ```
@@ -56,6 +46,7 @@ They should be configured under `elasticjob.jobs.classed`.
 The Starter will create instances of `OneOffJobBootstrap` or `ScheduleJobBootstrap` and register them into the Spring IoC container automatically. 
 
 Configuration reference:
+
 ```yaml
 elasticjob:
   regCenter:
@@ -77,7 +68,7 @@ elasticjob:
             script.command.line: "echo SCRIPT Job: "
 ```
 
-## Job start
+## Job Start
 
 ### Schedule Job
 
@@ -90,20 +81,19 @@ Developers can inject the `OneOffJobBootstrap` bean into where they plan to invo
 Trigger the job by invoking `execute()` method manually.
 
 **About @DependsOn Annotation**
+
 JobBootstraps are created by the Starter dynamically. It's unable to inject the `JobBootstrap` beans if the beans which depends on `JobBootstrap` were instantiated earlier than the instantiation of `JobBootstrap`.
 
 Developers can also retrieve `JobBootstrap` beans by ApplicationContext.
 
-Improvement is welcome.
-
 ```java
 @RestController
 @DependsOn("org.apache.shardingsphere.elasticjob.lite.boot.ElasticJobLiteAutoConfiguration")
 public class OneOffJobController {
-
+    
     @Resource(name = "manualScriptJobOneOffJobBootstrap")
     private OneOffJobBootstrap manualScriptJob;
-
+    
     @GetMapping("/execute")
     public String executeOneOffJob() {
         manualScriptJob.execute();
@@ -111,4 +101,3 @@ public class OneOffJobController {
     }
 }
 ```
-
diff --git a/elasticjob-infra/elasticjob-tracing/elasticjob-tracing-spring-boot-starter/pom.xml b/elasticjob-infra/elasticjob-tracing/elasticjob-tracing-spring-boot-starter/pom.xml
index 30a7919..e0f76da 100644
--- a/elasticjob-infra/elasticjob-tracing/elasticjob-tracing-spring-boot-starter/pom.xml
+++ b/elasticjob-infra/elasticjob-tracing/elasticjob-tracing-spring-boot-starter/pom.xml
@@ -25,9 +25,9 @@
         <version>3.0.0.M1-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
-
+    
     <artifactId>elasticjob-tracing-spring-boot-starter</artifactId>
-
+    
     <dependencies>
         <dependency>
             <groupId>org.apache.shardingsphere.elasticjob</groupId>
@@ -73,5 +73,4 @@
             <scope>test</scope>
         </dependency>
  </dependencies>
-
 </project>