doc
This commit is contained in:
@@ -40,7 +40,7 @@
|
||||
}
|
||||
```
|
||||
|
||||
## 定时配置
|
||||
## 基本配置
|
||||
```xml
|
||||
<!--
|
||||
全局Serivce的定时任务设置,没配置该节点将自动创建一个。
|
||||
@@ -48,3 +48,37 @@
|
||||
-->
|
||||
<schedule enabled="true"/>
|
||||
```
|
||||
|
||||
|
||||
## 使用Xxl-Job
|
||||
  Schedule可以采用第三方实现, 官方扩展包```redkale-plugins```提供了xxl-job实现,且不依赖xxl-job包。
|
||||
|
||||
### pom依赖
|
||||
```xml
|
||||
<dependency>
|
||||
<groupId>org.redkalex</groupId>
|
||||
<artifactId>redkale-plugins</artifactId>
|
||||
<version>2.8.0</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
### 配置文件
|
||||
```xml
|
||||
<schedule enabled="true">
|
||||
<xxljob addresses="http://localhost:8080/xxl-job-admin"
|
||||
executorName="redkale-examples"
|
||||
ip="127.0.0.1" <!-- 可选 -->
|
||||
port="5678" <!-- 可选 -->
|
||||
accessToken="default_token" />
|
||||
</schedule>
|
||||
```
|
||||
|
||||
### 使用方法
|
||||
```java
|
||||
@Scheduled(name = "testTask")
|
||||
public void runTask(ScheduleEvent event) {
|
||||
System.out.println("xxl-job参数param: " + event.getString("param"));
|
||||
System.out.println("xxl-job参数index: " + event.getInteger("index"));
|
||||
System.out.println("xxl-job参数total: " + event.getInteger("total"));
|
||||
}
|
||||
```
|
||||
@@ -881,7 +881,7 @@ public final class Application {
|
||||
listener.onPreStart(this);
|
||||
}
|
||||
for (ModuleEngine item : moduleEngines) {
|
||||
item.onAppPostInit();
|
||||
item.onAppPreStart();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
*/
|
||||
package org.redkale.schedule;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.redkale.convert.json.JsonConvert;
|
||||
@@ -36,6 +37,11 @@ public final class ScheduleEvent {
|
||||
return (T) map.get(name);
|
||||
}
|
||||
|
||||
public <T> T getJson(String name, Type type) {
|
||||
Object obj = get(name);
|
||||
return obj == null ? null : JsonConvert.root().convertFrom(type, obj.toString());
|
||||
}
|
||||
|
||||
public String getString(String name) {
|
||||
return Utility.convertValue(String.class, map.get(name));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user