Skip to content

Commit

Permalink
support liteflow executors
Browse files Browse the repository at this point in the history
  • Loading branch information
yanhom1314 committed Sep 11, 2024
1 parent 3d9bf57 commit 48b09d3
Show file tree
Hide file tree
Showing 16 changed files with 355 additions and 3 deletions.
1 change: 0 additions & 1 deletion adapter/adapter-liteflow/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
<dependency>
<groupId>com.yomahub</groupId>
<artifactId>liteflow-core</artifactId>
<version>2.12.3</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
* @since 1.1.0
*/
@Slf4j
@SuppressWarnings("unchecked")
@SuppressWarnings("all")
public class LiteflowDtpAdapter extends AbstractDtpAdapter {

private static final String TP_PREFIX = "liteflowTp";
Expand Down Expand Up @@ -70,7 +70,13 @@ protected void initialize() {
executorMap.forEach((k, v) -> {
String key = k.substring(k.lastIndexOf(".") + 1);
val tpName = TP_PREFIX + "#" + key;
ThreadPoolExecutorProxy proxy = new ThreadPoolExecutorProxy((ThreadPoolExecutor) v);
ThreadPoolExecutor executor;
if (v instanceof ThreadPoolExecutor) {
executor = (ThreadPoolExecutor) v;
} else {
executor = (ThreadPoolExecutor) ReflectionUtil.getFieldValue("executorService", v);
}
ThreadPoolExecutorProxy proxy = new ThreadPoolExecutorProxy(executor);
newExecutorMap.put(k, proxy);
executors.put(tpName, new ExecutorWrapper(tpName, proxy));
});
Expand Down
18 changes: 18 additions & 0 deletions dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<equator.version>1.0.4</equator.version>

<sofa-rpc.version>5.9.1</sofa-rpc.version>
<liteflow.version>2.12.3</liteflow.version>
<brpc.version>2022.2.0</brpc.version>
<apache-dubbo.version>3.0.7</apache-dubbo.version>
<alibaba-dubbo.version>2.6.0</alibaba-dubbo.version>
Expand Down Expand Up @@ -226,6 +227,12 @@
<version>${sofa-rpc.version}</version>
</dependency>

<dependency>
<groupId>com.yomahub</groupId>
<artifactId>liteflow-core</artifactId>
<version>${liteflow.version}</version>
</dependency>

<dependency>
<groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo-client</artifactId>
Expand Down Expand Up @@ -420,6 +427,12 @@
<version>${revision}</version>
</dependency>

<dependency>
<groupId>org.dromara.dynamictp</groupId>
<artifactId>dynamic-tp-adapter-liteflow</artifactId>
<version>${revision}</version>
</dependency>

<dependency>
<groupId>org.dromara.dynamictp</groupId>
<artifactId>dynamic-tp-extension-limiter-redis</artifactId>
Expand Down Expand Up @@ -579,6 +592,11 @@
<artifactId>dynamic-tp-spring-boot-starter-adapter-rabbitmq</artifactId>
<version>${revision}</version>
</dependency>
<dependency>
<groupId>org.dromara.dynamictp</groupId>
<artifactId>dynamic-tp-spring-boot-starter-adapter-liteflow</artifactId>
<version>${revision}</version>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down
45 changes: 45 additions & 0 deletions example/example-adapter/example-adapter-liteflow/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>dynamic-tp-example-adapter</artifactId>
<groupId>org.dromara.dynamictp</groupId>
<version>${revision}</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>dynamic-tp-example-adapter-liteflow</artifactId>

<properties>
<maven.deploy.skip>true</maven.deploy.skip>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</dependency>

<dependency>
<groupId>com.yomahub</groupId>
<artifactId>liteflow-spring-boot-starter</artifactId>
<version>2.12.3</version>
</dependency>

<dependency>
<groupId>org.dromara.dynamictp</groupId>
<artifactId>dynamic-tp-spring-boot-starter-adapter-liteflow</artifactId>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>

</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.dromara.dynamictp.example;

import org.dromara.dynamictp.core.spring.EnableDynamicTp;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
* LiteflowExampleApplication related
*
* @author yanhom
* @since 1.1.0
*/
@EnableDynamicTp
@SpringBootApplication
public class LiteflowExampleApplication {

public static void main(String[] args) {
SpringApplication.run(LiteflowExampleApplication.class, args);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.dromara.dynamictp.example.cmp;

import com.yomahub.liteflow.core.NodeComponent;
import org.springframework.stereotype.Component;

/**
* ACmp related
*
* @author yanhom
* @since 1.1.0
*/
@Component("a")
public class ACmp extends NodeComponent {

@Override
public void process() {
//do your business
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.dromara.dynamictp.example.cmp;

import com.yomahub.liteflow.core.NodeComponent;
import org.springframework.stereotype.Component;

/**
* BCmp related
*
* @author yanhom
* @since 1.1.0
*/
@Component("b")
public class BCmp extends NodeComponent {

@Override
public void process() {
//do your business
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.dromara.dynamictp.example.cmp;

import com.yomahub.liteflow.core.NodeComponent;
import org.springframework.stereotype.Component;

/**
* CCmp related
*
* @author yanhom
* @since 1.1.0
*/
@Component("c")
public class CCmp extends NodeComponent {

@Override
public void process() {
//do your business
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.dromara.dynamictp.example.controller;

import lombok.extern.slf4j.Slf4j;
import org.dromara.dynamictp.example.service.BizService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
* TestController related
*
* @author yanhom
* @since 1.1.0
*/
@Slf4j
@RestController
@SuppressWarnings("all")
public class TestController {

@Resource
private BizService bizService;

@GetMapping("/dtp-example-adapter/testLiteflow")
public String testLiteflow() throws InterruptedException {
bizService.testConfig();
return "success";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.dromara.dynamictp.example.service;

import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.flow.LiteflowResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
* BizService related
*
* @author yanhom
* @since 1.1.0
*/
@Slf4j
@Service
public class BizService {

@Resource
private FlowExecutor flowExecutor;

public void testConfig(){
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
log.info("response:{}", response);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
server:
port: 9119

liteflow:
rule-source: config/flow.el.xml

spring:
application:
name: dynamic-tp-adapter-liteflow-demo
profiles:
active: dev

dynamic:
tp:
enabled: true
enabledCollect: true # 是否开启监控指标采集,默认false
collectorTypes: logging # 监控数据采集器类型(logging | micrometer | internal_logging),默认micrometer
monitorInterval: 5
liteflowTp: # 通知报警平台配置
- threadPoolName: liteflowTp#LiteFlowDefaultWhenExecutorBuilder
corePoolSize: 10
maximumPoolSize: 20
keepAliveTime: 60

# 开启 SpringBoot Actuator Endpoint 暴露出DynamicTp指标接口
# 开启 prometheus 指标采集端点
management:
metrics:
export:
prometheus:
enabled: true
endpoints:
web:
exposure:
include: '*' # 测试使用,线上不要用*,按需开启
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<flow>
<chain name="chain1">
WHEN(a, b, c);
</chain>
</flow>
1 change: 1 addition & 0 deletions starter/starter-adapter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<module>starter-adapter-tars</module>
<module>starter-adapter-sofa</module>
<module>starter-adapter-rabbitmq</module>
<module>starter-adapter-liteflow</module>
</modules>

<dependencies>
Expand Down
24 changes: 24 additions & 0 deletions starter/starter-adapter/starter-adapter-liteflow/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.dromara.dynamictp</groupId>
<artifactId>dynamic-tp-starter-adapter</artifactId>
<version>${revision}</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>dynamic-tp-spring-boot-starter-adapter-liteflow</artifactId>

<dependencies>
<dependency>
<groupId>org.dromara.dynamictp</groupId>
<artifactId>dynamic-tp-spring-boot-starter-adapter-common</artifactId>
</dependency>

<dependency>
<groupId>org.dromara.dynamictp</groupId>
<artifactId>dynamic-tp-adapter-liteflow</artifactId>
</dependency>
</dependencies>
</project>
Loading

0 comments on commit 48b09d3

Please sign in to comment.