diff --git a/README.md b/README.md index 8e8ab43ea..d8ea19856 100644 --- a/README.md +++ b/README.md @@ -84,7 +84,7 @@ - **支持多配置中心**:基于主流配置中心实现线程池参数动态调整,实时生效,已支持 Nacos、Apollo、Zookeeper、Consul、Etcd,同时也提供 SPI 接口可自定义扩展实现 -- **中间件线程池管理**:集成管理常用第三方组件的线程池,已集成 Tomcat、Jetty、Undertow、Dubbo、RocketMq、Hystrix、Grpc、Motan、Okhttp3 等组件的线程池管理(调参、监控报警) +- **中间件线程池管理**:集成管理常用第三方组件的线程池,已集成 Tomcat、Jetty、Undertow、Dubbo、RocketMq、Hystrix、Grpc、Motan、Okhttp3、Brpc 等组件的线程池管理(调参、监控报警) --- diff --git a/adapter/adapter-brpc/pom.xml b/adapter/adapter-brpc/pom.xml new file mode 100644 index 000000000..39ee19d9b --- /dev/null +++ b/adapter/adapter-brpc/pom.xml @@ -0,0 +1,31 @@ + + + 4.0.0 + + cn.dynamictp + dynamic-tp-adapter + 1.0.9 + + dynamic-tp-adapter-brpc + + + 2022.2.0 + + + + + cn.dynamictp + dynamic-tp-adapter-common + + + + com.baidu.cloud + spring-cloud-starter-baidu-starlight + ${brpc.version} + compile + true + + + + diff --git a/adapter/adapter-brpc/src/main/java/com/dtp/apapter/brpc/client/StarlightClientDtpAdapter.java b/adapter/adapter-brpc/src/main/java/com/dtp/apapter/brpc/client/StarlightClientDtpAdapter.java new file mode 100644 index 000000000..d5b2a0246 --- /dev/null +++ b/adapter/adapter-brpc/src/main/java/com/dtp/apapter/brpc/client/StarlightClientDtpAdapter.java @@ -0,0 +1,81 @@ +package com.dtp.apapter.brpc.client; + +import cn.hutool.core.collection.CollUtil; +import com.baidu.cloud.starlight.api.rpc.StarlightClient; +import com.baidu.cloud.starlight.api.rpc.threadpool.ThreadPoolFactory; +import com.baidu.cloud.starlight.core.rpc.SingleStarlightClient; +import com.baidu.cloud.starlight.springcloud.client.cluster.SingleStarlightClientManager; +import com.dtp.adapter.common.AbstractDtpAdapter; +import com.dtp.common.ApplicationContextHolder; +import com.dtp.common.dto.ExecutorWrapper; +import com.dtp.common.properties.DtpProperties; +import com.dtp.common.util.ReflectionUtil; +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import lombok.extern.slf4j.Slf4j; +import lombok.val; + +import java.util.List; +import java.util.Map; +import java.util.Objects; + +/** + * StarlightClientDtpAdapter related + * + * @author yanhom + * @since 1.1.0 + */ +@Slf4j +public class StarlightClientDtpAdapter extends AbstractDtpAdapter { + + private static final String NAME = "brpcClientTp"; + + private static final String THREAD_POOL_FIELD = "threadPoolOfAll"; + + @Override + public void refresh(DtpProperties dtpProperties) { + refresh(NAME, dtpProperties.getBrpcTp(), dtpProperties.getPlatforms()); + } + + @Override + protected void initialize() { + super.initialize(); + + SingleStarlightClientManager sscManager = null; + Map scBeans = Maps.newHashMap(); + try { + sscManager = ApplicationContextHolder.getBean(SingleStarlightClientManager.class); + scBeans = ApplicationContextHolder.getBeansOfType(StarlightClient.class); + } catch (Exception e) { + log.warn("getBean error, msg: {}", e.getMessage()); + } + + List starlightClients = Lists.newArrayList(); + if (CollUtil.isNotEmpty(scBeans)) { + starlightClients.addAll(scBeans.values()); + } + if (Objects.nonNull(sscManager) && CollUtil.isNotEmpty(sscManager.allSingleClients())) { + starlightClients.addAll(sscManager.allSingleClients().values()); + } + if (CollUtil.isEmpty(starlightClients)) { + log.warn("Cannot find beans of type StarlightClient."); + return; + } + + starlightClients.forEach(v -> { + val threadPoolFactory = (ThreadPoolFactory) ReflectionUtil.getFieldValue(SingleStarlightClient.class, + THREAD_POOL_FIELD, v); + if (Objects.isNull(threadPoolFactory)) { + return; + } + String bizThreadPoolName = v.remoteURI().getParameter("biz_thread_pool_name") + "#client"; + val executor = threadPoolFactory.defaultThreadPool(); + if (Objects.nonNull(executor)) { + val executorWrapper = new ExecutorWrapper(bizThreadPoolName, executor); + initNotifyItems(bizThreadPoolName, executorWrapper); + executors.put(bizThreadPoolName, executorWrapper); + } + }); + log.info("DynamicTp adapter, brpc client executors init end, executors: {}", executors); + } +} diff --git a/adapter/adapter-brpc/src/main/java/com/dtp/apapter/brpc/server/StarlightServerDtpAdapter.java b/adapter/adapter-brpc/src/main/java/com/dtp/apapter/brpc/server/StarlightServerDtpAdapter.java new file mode 100644 index 000000000..ab645d9ba --- /dev/null +++ b/adapter/adapter-brpc/src/main/java/com/dtp/apapter/brpc/server/StarlightServerDtpAdapter.java @@ -0,0 +1,77 @@ +package com.dtp.apapter.brpc.server; + +import com.baidu.cloud.starlight.api.common.URI; +import com.baidu.cloud.starlight.api.rpc.StarlightServer; +import com.baidu.cloud.starlight.api.rpc.threadpool.ThreadPoolFactory; +import com.baidu.cloud.starlight.api.transport.ServerPeer; +import com.baidu.cloud.starlight.core.rpc.DefaultStarlightServer; +import com.baidu.cloud.starlight.core.rpc.ServerProcessor; +import com.baidu.cloud.starlight.transport.netty.NettyServer; +import com.dtp.adapter.common.AbstractDtpAdapter; +import com.dtp.common.ApplicationContextHolder; +import com.dtp.common.dto.ExecutorWrapper; +import com.dtp.common.properties.DtpProperties; +import com.dtp.common.util.ReflectionUtil; +import lombok.extern.slf4j.Slf4j; +import lombok.val; + +import java.util.Objects; + +/** + * StarlightServerDtpAdapter related + * + * @author yanhom + * @since 1.1.0 + */ +@Slf4j +public class StarlightServerDtpAdapter extends AbstractDtpAdapter { + + private static final String NAME = "brpcServerTp"; + + private static final String URI_FIELD = "uri"; + + private static final String SERVER_PEER_FIELD = "serverPeer"; + + private static final String THREAD_POOL_FACTORY_FIELD = "threadPoolFactory"; + + @Override + public void refresh(DtpProperties dtpProperties) { + refresh(NAME, dtpProperties.getBrpcTp(), dtpProperties.getPlatforms()); + } + + @Override + protected void initialize() { + super.initialize(); + + val bean = ApplicationContextHolder.getBean(StarlightServer.class); + if (!(bean instanceof DefaultStarlightServer)) { + return; + } + val starlightServer = (DefaultStarlightServer) bean; + val uri = (URI) ReflectionUtil.getFieldValue(DefaultStarlightServer.class, + URI_FIELD, starlightServer); + val serverPeer = (ServerPeer) ReflectionUtil.getFieldValue(DefaultStarlightServer.class, + SERVER_PEER_FIELD, starlightServer); + + if (Objects.isNull(uri) || Objects.isNull(serverPeer) || !(serverPeer instanceof NettyServer)) { + return; + } + val processor = (ServerProcessor) serverPeer.getProcessor(); + if (Objects.isNull(processor)) { + return; + } + val threadPoolFactory = (ThreadPoolFactory) ReflectionUtil.getFieldValue(ServerProcessor.class, + THREAD_POOL_FACTORY_FIELD, processor); + if (Objects.isNull(threadPoolFactory)) { + return; + } + String bizThreadPoolName = uri.getParameter("biz_thread_pool_name") + "#server"; + val executor = threadPoolFactory.defaultThreadPool(); + if (Objects.nonNull(executor)) { + val executorWrapper = new ExecutorWrapper(bizThreadPoolName, executor); + initNotifyItems(bizThreadPoolName, executorWrapper); + executors.put(bizThreadPoolName, executorWrapper); + } + log.info("DynamicTp adapter, brpc server executors init end, executors: {}", executors); + } +} diff --git a/adapter/pom.xml b/adapter/pom.xml index 57d165492..f8282b9c8 100644 --- a/adapter/pom.xml +++ b/adapter/pom.xml @@ -19,6 +19,7 @@ adapter-grpc adapter-motan adapter-okhttp3 + adapter-brpc diff --git a/common/src/main/java/com/dtp/common/properties/DtpProperties.java b/common/src/main/java/com/dtp/common/properties/DtpProperties.java index 0c2a2e394..8c4118406 100644 --- a/common/src/main/java/com/dtp/common/properties/DtpProperties.java +++ b/common/src/main/java/com/dtp/common/properties/DtpProperties.java @@ -127,6 +127,11 @@ public class DtpProperties { */ private List okhttp3Tp; + /** + * Brpc thread pools. + */ + private List brpcTp; + /** * Notify platform configs. */ diff --git a/core/src/main/java/com/dtp/core/thread/OrderedDtpExecutor.java b/core/src/main/java/com/dtp/core/thread/OrderedDtpExecutor.java index 6aafea941..bfcb802b7 100644 --- a/core/src/main/java/com/dtp/core/thread/OrderedDtpExecutor.java +++ b/core/src/main/java/com/dtp/core/thread/OrderedDtpExecutor.java @@ -19,7 +19,6 @@ * are run in a certain order. * * @author dragon-zhang - * @date 2022/12/12 09:46 */ @Slf4j public class OrderedDtpExecutor extends DtpExecutor { diff --git a/docs/docs/README.md b/docs/docs/README.md index adedc5232..95e08be04 100644 --- a/docs/docs/README.md +++ b/docs/docs/README.md @@ -70,7 +70,7 @@ features: - **支持多配置中心**:基于主流配置中心实现线程池参数动态调整,实时生效,已支持 Nacos、Apollo、Zookeeper、Consul、Etcd,同时也提供 SPI 接口可自定义扩展实现 -- **中间件线程池管理**:集成管理常用第三方组件的线程池,已集成Tomcat、Jetty、Undertow、Dubbo、RocketMq、Hystrix、Grpc、Motan、Okhttp3 等组件的线程池管理(调参、监控报警) +- **中间件线程池管理**:集成管理常用第三方组件的线程池,已集成Tomcat、Jetty、Undertow、Dubbo、RocketMq、Hystrix、Grpc、Motan、Okhttp3、Brpc 等组件的线程池管理(调参、监控报警) # 技术架构 diff --git a/docs/docs/guide/introduction/functions.md b/docs/docs/guide/introduction/functions.md index 7406e17e8..a1d49dbe6 100644 --- a/docs/docs/guide/introduction/functions.md +++ b/docs/docs/guide/introduction/functions.md @@ -50,4 +50,4 @@ star: true - **支持多配置中心**:基于主流配置中心实现线程池参数动态调整,实时生效,已支持 Nacos、Apollo、Zookeeper、Consul、Etcd,同时也提供 SPI 接口可自定义扩展实现 -- **中间件线程池管理**:集成管理常用第三方组件的线程池,已集成Tomcat、Jetty、Undertow、Dubbo、RocketMq、Hystrix、Grpc、Motan、Okhttp3 等组件的线程池管理(调参、监控报警) +- **中间件线程池管理**:集成管理常用第三方组件的线程池,已集成Tomcat、Jetty、Undertow、Dubbo、RocketMq、Hystrix、Grpc、Motan、Okhttp3、Brpc 等组件的线程池管理(调参、监控报警) diff --git a/docs/docs/guide/middleware/middleware.md b/docs/docs/guide/middleware/middleware.md index 96ba05877..7c90f3f2c 100644 --- a/docs/docs/guide/middleware/middleware.md +++ b/docs/docs/guide/middleware/middleware.md @@ -37,6 +37,8 @@ star: true 8. Motan 线程池管理 9. Okhttp3 线程池管理 + +10. Brpc 线程池管理 ::: 依赖如下,使用时需要手动引入对应依赖 @@ -96,13 +98,21 @@ star: true 1.1.0 ``` + +```xml + + cn.dynamictp + dynamic-tp-spring-boot-starter-adapter-brpc + 1.1.0 + +``` ::: tip 1.三方组件线程池配置请参考 快速使用 / 配置文件 2.Tomcat、Jetty、Undertow 线程池目前只享有动态调参和监控功能,没通知报警功能 -3.Dubbo、RocketMq、Hystrix、Grpc、Motan、Okhttp3 享有动态调参、监控、通知告警完整的功能 +3.Dubbo、RocketMq、Hystrix、Grpc、Motan、Okhttp3、Brpc 享有动态调参、监控、通知告警完整的功能 4.注意配置时 threadPoolName 规则,配置文件有注释 diff --git a/docs/docs/guide/use/config.md b/docs/docs/guide/use/config.md index 1d55bd9a9..733e3aa03 100644 --- a/docs/docs/guide/use/config.md +++ b/docs/docs/guide/use/config.md @@ -82,11 +82,16 @@ spring: corePoolSize: 100 maximumPoolSize: 200 keepAliveTime: 60 - okhttp3Tp: # okhttp3 线程池配置 + okhttp3Tp: # okhttp3 线程池配置 - threadPoolName: okHttpClientTp corePoolSize: 100 maximumPoolSize: 200 keepAliveTime: 60 + brpcTp: # brpc 线程池配置 + - threadPoolName: biz1#server # 名称规则:biz_thread_pool_name + "#" + client/server + corePoolSize: 100 + maximumPoolSize: 200 + keepAliveTime: 60 dubboTp: # dubbo 线程池配置 - threadPoolName: dubboTp#20880 # 名称规则:dubboTp + "#" + 协议端口 threadPoolAliasName: 测试线程池 diff --git a/example/example-adapter/pom.xml b/example/example-adapter/pom.xml index 63968eed7..9f6e23ea9 100644 --- a/example/example-adapter/pom.xml +++ b/example/example-adapter/pom.xml @@ -13,6 +13,7 @@ true 1.1.13 3.14.9 + 2022.2.0 @@ -95,6 +96,12 @@ ${dtp.version} + + cn.dynamictp + dynamic-tp-spring-boot-starter-adapter-brpc + ${dtp.version} + + cn.dynamictp dynamic-tp-spring-boot-starter-extension-limiter-redis @@ -202,6 +209,17 @@ ${okhttp.version} + + com.baidu.cloud + spring-cloud-starter-baidu-starlight + ${brpc.version} + + + ch.qos.logback + logback-classic + + + diff --git a/example/example-adapter/src/main/java/com/dtp/example/adapter/ExampleAdapterApplication.java b/example/example-adapter/src/main/java/com/dtp/example/adapter/ExampleAdapterApplication.java index 4b9baa0d4..1d88951e2 100644 --- a/example/example-adapter/src/main/java/com/dtp/example/adapter/ExampleAdapterApplication.java +++ b/example/example-adapter/src/main/java/com/dtp/example/adapter/ExampleAdapterApplication.java @@ -1,5 +1,6 @@ package com.dtp.example.adapter; +import com.baidu.cloud.starlight.springcloud.server.annotation.StarlightScan; import com.dtp.core.spring.EnableDynamicTp; import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; import org.springframework.boot.SpringApplication; @@ -12,6 +13,7 @@ @EnableDubbo @ImportResource(locations = {"classpath:motan_server.xml"}) @SpringBootApplication +@StarlightScan public class ExampleAdapterApplication { public static void main(String[] args) { diff --git a/example/example-adapter/src/main/java/com/dtp/example/adapter/brpc/BrpcClientService.java b/example/example-adapter/src/main/java/com/dtp/example/adapter/brpc/BrpcClientService.java new file mode 100644 index 000000000..e6c567052 --- /dev/null +++ b/example/example-adapter/src/main/java/com/dtp/example/adapter/brpc/BrpcClientService.java @@ -0,0 +1,30 @@ +package com.dtp.example.adapter.brpc; + +import com.baidu.cloud.starlight.springcloud.client.annotation.RpcProxy; +import org.springframework.stereotype.Service; + +/** + * BrpcClientService related + * + * @author yanhom + * @since 1.1.0 + */ +@Service +public class BrpcClientService { + + /** + * 使用注解引用服务,指定服务端IP Port,采用brpc协议调用 + */ + @RpcProxy(remoteUrl = "localhost:8777", protocol = "brpc") + private UserService userService; + + /** + * 使用注解引用服务,指定服务端IP Port,采用springrest(http)协议调用 + */ + @RpcProxy(remoteUrl = "localhost:8777", protocol = "springrest") + private UserService restUserService; + + public String getUserName(Long userId) { + return userService.getUserName(userId); + } +} diff --git a/example/example-adapter/src/main/java/com/dtp/example/adapter/brpc/UserService.java b/example/example-adapter/src/main/java/com/dtp/example/adapter/brpc/UserService.java new file mode 100644 index 000000000..cb83fd3e5 --- /dev/null +++ b/example/example-adapter/src/main/java/com/dtp/example/adapter/brpc/UserService.java @@ -0,0 +1,12 @@ +package com.dtp.example.adapter.brpc; + +/** + * UserService related + * + * @author yanhom + * @since 1.1.0 + */ +public interface UserService { + + String getUserName(Long userId); +} diff --git a/example/example-adapter/src/main/java/com/dtp/example/adapter/brpc/UserServiceImpl.java b/example/example-adapter/src/main/java/com/dtp/example/adapter/brpc/UserServiceImpl.java new file mode 100644 index 000000000..c33a4a0f6 --- /dev/null +++ b/example/example-adapter/src/main/java/com/dtp/example/adapter/brpc/UserServiceImpl.java @@ -0,0 +1,18 @@ +package com.dtp.example.adapter.brpc; + +import com.baidu.cloud.starlight.springcloud.server.annotation.RpcService; + +/** + * UserServiceImpl related + * + * @author yanhom + * @since 1.1.0 + */ +@RpcService +public class UserServiceImpl implements UserService { + + @Override + public String getUserName(Long userId) { + return "dynamictp"; + } +} diff --git a/example/example-adapter/src/main/java/com/dtp/example/adapter/controller/TestController.java b/example/example-adapter/src/main/java/com/dtp/example/adapter/controller/TestController.java index adb565761..49a06bb2b 100644 --- a/example/example-adapter/src/main/java/com/dtp/example/adapter/controller/TestController.java +++ b/example/example-adapter/src/main/java/com/dtp/example/adapter/controller/TestController.java @@ -1,5 +1,6 @@ package com.dtp.example.adapter.controller; +import com.dtp.example.adapter.brpc.BrpcClientService; import com.dtp.example.adapter.dubbo.DubboUserService; import com.dtp.example.adapter.grpc.GrpcClientService; import com.dtp.example.adapter.hystrix.HystrixTester; @@ -30,6 +31,9 @@ public class TestController { @Resource private Okhttp3Service okhttp3Service; + @Resource + private BrpcClientService brpcClientService; + @GetMapping("/dtp-example-adapter/testHystrix") public String testHystrix() throws InterruptedException { return hystrixTester.testHystrix(); @@ -50,4 +54,9 @@ public String testOkhttp3() throws InterruptedException { okhttp3Service.call("https://api.bilibili.com/x/web-interface/popular?ps=20&pn=1"); return ""; } + + @GetMapping("/dtp-example-adapter/testBrpc") + public String testBrpc() throws InterruptedException { + return brpcClientService.getUserName(111L); + } } diff --git a/example/example-adapter/src/main/resources/bootstrap.yml b/example/example-adapter/src/main/resources/bootstrap.yml index 0dcb31728..279f6b979 100644 --- a/example/example-adapter/src/main/resources/bootstrap.yml +++ b/example/example-adapter/src/main/resources/bootstrap.yml @@ -46,4 +46,9 @@ grpc: address: 'discovery:///dynamic-tp-adapter-demo' enableKeepAlive: true keepAliveWithoutCalls: true - negotiationType: plaintext \ No newline at end of file + negotiationType: plaintext + +starlight: + server: + enable: true + port: 8777 \ No newline at end of file diff --git a/pom.xml b/pom.xml index 2105de074..914ccabfc 100644 --- a/pom.xml +++ b/pom.xml @@ -162,6 +162,12 @@ ${dtp.version} + + cn.dynamictp + dynamic-tp-adapter-brpc + ${dtp.version} + + cn.dynamictp dynamic-tp-extension-limiter-redis diff --git a/starter/starter-adapter/pom.xml b/starter/starter-adapter/pom.xml index a476b44d1..e90bab56c 100644 --- a/starter/starter-adapter/pom.xml +++ b/starter/starter-adapter/pom.xml @@ -19,5 +19,6 @@ starter-adapter-grpc starter-adapter-motan starter-adapter-okhttp3 + starter-adapter-brpc diff --git a/starter/starter-adapter/starter-adapter-brpc/pom.xml b/starter/starter-adapter/starter-adapter-brpc/pom.xml new file mode 100644 index 000000000..b7c403236 --- /dev/null +++ b/starter/starter-adapter/starter-adapter-brpc/pom.xml @@ -0,0 +1,23 @@ + + + 4.0.0 + + cn.dynamictp + dynamic-tp-starter-adapter + 1.0.9 + + dynamic-tp-spring-boot-starter-adapter-brpc + + + + cn.dynamictp + dynamic-tp-spring-boot-starter-adapter-common + + + + cn.dynamictp + dynamic-tp-adapter-brpc + + + diff --git a/starter/starter-adapter/starter-adapter-brpc/src/main/java/com/dtp/starter/adapter/brpc/autoconfigure/BrpcTpAutoConfiguration.java b/starter/starter-adapter/starter-adapter-brpc/src/main/java/com/dtp/starter/adapter/brpc/autoconfigure/BrpcTpAutoConfiguration.java new file mode 100644 index 000000000..f7fb7af48 --- /dev/null +++ b/starter/starter-adapter/starter-adapter-brpc/src/main/java/com/dtp/starter/adapter/brpc/autoconfigure/BrpcTpAutoConfiguration.java @@ -0,0 +1,36 @@ +package com.dtp.starter.adapter.brpc.autoconfigure; + +import com.dtp.apapter.brpc.client.StarlightClientDtpAdapter; +import com.dtp.apapter.brpc.server.StarlightServerDtpAdapter; +import com.dtp.starter.common.autoconfigure.BaseBeanAutoConfiguration; +import org.springframework.boot.autoconfigure.AutoConfigureAfter; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * BrpcTpAutoConfiguration related + * + * @author yanhom + * @since 1.1.0 + */ +@Configuration +@AutoConfigureAfter({BaseBeanAutoConfiguration.class}) +public class BrpcTpAutoConfiguration { + + @Bean + @ConditionalOnMissingBean + @ConditionalOnClass(name = "com.baidu.cloud.starlight.springcloud.client.annotation.RpcProxy") + public StarlightClientDtpAdapter starlightClientDtpAdapter() { + return new StarlightClientDtpAdapter(); + } + + @Bean + @ConditionalOnMissingBean + @ConditionalOnProperty(value = "starlight.server.enable") + public StarlightServerDtpAdapter starlightServerDtpAdapter() { + return new StarlightServerDtpAdapter(); + } +} diff --git a/starter/starter-adapter/starter-adapter-brpc/src/main/resources/META-INF/spring.factories b/starter/starter-adapter/starter-adapter-brpc/src/main/resources/META-INF/spring.factories new file mode 100644 index 000000000..adbd60333 --- /dev/null +++ b/starter/starter-adapter/starter-adapter-brpc/src/main/resources/META-INF/spring.factories @@ -0,0 +1,2 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ + com.dtp.starter.adapter.brpc.autoconfigure.BrpcTpAutoConfiguration \ No newline at end of file diff --git a/test/test-core/src/test/java/com/dtp/test/core/parse/JsonConfigParserTest.java b/test/test-core/src/test/java/com/dtp/test/core/parse/JsonConfigParserTest.java index 0cb4bbfcf..cb631ece5 100644 --- a/test/test-core/src/test/java/com/dtp/test/core/parse/JsonConfigParserTest.java +++ b/test/test-core/src/test/java/com/dtp/test/core/parse/JsonConfigParserTest.java @@ -26,7 +26,7 @@ void testDoParse() throws IOException { JsonConfigParser parser = new JsonConfigParser(); Map result = parser.doParse(content); - Assertions.assertEquals("dtpExecutor1", result.get("spring.dynamic.tp.spring.dynamic.tp.executors[0].threadPoolName").toString()); + Assertions.assertEquals("dtpExecutor1", result.get("spring.dynamic.tp.executors[0].threadPoolName").toString()); } } diff --git a/test/test-core/src/test/resources/demo-dtp-dev.json b/test/test-core/src/test/resources/demo-dtp-dev.json index 52a3e2e46..09336586d 100644 --- a/test/test-core/src/test/resources/demo-dtp-dev.json +++ b/test/test-core/src/test/resources/demo-dtp-dev.json @@ -1,128 +1,122 @@ { - "spring": { - "dynamic": { - "tp": { - "enabled": true, - "enabledBanner": true, - "enabledCollect": true, - "collectorTypes": "micrometer,logging", - "logPath": "/home/logs", - "monitorInterval": 5, - "platforms": [ - { - "platform": "wechat", - "urlKey": "3a7500-1287-4bd-a798-c5c3d8b69c", - "receivers": "test1,test2" - }, - { - "platform": "ding", - "urlKey": "f80dad441fcd655438f4a08dcd6a", - "secret": "SECb5441fa6f375d5b9d21", - "receivers": 15810119805 - }, - { - "platform": "lark", - "urlKey": "0d944ae7-b24a-40", - "receivers": "test1,test2" - } - ], - "tomcatTp": { - "corePoolSize": 100, - "maximumPoolSize": 400, - "keepAliveTime": 60 + "enabled": true, + "enabledBanner": true, + "enabledCollect": true, + "collectorTypes": "micrometer,logging", + "logPath": "/home/logs", + "monitorInterval": 5, + "platforms": [ + { + "platform": "wechat", + "urlKey": "3a7500-1287-4bd-a798-c5c3d8b69c", + "receivers": "test1,test2" + }, + { + "platform": "ding", + "urlKey": "f80dad441fcd655438f4a08dcd6a", + "secret": "SECb5441fa6f375d5b9d21", + "receivers": 15810119805 + }, + { + "platform": "lark", + "urlKey": "0d944ae7-b24a-40", + "receivers": "test1,test2" + } + ], + "tomcatTp": { + "corePoolSize": 100, + "maximumPoolSize": 400, + "keepAliveTime": 60 + }, + "jettyTp": { + "corePoolSize": 100, + "maximumPoolSize": 400 + }, + "undertowTp": { + "corePoolSize": 100, + "maximumPoolSize": 400, + "keepAliveTime": 60 + }, + "hystrixTp": [ + { + "threadPoolName": "hystrix1", + "corePoolSize": 100, + "maximumPoolSize": 400, + "keepAliveTime": 60 + } + ], + "dubboTp": [ + { + "threadPoolName": "dubboTp#20880", + "corePoolSize": 100, + "maximumPoolSize": 400, + "keepAliveTime": 60 + } + ], + "rocketMqTp": [ + { + "threadPoolName": "group1#topic1", + "corePoolSize": 200, + "maximumPoolSize": 400, + "keepAliveTime": 60 + } + ], + "executors": [ + { + "threadPoolName": "dtpExecutor1", + "executorType": "common", + "corePoolSize": 6, + "maximumPoolSize": 8, + "queueCapacity": 200, + "queueType": "VariableLinkedBlockingQueue", + "rejectedHandlerType": "CallerRunsPolicy", + "keepAliveTime": 50, + "allowCoreThreadTimeOut": false, + "threadNamePrefix": "test", + "waitForTasksToCompleteOnShutdown": false, + "awaitTerminationSeconds": 5, + "preStartAllCoreThreads": false, + "runTimeout": 200, + "queueTimeout": 100, + "taskWrapperNames": [ + "ttl" + ], + "notifyItems": [ + { + "type": "capacity", + "enabled": true, + "threshold": 80, + "platforms": [ + "ding", + "wechat" + ], + "interval": 120 + }, + { + "type": "change", + "enabled": true + }, + { + "type": "liveness", + "enabled": true, + "threshold": 80 }, - "jettyTp": { - "corePoolSize": 100, - "maximumPoolSize": 400 + { + "type": "reject", + "enabled": true, + "threshold": 1 }, - "undertowTp": { - "corePoolSize": 100, - "maximumPoolSize": 400, - "keepAliveTime": 60 + { + "type": "run_timeout", + "enabled": true, + "threshold": 1 }, - "hystrixTp": [ - { - "threadPoolName": "hystrix1", - "corePoolSize": 100, - "maximumPoolSize": 400, - "keepAliveTime": 60 - } - ], - "dubboTp": [ - { - "threadPoolName": "dubboTp#20880", - "corePoolSize": 100, - "maximumPoolSize": 400, - "keepAliveTime": 60 - } - ], - "rocketMqTp": [ - { - "threadPoolName": "group1#topic1", - "corePoolSize": 200, - "maximumPoolSize": 400, - "keepAliveTime": 60 - } - ], - "executors": [ - { - "threadPoolName": "dtpExecutor1", - "executorType": "common", - "corePoolSize": 6, - "maximumPoolSize": 8, - "queueCapacity": 200, - "queueType": "VariableLinkedBlockingQueue", - "rejectedHandlerType": "CallerRunsPolicy", - "keepAliveTime": 50, - "allowCoreThreadTimeOut": false, - "threadNamePrefix": "test", - "waitForTasksToCompleteOnShutdown": false, - "awaitTerminationSeconds": 5, - "preStartAllCoreThreads": false, - "runTimeout": 200, - "queueTimeout": 100, - "taskWrapperNames": [ - "ttl" - ], - "notifyItems": [ - { - "type": "capacity", - "enabled": true, - "threshold": 80, - "platforms": [ - "ding", - "wechat" - ], - "interval": 120 - }, - { - "type": "change", - "enabled": true - }, - { - "type": "liveness", - "enabled": true, - "threshold": 80 - }, - { - "type": "reject", - "enabled": true, - "threshold": 1 - }, - { - "type": "run_timeout", - "enabled": true, - "threshold": 1 - }, - { - "type": "queue_timeout", - "enabled": true, - "threshold": 1 - } - ] - } - ] - } + { + "type": "queue_timeout", + "enabled": true, + "threshold": 1 + } + ] } - } + ] } \ No newline at end of file