From 9cab0760dc3fe7958dee498e0e72ef87540cfa8b Mon Sep 17 00:00:00 2001 From: yanhom Date: Sat, 16 Dec 2023 15:12:09 +0800 Subject: [PATCH] optimize cloud refresher and perfect example --- .../core/refresher/AbstractRefresher.java | 23 ++++++++++-- .../src/main/resources/application.yml | 36 +++++++----------- .../src/main/resources/application.yml | 34 ++++++----------- .../src/main/resources/application.yml | 34 ++++++----------- .../src/main/resources/application.yml | 34 ++++++----------- .../src/main/resources/application.yml | 34 ++++++----------- .../src/main/resources/application.yml | 37 +++++++------------ .../src/main/resources/application.yml | 33 ++++++----------- .../src/main/resources/application.yml | 33 ++++++----------- .../src/main/resources/application.yml | 14 ++++++- .../src/main/resources/application.yml | 24 ++++++------ .../src/main/resources/application.yml | 34 +++++++---------- .../src/main/resources/application.yml | 27 +++++++++++++- .../src/main/resources/application.yml | 27 +++++++------- .../src/main/resources/bootstrap.yml | 27 +++++++------- .../src/main/resources/application.yml | 14 +++++-- .../src/main/resources/bootstrap.yml | 14 ++++++- .../src/main/resources/bootstrap.yml | 2 + .../src/main/resources/application.yml | 27 ++++++-------- .../src/main/resources/bootstrap.yml | 4 +- .../src/main/resources/bootstrap.yml | 14 ++++++- .../src/main/resources/application.yml | 15 ++++++-- .../DtpConsulAutoConfiguration.java | 7 ++-- .../refresher/CloudConsulRefresher.java | 11 ++++-- .../DtpHuaweiAutoConfiguration.java | 7 ++-- .../refresher/CloudHuaweiRefresher.java | 12 ++++-- .../DtpCloudNacosAutoConfiguration.java | 7 ++-- .../nacos/refresher/CloudNacosRefresher.java | 11 ++++-- .../DtpPolarisAutoConfiguration.java | 9 +++-- .../refresher/CloudPolarisRefresher.java | 11 ++++-- .../DtpCloudZkAutoConfiguration.java | 7 ++-- .../refresher/CloudZookeeperRefresher.java | 11 ++++-- .../DtpApolloAutoConfiguration.java | 7 ++-- .../apollo/refresher/ApolloRefresher.java | 5 +++ .../DtpEtcdAutoConfiguration.java | 7 ++-- .../starter/etcd/refresher/EtcdRefresher.java | 4 ++ .../DtpNacosAutoConfiguration.java | 5 ++- .../nacos/refresher/NacosRefresher.java | 7 +++- .../autoconfigure/DtpZkAutoConfiguration.java | 7 +++- .../refresher/ZookeeperRefresher.java | 5 +++ .../NotifyEmailAutoConfiguration.java | 1 - 41 files changed, 365 insertions(+), 317 deletions(-) diff --git a/core/src/main/java/org/dromara/dynamictp/core/refresher/AbstractRefresher.java b/core/src/main/java/org/dromara/dynamictp/core/refresher/AbstractRefresher.java index cf4b7795f..c4de0ba65 100644 --- a/core/src/main/java/org/dromara/dynamictp/core/refresher/AbstractRefresher.java +++ b/core/src/main/java/org/dromara/dynamictp/core/refresher/AbstractRefresher.java @@ -19,6 +19,7 @@ import lombok.extern.slf4j.Slf4j; import lombok.val; +import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.StringUtils; import org.dromara.dynamictp.common.em.ConfigFileTypeEnum; @@ -31,10 +32,13 @@ import org.springframework.context.EnvironmentAware; import org.springframework.core.env.Environment; -import javax.annotation.Resource; import java.io.IOException; import java.util.Map; import java.util.Objects; +import java.util.Set; +import java.util.stream.Collectors; + +import static org.dromara.dynamictp.common.constant.DynamicTpConst.MAIN_PROPERTIES_PREFIX; /** * AbstractRefresher related @@ -45,11 +49,14 @@ @Slf4j public abstract class AbstractRefresher implements Refresher, EnvironmentAware { - @Resource - protected DtpProperties dtpProperties; + protected final DtpProperties dtpProperties; protected Environment environment; + protected AbstractRefresher(DtpProperties dtpProperties) { + this.dtpProperties = dtpProperties; + } + @Override public void setEnvironment(Environment environment) { this.environment = environment; @@ -91,6 +98,16 @@ protected void doRefresh(DtpProperties properties) { publishEvent(properties); } + protected boolean needRefresh(Set keys) { + if (CollectionUtils.isEmpty(keys)) { + return false; + } + keys = keys.stream() + .filter(str -> str.startsWith(MAIN_PROPERTIES_PREFIX)) + .collect(Collectors.toSet()); + return CollectionUtils.isNotEmpty(keys); + } + private void publishEvent(DtpProperties dtpProperties) { RefreshEvent event = new RefreshEvent(this, dtpProperties); ApplicationContextHolder.publishEvent(event); diff --git a/example/example-adapter/example-adapter-brpc/src/main/resources/application.yml b/example/example-adapter/example-adapter-brpc/src/main/resources/application.yml index 88db9514a..3e3c4a1b6 100644 --- a/example/example-adapter/example-adapter-brpc/src/main/resources/application.yml +++ b/example/example-adapter/example-adapter-brpc/src/main/resources/application.yml @@ -24,35 +24,25 @@ spring: - platform: lark urlKey: 0d944ae7-b24a-40 # 替换 receivers: test1,test2 # 接受人飞书名称/openid - - platform: email - receivers: 123456@qq.com,789789@qq.com # 收件人 brpcTp: # brpc 线程池配置 - threadPoolName: rpc#server # 名称规则:biz_thread_pool_name + "#" + client/server corePoolSize: 100 maximumPoolSize: 200 keepAliveTime: 60 - # email notify configuration - mail: - # (optional) email subject, default:ThreadPool Notify - title: ThreadPool Notify - # mail service address - host: smtp.qq.com - port: 465 - # send from - username: 123456@qq.com - # authorization code eg: rlpadadtcugh4152e - password: xxxxxxxxxxxxxxxx - default-encoding: UTF-8 - properties: - mail: - smtp: - socketFactoryClass: javax.net.ssl.SSLSocketFactory - ssl: - enable: true - debug: false - starlight: server: enable: true - port: 8777 \ No newline at end of file + port: 8777 + +# 开启 SpringBoot Actuator Endpoint 暴露出DynamicTp指标接口 +# 开启 prometheus 指标采集端点 +management: + metrics: + export: + prometheus: + enabled: true + endpoints: + web: + exposure: + include: '*' # 测试使用,线上不要用*,按需开启 diff --git a/example/example-adapter/example-adapter-dubbo/example-adapter-alibaba-dubbo/src/main/resources/application.yml b/example/example-adapter/example-adapter-dubbo/example-adapter-alibaba-dubbo/src/main/resources/application.yml index 8db68fb0e..9c39fb9db 100644 --- a/example/example-adapter/example-adapter-dubbo/example-adapter-alibaba-dubbo/src/main/resources/application.yml +++ b/example/example-adapter/example-adapter-dubbo/example-adapter-alibaba-dubbo/src/main/resources/application.yml @@ -24,8 +24,6 @@ spring: - platform: lark urlKey: 0d944ae7-b24a-40 # 替换 receivers: test1,test2 # 接受人飞书名称/openid - - platform: email - receivers: 123456@qq.com,789789@qq.com # 收件人 dubboTp: # dubbo 线程池配置 - threadPoolName: dubboTp#20880 # 名称规则:dubboTp + "#" + 协议端口 threadPoolAliasName: 测试线程池 @@ -33,26 +31,6 @@ spring: maximumPoolSize: 200 keepAliveTime: 60 - # email notify configuration - mail: - # (optional) email subject, default:ThreadPool Notify - title: ThreadPool Notify - # mail service address - host: smtp.qq.com - port: 465 - # send from - username: 123456@qq.com - # authorization code eg: rlpadadtcugh4152e - password: xxxxxxxxxxxxxxxx - default-encoding: UTF-8 - properties: - mail: - smtp: - socketFactoryClass: javax.net.ssl.SSLSocketFactory - ssl: - enable: true - debug: false - dubbo: application: name: dynamic-tp-adapter-demo @@ -63,3 +41,15 @@ dubbo: protocol: name: dubbo port: 20880 + +# 开启 SpringBoot Actuator Endpoint 暴露出DynamicTp指标接口 +# 开启 prometheus 指标采集端点 +management: + metrics: + export: + prometheus: + enabled: true + endpoints: + web: + exposure: + include: '*' # 测试使用,线上不要用*,按需开启 \ No newline at end of file diff --git a/example/example-adapter/example-adapter-dubbo/example-adapter-apache-dubbo/example-adapter-apache-dubbo-2.7.3/src/main/resources/application.yml b/example/example-adapter/example-adapter-dubbo/example-adapter-apache-dubbo/example-adapter-apache-dubbo-2.7.3/src/main/resources/application.yml index 2a61b1483..7cb1f62e8 100644 --- a/example/example-adapter/example-adapter-dubbo/example-adapter-apache-dubbo/example-adapter-apache-dubbo-2.7.3/src/main/resources/application.yml +++ b/example/example-adapter/example-adapter-dubbo/example-adapter-apache-dubbo/example-adapter-apache-dubbo-2.7.3/src/main/resources/application.yml @@ -10,7 +10,6 @@ spring: dynamic: tp: enabled: true - enabledBanner: true # 是否开启banner打印,默认true enabledCollect: true # 是否开启监控指标采集,默认false collectorTypes: logging # 监控数据采集器类型(logging | micrometer | internal_logging),默认micrometer monitorInterval: 5 @@ -25,8 +24,6 @@ spring: - platform: lark urlKey: 0d944ae7-b24a-40 # 替换 receivers: test1,test2 # 接受人飞书名称/openid - - platform: email - receivers: 123456@qq.com,789789@qq.com # 收件人 dubboTp: # dubbo 线程池配置 - threadPoolName: dubboTp#20880 # 名称规则:dubboTp + "#" + 协议端口 threadPoolAliasName: 测试线程池 @@ -39,25 +36,6 @@ spring: threshold: 80 # 报警阈值 platforms: [ ding,wechat ] # 可选配置,不配置默认拿上层platforms配置的所以平台 interval: 120 # 报警间隔(单位:s) - # email notify configuration - mail: - # (optional) email subject, default:ThreadPool Notify - title: ThreadPool Notify - # mail service address - host: smtp.qq.com - port: 465 - # send from - username: 123456@qq.com - # authorization code eg: rlpadadtcugh4152e - password: xxxxxxxxxxxxxxxx - default-encoding: UTF-8 - properties: - mail: - smtp: - socketFactoryClass: javax.net.ssl.SSLSocketFactory - ssl: - enable: true - debug: false dubbo: application: @@ -69,3 +47,15 @@ dubbo: protocol: name: dubbo port: 20880 + +# 开启 SpringBoot Actuator Endpoint 暴露出DynamicTp指标接口 +# 开启 prometheus 指标采集端点 +management: + metrics: + export: + prometheus: + enabled: true + endpoints: + web: + exposure: + include: '*' # 测试使用,线上不要用*,按需开启 \ No newline at end of file diff --git a/example/example-adapter/example-adapter-dubbo/example-adapter-apache-dubbo/example-adapter-apache-dubbo-2.7.9/src/main/resources/application.yml b/example/example-adapter/example-adapter-dubbo/example-adapter-apache-dubbo/example-adapter-apache-dubbo-2.7.9/src/main/resources/application.yml index 2a61b1483..7cb1f62e8 100644 --- a/example/example-adapter/example-adapter-dubbo/example-adapter-apache-dubbo/example-adapter-apache-dubbo-2.7.9/src/main/resources/application.yml +++ b/example/example-adapter/example-adapter-dubbo/example-adapter-apache-dubbo/example-adapter-apache-dubbo-2.7.9/src/main/resources/application.yml @@ -10,7 +10,6 @@ spring: dynamic: tp: enabled: true - enabledBanner: true # 是否开启banner打印,默认true enabledCollect: true # 是否开启监控指标采集,默认false collectorTypes: logging # 监控数据采集器类型(logging | micrometer | internal_logging),默认micrometer monitorInterval: 5 @@ -25,8 +24,6 @@ spring: - platform: lark urlKey: 0d944ae7-b24a-40 # 替换 receivers: test1,test2 # 接受人飞书名称/openid - - platform: email - receivers: 123456@qq.com,789789@qq.com # 收件人 dubboTp: # dubbo 线程池配置 - threadPoolName: dubboTp#20880 # 名称规则:dubboTp + "#" + 协议端口 threadPoolAliasName: 测试线程池 @@ -39,25 +36,6 @@ spring: threshold: 80 # 报警阈值 platforms: [ ding,wechat ] # 可选配置,不配置默认拿上层platforms配置的所以平台 interval: 120 # 报警间隔(单位:s) - # email notify configuration - mail: - # (optional) email subject, default:ThreadPool Notify - title: ThreadPool Notify - # mail service address - host: smtp.qq.com - port: 465 - # send from - username: 123456@qq.com - # authorization code eg: rlpadadtcugh4152e - password: xxxxxxxxxxxxxxxx - default-encoding: UTF-8 - properties: - mail: - smtp: - socketFactoryClass: javax.net.ssl.SSLSocketFactory - ssl: - enable: true - debug: false dubbo: application: @@ -69,3 +47,15 @@ dubbo: protocol: name: dubbo port: 20880 + +# 开启 SpringBoot Actuator Endpoint 暴露出DynamicTp指标接口 +# 开启 prometheus 指标采集端点 +management: + metrics: + export: + prometheus: + enabled: true + endpoints: + web: + exposure: + include: '*' # 测试使用,线上不要用*,按需开启 \ No newline at end of file diff --git a/example/example-adapter/example-adapter-dubbo/example-adapter-apache-dubbo/example-adapter-apache-dubbo-3.0.7/src/main/resources/application.yml b/example/example-adapter/example-adapter-dubbo/example-adapter-apache-dubbo/example-adapter-apache-dubbo-3.0.7/src/main/resources/application.yml index 2a61b1483..7cb1f62e8 100644 --- a/example/example-adapter/example-adapter-dubbo/example-adapter-apache-dubbo/example-adapter-apache-dubbo-3.0.7/src/main/resources/application.yml +++ b/example/example-adapter/example-adapter-dubbo/example-adapter-apache-dubbo/example-adapter-apache-dubbo-3.0.7/src/main/resources/application.yml @@ -10,7 +10,6 @@ spring: dynamic: tp: enabled: true - enabledBanner: true # 是否开启banner打印,默认true enabledCollect: true # 是否开启监控指标采集,默认false collectorTypes: logging # 监控数据采集器类型(logging | micrometer | internal_logging),默认micrometer monitorInterval: 5 @@ -25,8 +24,6 @@ spring: - platform: lark urlKey: 0d944ae7-b24a-40 # 替换 receivers: test1,test2 # 接受人飞书名称/openid - - platform: email - receivers: 123456@qq.com,789789@qq.com # 收件人 dubboTp: # dubbo 线程池配置 - threadPoolName: dubboTp#20880 # 名称规则:dubboTp + "#" + 协议端口 threadPoolAliasName: 测试线程池 @@ -39,25 +36,6 @@ spring: threshold: 80 # 报警阈值 platforms: [ ding,wechat ] # 可选配置,不配置默认拿上层platforms配置的所以平台 interval: 120 # 报警间隔(单位:s) - # email notify configuration - mail: - # (optional) email subject, default:ThreadPool Notify - title: ThreadPool Notify - # mail service address - host: smtp.qq.com - port: 465 - # send from - username: 123456@qq.com - # authorization code eg: rlpadadtcugh4152e - password: xxxxxxxxxxxxxxxx - default-encoding: UTF-8 - properties: - mail: - smtp: - socketFactoryClass: javax.net.ssl.SSLSocketFactory - ssl: - enable: true - debug: false dubbo: application: @@ -69,3 +47,15 @@ dubbo: protocol: name: dubbo port: 20880 + +# 开启 SpringBoot Actuator Endpoint 暴露出DynamicTp指标接口 +# 开启 prometheus 指标采集端点 +management: + metrics: + export: + prometheus: + enabled: true + endpoints: + web: + exposure: + include: '*' # 测试使用,线上不要用*,按需开启 \ No newline at end of file diff --git a/example/example-adapter/example-adapter-grpc/src/main/resources/application.yml b/example/example-adapter/example-adapter-grpc/src/main/resources/application.yml index f4075d7e0..d458aef50 100644 --- a/example/example-adapter/example-adapter-grpc/src/main/resources/application.yml +++ b/example/example-adapter/example-adapter-grpc/src/main/resources/application.yml @@ -22,7 +22,6 @@ spring: dynamic: tp: enabled: true - enabledBanner: true # 是否开启banner打印,默认true enabledCollect: true # 是否开启监控指标采集,默认false collectorTypes: logging # 监控数据采集器类型(logging | micrometer | internal_logging),默认micrometer monitorInterval: 5 @@ -37,34 +36,12 @@ spring: - platform: lark urlKey: 0d944ae7-b24a-40 # 替换 receivers: test1,test2 # 接受人飞书名称/openid - - platform: email - receivers: 123456@qq.com,789789@qq.com # 收件人 grpcTp: # grpc 线程池配置 - threadPoolName: grpcTp#9999 corePoolSize: 100 maximumPoolSize: 200 keepAliveTime: 60 - # email notify configuration - mail: - # (optional) email subject, default:ThreadPool Notify - title: ThreadPool Notify - # mail service address - host: smtp.qq.com - port: 465 - # send from - username: 123456@qq.com - # authorization code eg: rlpadadtcugh4152e - password: xxxxxxxxxxxxxxxx - default-encoding: UTF-8 - properties: - mail: - smtp: - socketFactoryClass: javax.net.ssl.SSLSocketFactory - ssl: - enable: true - debug: false - grpc: server: port: 9999 @@ -75,4 +52,16 @@ grpc: address: 'discovery:///dynamic-tp-adapter-grpc-demo' enableKeepAlive: true keepAliveWithoutCalls: true - negotiationType: plaintext \ No newline at end of file + negotiationType: plaintext + +# 开启 SpringBoot Actuator Endpoint 暴露出DynamicTp指标接口 +# 开启 prometheus 指标采集端点 +management: + metrics: + export: + prometheus: + enabled: true + endpoints: + web: + exposure: + include: '*' # 测试使用,线上不要用*,按需开启 \ No newline at end of file diff --git a/example/example-adapter/example-adapter-hystrix/src/main/resources/application.yml b/example/example-adapter/example-adapter-hystrix/src/main/resources/application.yml index d676520d6..e314fb2db 100644 --- a/example/example-adapter/example-adapter-hystrix/src/main/resources/application.yml +++ b/example/example-adapter/example-adapter-hystrix/src/main/resources/application.yml @@ -10,7 +10,6 @@ spring: dynamic: tp: enabled: true - enabledBanner: true # 是否开启banner打印,默认true enabledCollect: true # 是否开启监控指标采集,默认false collectorTypes: logging # 监控数据采集器类型(logging | micrometer | internal_logging),默认micrometer monitorInterval: 5 @@ -25,30 +24,20 @@ spring: - platform: lark urlKey: 0d944ae7-b24a-40 # 替换 receivers: test1,test2 # 接受人飞书名称/openid - - platform: email - receivers: 123456@qq.com,789789@qq.com # 收件人 hystrixTp: # hystrix 线程池配置 - threadPoolName: testThreadPoolKey corePoolSize: 100 maximumPoolSize: 200 keepAliveTime: 60 - # email notify configuration - mail: - # (optional) email subject, default:ThreadPool Notify - title: ThreadPool Notify - # mail service address - host: smtp.qq.com - port: 465 - # send from - username: 123456@qq.com - # authorization code eg: rlpadadtcugh4152e - password: xxxxxxxxxxxxxxxx - default-encoding: UTF-8 - properties: - mail: - smtp: - socketFactoryClass: javax.net.ssl.SSLSocketFactory - ssl: - enable: true - debug: false +# 开启 SpringBoot Actuator Endpoint 暴露出DynamicTp指标接口 +# 开启 prometheus 指标采集端点 +management: + metrics: + export: + prometheus: + enabled: true + endpoints: + web: + exposure: + include: '*' # 测试使用,线上不要用*,按需开启 \ No newline at end of file diff --git a/example/example-adapter/example-adapter-motan/src/main/resources/application.yml b/example/example-adapter/example-adapter-motan/src/main/resources/application.yml index 00b82b0f3..daed76a01 100644 --- a/example/example-adapter/example-adapter-motan/src/main/resources/application.yml +++ b/example/example-adapter/example-adapter-motan/src/main/resources/application.yml @@ -10,7 +10,6 @@ spring: dynamic: tp: enabled: true - enabledBanner: true # 是否开启banner打印,默认true enabledCollect: true # 是否开启监控指标采集,默认false collectorTypes: logging # 监控数据采集器类型(logging | micrometer | internal_logging),默认micrometer monitorInterval: 5 @@ -25,30 +24,20 @@ spring: - platform: lark urlKey: 0d944ae7-b24a-40 # 替换 receivers: test1,test2 # 接受人飞书名称/openid - - platform: email - receivers: 123456@qq.com,789789@qq.com # 收件人 motanTp: # motan server 线程池配置 - threadPoolName: motanTp#8002 corePoolSize: 100 maximumPoolSize: 200 keepAliveTime: 60 - # email notify configuration - mail: - # (optional) email subject, default:ThreadPool Notify - title: ThreadPool Notify - # mail service address - host: smtp.qq.com - port: 465 - # send from - username: 123456@qq.com - # authorization code eg: rlpadadtcugh4152e - password: xxxxxxxxxxxxxxxx - default-encoding: UTF-8 - properties: - mail: - smtp: - socketFactoryClass: javax.net.ssl.SSLSocketFactory - ssl: - enable: true - debug: false \ No newline at end of file +# 开启 SpringBoot Actuator Endpoint 暴露出DynamicTp指标接口 +# 开启 prometheus 指标采集端点 +management: + metrics: + export: + prometheus: + enabled: true + endpoints: + web: + exposure: + include: '*' # 测试使用,线上不要用*,按需开启 \ No newline at end of file diff --git a/example/example-adapter/example-adapter-okhttp3/src/main/resources/application.yml b/example/example-adapter/example-adapter-okhttp3/src/main/resources/application.yml index d51a2a8df..6c7bfdd8f 100644 --- a/example/example-adapter/example-adapter-okhttp3/src/main/resources/application.yml +++ b/example/example-adapter/example-adapter-okhttp3/src/main/resources/application.yml @@ -10,7 +10,6 @@ spring: dynamic: tp: enabled: true - enabledBanner: true # 是否开启banner打印,默认true enabledCollect: true # 是否开启监控指标采集,默认false collectorTypes: logging # 监控数据采集器类型(logging | micrometer | internal_logging),默认micrometer monitorInterval: 5 @@ -38,4 +37,15 @@ spring: keepAliveTime: 60 runTimeout: 20 queueTimeout: 10 - taskWrapperNames: ["swTrace"] + +# 开启 SpringBoot Actuator Endpoint 暴露出DynamicTp指标接口 +# 开启 prometheus 指标采集端点 +management: + metrics: + export: + prometheus: + enabled: true + endpoints: + web: + exposure: + include: '*' # 测试使用,线上不要用*,按需开启 \ No newline at end of file diff --git a/example/example-adapter/example-adapter-rabbitmq/src/main/resources/application.yml b/example/example-adapter/example-adapter-rabbitmq/src/main/resources/application.yml index 63314f245..97df5f97e 100644 --- a/example/example-adapter/example-adapter-rabbitmq/src/main/resources/application.yml +++ b/example/example-adapter/example-adapter-rabbitmq/src/main/resources/application.yml @@ -18,7 +18,6 @@ spring: dynamic: tp: enabled: true - enabledBanner: true # 是否开启banner打印,默认true enabledCollect: true # 是否开启监控指标采集,默认false collectorTypes: internal_logging # 监控数据采集器类型(logging | micrometer | internal_logging),默认micrometer monitorInterval: 5 @@ -30,14 +29,15 @@ spring: maximumPoolSize: 16 #单位秒 keepAliveTime: 60 - notifyEnabled: true - notifyItems: - - type: change - enable: true - - type: liveness - enabled: true - threshold: 10 - interval: 5 - - type: capacity - enable: true - threshold: 10 + +# 开启 SpringBoot Actuator Endpoint 暴露出DynamicTp指标接口 +# 开启 prometheus 指标采集端点 +management: + metrics: + export: + prometheus: + enabled: true + endpoints: + web: + exposure: + include: '*' # 测试使用,线上不要用*,按需开启 \ No newline at end of file diff --git a/example/example-adapter/example-adapter-rocketmq/src/main/resources/application.yml b/example/example-adapter/example-adapter-rocketmq/src/main/resources/application.yml index 9afad6a73..8c37229c8 100644 --- a/example/example-adapter/example-adapter-rocketmq/src/main/resources/application.yml +++ b/example/example-adapter/example-adapter-rocketmq/src/main/resources/application.yml @@ -32,27 +32,19 @@ spring: maximumPoolSize: 200 keepAliveTime: 60 - # email notify configuration - mail: - # (optional) email subject, default:ThreadPool Notify - title: ThreadPool Notify - # mail service address - host: smtp.qq.com - port: 465 - # send from - username: 123456@qq.com - # authorization code eg: rlpadadtcugh4152e - password: xxxxxxxxxxxxxxxx - default-encoding: UTF-8 - properties: - mail: - smtp: - socketFactoryClass: javax.net.ssl.SSLSocketFactory - ssl: - enable: true - debug: false - rocketmq: name-server: 127.0.0.1:9876 producer: - group: test \ No newline at end of file + group: test + +# 开启 SpringBoot Actuator Endpoint 暴露出DynamicTp指标接口 +# 开启 prometheus 指标采集端点 +management: + metrics: + export: + prometheus: + enabled: true + endpoints: + web: + exposure: + include: '*' # 测试使用,线上不要用*,按需开启 \ No newline at end of file diff --git a/example/example-adapter/example-adapter-webserver/src/main/resources/application.yml b/example/example-adapter/example-adapter-webserver/src/main/resources/application.yml index 512afc43e..54d8b6cf8 100644 --- a/example/example-adapter/example-adapter-webserver/src/main/resources/application.yml +++ b/example/example-adapter/example-adapter-webserver/src/main/resources/application.yml @@ -7,10 +7,29 @@ spring: profiles: active: dev + # email notify configuration + mail: + # (optional) email subject, default:ThreadPool Notify + title: ThreadPool Notify + # mail service address + host: smtp.qq.com + port: 465 + # send from + username: 123456@qq.com + # authorization code eg: rlpadadtcugh4152e + password: xxxxxxxxxxxxxxxx + default-encoding: UTF-8 + properties: + mail: + smtp: + socketFactoryClass: javax.net.ssl.SSLSocketFactory + ssl: + enable: true + debug: false + dynamic: tp: enabled: true - enabledBanner: true # 是否开启banner打印,默认true enabledCollect: true # 是否开启监控指标采集,默认false collectorTypes: logging,micrometer # 监控数据采集器类型(logging | micrometer | internal_logging),默认micrometer monitorInterval: 5 @@ -25,6 +44,8 @@ spring: - platform: lark urlKey: 0d944ae7-b24a-40 # 替换 receivers: test1,test2 # 接受人飞书名称/openid + - platform: email + receivers: 123456@qq.com,789789@qq.com # 收件人 tomcatTp: # tomcat webserver 线程池配置 corePoolSize: 100 maximumPoolSize: 200 @@ -46,6 +67,8 @@ spring: runTimeout: 20 queueTimeout: 10 +# 开启 SpringBoot Actuator Endpoint 暴露出DynamicTp指标接口 +# 开启 prometheus 指标采集端点 management: metrics: export: @@ -54,4 +77,4 @@ management: endpoints: web: exposure: - include: '*' \ No newline at end of file + include: '*' # 测试使用,线上不要用*,按需开启 \ No newline at end of file diff --git a/example/example-apollo/src/main/resources/application.yml b/example/example-apollo/src/main/resources/application.yml index 53c432440..22e97c4d1 100644 --- a/example/example-apollo/src/main/resources/application.yml +++ b/example/example-apollo/src/main/resources/application.yml @@ -7,19 +7,6 @@ spring: profiles: active: dev -management: - endpoints: - web: - base-path: /actuator - exposure: - include: '*' - httptrace: - enabled: false - configprops: - enabled: false - shutdown: - enabled: false - apollo: bootstrap: enabled: true @@ -28,4 +15,16 @@ apollo: namespaces: dynamic-tp-apollo-demo-dtp.yml,application meta: http://81.68.181.139:8080 app: - id: dynamic-tp-apollo-demo \ No newline at end of file + id: dynamic-tp-apollo-demo + +# 开启 SpringBoot Actuator Endpoint 暴露出DynamicTp指标接口 +# 开启 prometheus 指标采集端点 +management: + metrics: + export: + prometheus: + enabled: true + endpoints: + web: + exposure: + include: '*' # 测试使用,线上不要用*,按需开启 diff --git a/example/example-consul-cloud/src/main/resources/bootstrap.yml b/example/example-consul-cloud/src/main/resources/bootstrap.yml index aa0af2b45..2e058835f 100644 --- a/example/example-consul-cloud/src/main/resources/bootstrap.yml +++ b/example/example-consul-cloud/src/main/resources/bootstrap.yml @@ -1,19 +1,6 @@ server: port: 9100 -management: - endpoints: - web: - base-path: /actuator - exposure: - include: '*' - httptrace: - enabled: false - configprops: - enabled: false - shutdown: - enabled: false - spring: application: name: dynamic-tp-cloud-consul-demo @@ -27,4 +14,16 @@ spring: enabled: true prefixes: config format: yaml - data-key: dynamic-tp-cloud-consul-demo-dtp \ No newline at end of file + data-key: dynamic-tp-cloud-consul-demo-dtp + +# 开启 SpringBoot Actuator Endpoint 暴露出DynamicTp指标接口 +# 开启 prometheus 指标采集端点 +management: + metrics: + export: + prometheus: + enabled: true + endpoints: + web: + exposure: + include: '*' # 测试使用,线上不要用*,按需开启 \ No newline at end of file diff --git a/example/example-etcd/src/main/resources/application.yml b/example/example-etcd/src/main/resources/application.yml index b586f40cd..812c1547a 100644 --- a/example/example-etcd/src/main/resources/application.yml +++ b/example/example-etcd/src/main/resources/application.yml @@ -12,6 +12,14 @@ spring: application: name: dynamic-tp-etcd-demo -logging: - level: - root: INFO \ No newline at end of file +# 开启 SpringBoot Actuator Endpoint 暴露出DynamicTp指标接口 +# 开启 prometheus 指标采集端点 +management: + metrics: + export: + prometheus: + enabled: true + endpoints: + web: + exposure: + include: '*' # 测试使用,线上不要用*,按需开启 \ No newline at end of file diff --git a/example/example-huawei-cloud/src/main/resources/bootstrap.yml b/example/example-huawei-cloud/src/main/resources/bootstrap.yml index 3bfd624ff..41590bcbe 100644 --- a/example/example-huawei-cloud/src/main/resources/bootstrap.yml +++ b/example/example-huawei-cloud/src/main/resources/bootstrap.yml @@ -17,4 +17,16 @@ spring: customLabel: public customLabelValue: default # 自定义配置,使用文本的key/value配置项作为yaml格式配置 - fileSource: application.yaml \ No newline at end of file + fileSource: application.yaml + +# 开启 SpringBoot Actuator Endpoint 暴露出DynamicTp指标接口 +# 开启 prometheus 指标采集端点 +management: + metrics: + export: + prometheus: + enabled: true + endpoints: + web: + exposure: + include: '*' # 测试使用,线上不要用*,按需开启 \ No newline at end of file diff --git a/example/example-nacos-cloud/src/main/resources/bootstrap.yml b/example/example-nacos-cloud/src/main/resources/bootstrap.yml index 337439cdb..71af6a26d 100644 --- a/example/example-nacos-cloud/src/main/resources/bootstrap.yml +++ b/example/example-nacos-cloud/src/main/resources/bootstrap.yml @@ -22,6 +22,8 @@ spring: host: ${redis:localhost} port: 6379 +# 开启 SpringBoot Actuator Endpoint 暴露出DynamicTp指标接口 +# 开启 prometheus 指标采集端点 management: metrics: export: diff --git a/example/example-nacos/src/main/resources/application.yml b/example/example-nacos/src/main/resources/application.yml index ec7627046..5647a939f 100644 --- a/example/example-nacos/src/main/resources/application.yml +++ b/example/example-nacos/src/main/resources/application.yml @@ -1,18 +1,6 @@ server: port: 8888 -# 开启 SpringBoot Actuator Endpoint 暴露出DynamicTp指标接口 -# 开启 prometheus 指标采集端点 -management: - metrics: - export: - prometheus: - enabled: true - endpoints: - web: - exposure: - include: '*' # 测试使用,线上不要用*,按需开启 - spring: application: name: dynamic-tp-nacos-demo @@ -30,7 +18,14 @@ nacos: enable: true log-enable: true -logging: - level: - #root: DEBUG - com.alibaba.nacos.client.config.impl: DEBUG \ No newline at end of file +# 开启 SpringBoot Actuator Endpoint 暴露出DynamicTp指标接口 +# 开启 prometheus 指标采集端点 +management: + metrics: + export: + prometheus: + enabled: true + endpoints: + web: + exposure: + include: '*' # 测试使用,线上不要用*,按需开启 \ No newline at end of file diff --git a/example/example-polaris-cloud/src/main/resources/bootstrap.yml b/example/example-polaris-cloud/src/main/resources/bootstrap.yml index fa9bc20fa..7de6ceb44 100644 --- a/example/example-polaris-cloud/src/main/resources/bootstrap.yml +++ b/example/example-polaris-cloud/src/main/resources/bootstrap.yml @@ -19,6 +19,8 @@ spring: - name: ${spring.application.name} # group name files: [ "config/dynamic-tp.yml" ] +# 开启 SpringBoot Actuator Endpoint 暴露出DynamicTp指标接口 +# 开启 prometheus 指标采集端点 management: metrics: export: @@ -27,4 +29,4 @@ management: endpoints: web: exposure: - include: '*' # 测试使用,线上不要用*,按需开启 + include: '*' # 测试使用,线上不要用*,按需开启 \ No newline at end of file diff --git a/example/example-zookeeper-cloud/src/main/resources/bootstrap.yml b/example/example-zookeeper-cloud/src/main/resources/bootstrap.yml index 7ce8f2a68..1c0b2524c 100644 --- a/example/example-zookeeper-cloud/src/main/resources/bootstrap.yml +++ b/example/example-zookeeper-cloud/src/main/resources/bootstrap.yml @@ -11,4 +11,16 @@ spring: root: /configserver/dev enabled: true profiles: - active: dev \ No newline at end of file + active: dev + +# 开启 SpringBoot Actuator Endpoint 暴露出DynamicTp指标接口 +# 开启 prometheus 指标采集端点 +management: + metrics: + export: + prometheus: + enabled: true + endpoints: + web: + exposure: + include: '*' # 测试使用,线上不要用*,按需开启 \ No newline at end of file diff --git a/example/example-zookeeper/src/main/resources/application.yml b/example/example-zookeeper/src/main/resources/application.yml index 10f6e6805..d565eaf49 100644 --- a/example/example-zookeeper/src/main/resources/application.yml +++ b/example/example-zookeeper/src/main/resources/application.yml @@ -13,7 +13,14 @@ spring: node: dtp-group config-key: dynamic-tp-zookeeper-demo-json # json 用到 - -#logging: -# level: -# root: DEBUG \ No newline at end of file +# 开启 SpringBoot Actuator Endpoint 暴露出DynamicTp指标接口 +# 开启 prometheus 指标采集端点 +management: + metrics: + export: + prometheus: + enabled: true + endpoints: + web: + exposure: + include: '*' # 测试使用,线上不要用*,按需开启 \ No newline at end of file diff --git a/starter/starter-configcenter/cloud-starter-consul/src/main/java/org/dromara/dynamictp/starter/cloud/consul/autoconfigure/DtpConsulAutoConfiguration.java b/starter/starter-configcenter/cloud-starter-consul/src/main/java/org/dromara/dynamictp/starter/cloud/consul/autoconfigure/DtpConsulAutoConfiguration.java index ad588336e..190572fb8 100644 --- a/starter/starter-configcenter/cloud-starter-consul/src/main/java/org/dromara/dynamictp/starter/cloud/consul/autoconfigure/DtpConsulAutoConfiguration.java +++ b/starter/starter-configcenter/cloud-starter-consul/src/main/java/org/dromara/dynamictp/starter/cloud/consul/autoconfigure/DtpConsulAutoConfiguration.java @@ -17,8 +17,9 @@ package org.dromara.dynamictp.starter.cloud.consul.autoconfigure; -import org.dromara.dynamictp.starter.cloud.consul.refresher.CloudConsulRefresher; +import org.dromara.dynamictp.common.properties.DtpProperties; import org.dromara.dynamictp.core.spring.DtpBaseBeanConfiguration; +import org.dromara.dynamictp.starter.cloud.consul.refresher.CloudConsulRefresher; import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; @@ -40,7 +41,7 @@ public class DtpConsulAutoConfiguration { @Bean @ConditionalOnMissingBean() @ConditionalOnProperty(value = "spring.cloud.consul.config.enabled", matchIfMissing = true) - public CloudConsulRefresher cloudConsulRefresher() { - return new CloudConsulRefresher(); + public CloudConsulRefresher cloudConsulRefresher(DtpProperties dtpProperties) { + return new CloudConsulRefresher(dtpProperties); } } diff --git a/starter/starter-configcenter/cloud-starter-consul/src/main/java/org/dromara/dynamictp/starter/cloud/consul/refresher/CloudConsulRefresher.java b/starter/starter-configcenter/cloud-starter-consul/src/main/java/org/dromara/dynamictp/starter/cloud/consul/refresher/CloudConsulRefresher.java index 395a039dd..31edd80de 100644 --- a/starter/starter-configcenter/cloud-starter-consul/src/main/java/org/dromara/dynamictp/starter/cloud/consul/refresher/CloudConsulRefresher.java +++ b/starter/starter-configcenter/cloud-starter-consul/src/main/java/org/dromara/dynamictp/starter/cloud/consul/refresher/CloudConsulRefresher.java @@ -18,8 +18,9 @@ package org.dromara.dynamictp.starter.cloud.consul.refresher; import lombok.extern.slf4j.Slf4j; +import org.dromara.dynamictp.common.properties.DtpProperties; import org.dromara.dynamictp.core.refresher.AbstractRefresher; -import org.springframework.cloud.context.scope.refresh.RefreshScopeRefreshedEvent; +import org.springframework.cloud.context.environment.EnvironmentChangeEvent; import org.springframework.context.ApplicationEvent; import org.springframework.context.event.SmartApplicationListener; import org.springframework.lang.NonNull; @@ -30,14 +31,18 @@ @Slf4j public class CloudConsulRefresher extends AbstractRefresher implements SmartApplicationListener { + public CloudConsulRefresher(DtpProperties dtpProperties) { + super(dtpProperties); + } + @Override public boolean supportsEventType(@NonNull Class eventType) { - return RefreshScopeRefreshedEvent.class.isAssignableFrom(eventType); + return EnvironmentChangeEvent.class.isAssignableFrom(eventType); } @Override public void onApplicationEvent(@NonNull ApplicationEvent event) { - if (event instanceof RefreshScopeRefreshedEvent) { + if (needRefresh(((EnvironmentChangeEvent) event).getKeys())) { refresh(environment); } } diff --git a/starter/starter-configcenter/cloud-starter-huawei/src/main/java/org/dromara/dynamictp/starter/cloud/huawei/autoconfigure/DtpHuaweiAutoConfiguration.java b/starter/starter-configcenter/cloud-starter-huawei/src/main/java/org/dromara/dynamictp/starter/cloud/huawei/autoconfigure/DtpHuaweiAutoConfiguration.java index 60db23552..c6f451953 100644 --- a/starter/starter-configcenter/cloud-starter-huawei/src/main/java/org/dromara/dynamictp/starter/cloud/huawei/autoconfigure/DtpHuaweiAutoConfiguration.java +++ b/starter/starter-configcenter/cloud-starter-huawei/src/main/java/org/dromara/dynamictp/starter/cloud/huawei/autoconfigure/DtpHuaweiAutoConfiguration.java @@ -17,9 +17,10 @@ package org.dromara.dynamictp.starter.cloud.huawei.autoconfigure; +import com.huaweicloud.common.configration.bootstrap.ConfigBootstrapProperties; +import org.dromara.dynamictp.common.properties.DtpProperties; import org.dromara.dynamictp.core.spring.DtpBaseBeanConfiguration; import org.dromara.dynamictp.starter.cloud.huawei.refresher.CloudHuaweiRefresher; -import com.huaweicloud.common.configration.bootstrap.ConfigBootstrapProperties; import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; @@ -40,7 +41,7 @@ public class DtpHuaweiAutoConfiguration { @Bean @ConditionalOnMissingBean() @ConditionalOnProperty(value = "spring.cloud.servicecomb.config.enabled", matchIfMissing = true) - public CloudHuaweiRefresher cloudHuaweiRefresher() { - return new CloudHuaweiRefresher(); + public CloudHuaweiRefresher cloudHuaweiRefresher(DtpProperties dtpProperties) { + return new CloudHuaweiRefresher(dtpProperties); } } diff --git a/starter/starter-configcenter/cloud-starter-huawei/src/main/java/org/dromara/dynamictp/starter/cloud/huawei/refresher/CloudHuaweiRefresher.java b/starter/starter-configcenter/cloud-starter-huawei/src/main/java/org/dromara/dynamictp/starter/cloud/huawei/refresher/CloudHuaweiRefresher.java index 3f8dcde7c..3e637c68d 100644 --- a/starter/starter-configcenter/cloud-starter-huawei/src/main/java/org/dromara/dynamictp/starter/cloud/huawei/refresher/CloudHuaweiRefresher.java +++ b/starter/starter-configcenter/cloud-starter-huawei/src/main/java/org/dromara/dynamictp/starter/cloud/huawei/refresher/CloudHuaweiRefresher.java @@ -17,9 +17,10 @@ package org.dromara.dynamictp.starter.cloud.huawei.refresher; -import com.huaweicloud.common.event.ConfigRefreshEvent; import lombok.extern.slf4j.Slf4j; +import org.dromara.dynamictp.common.properties.DtpProperties; import org.dromara.dynamictp.core.refresher.AbstractRefresher; +import org.springframework.cloud.context.environment.EnvironmentChangeEvent; import org.springframework.context.ApplicationEvent; import org.springframework.context.event.SmartApplicationListener; import org.springframework.lang.NonNull; @@ -30,15 +31,18 @@ @Slf4j public class CloudHuaweiRefresher extends AbstractRefresher implements SmartApplicationListener { + public CloudHuaweiRefresher(DtpProperties dtpProperties) { + super(dtpProperties); + } + @Override public boolean supportsEventType(@NonNull Class eventType) { - return ConfigRefreshEvent.class.isAssignableFrom(eventType); + return EnvironmentChangeEvent.class.isAssignableFrom(eventType); } @Override public void onApplicationEvent(@NonNull ApplicationEvent event) { - // huawei config define RefreshEvent - if (event instanceof ConfigRefreshEvent) { + if (needRefresh(((EnvironmentChangeEvent) event).getKeys())) { refresh(environment); } } diff --git a/starter/starter-configcenter/cloud-starter-nacos/src/main/java/org/dromara/dynamictp/starter/cloud/nacos/autoconfigure/DtpCloudNacosAutoConfiguration.java b/starter/starter-configcenter/cloud-starter-nacos/src/main/java/org/dromara/dynamictp/starter/cloud/nacos/autoconfigure/DtpCloudNacosAutoConfiguration.java index 236eed166..23b45a3b2 100644 --- a/starter/starter-configcenter/cloud-starter-nacos/src/main/java/org/dromara/dynamictp/starter/cloud/nacos/autoconfigure/DtpCloudNacosAutoConfiguration.java +++ b/starter/starter-configcenter/cloud-starter-nacos/src/main/java/org/dromara/dynamictp/starter/cloud/nacos/autoconfigure/DtpCloudNacosAutoConfiguration.java @@ -19,8 +19,9 @@ import com.alibaba.cloud.nacos.NacosConfigManager; import com.alibaba.cloud.nacos.NacosConfigProperties; -import org.dromara.dynamictp.starter.cloud.nacos.refresher.CloudNacosRefresher; +import org.dromara.dynamictp.common.properties.DtpProperties; import org.dromara.dynamictp.core.spring.DtpBaseBeanConfiguration; +import org.dromara.dynamictp.starter.cloud.nacos.refresher.CloudNacosRefresher; import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; @@ -43,7 +44,7 @@ public class DtpCloudNacosAutoConfiguration { @Bean @ConditionalOnMissingBean() @ConditionalOnClass(NacosConfigManager.class) - public CloudNacosRefresher cloudNacosRefresher() { - return new CloudNacosRefresher(); + public CloudNacosRefresher cloudNacosRefresher(DtpProperties dtpProperties) { + return new CloudNacosRefresher(dtpProperties); } } diff --git a/starter/starter-configcenter/cloud-starter-nacos/src/main/java/org/dromara/dynamictp/starter/cloud/nacos/refresher/CloudNacosRefresher.java b/starter/starter-configcenter/cloud-starter-nacos/src/main/java/org/dromara/dynamictp/starter/cloud/nacos/refresher/CloudNacosRefresher.java index ffe670304..8da6c6e03 100644 --- a/starter/starter-configcenter/cloud-starter-nacos/src/main/java/org/dromara/dynamictp/starter/cloud/nacos/refresher/CloudNacosRefresher.java +++ b/starter/starter-configcenter/cloud-starter-nacos/src/main/java/org/dromara/dynamictp/starter/cloud/nacos/refresher/CloudNacosRefresher.java @@ -18,8 +18,9 @@ package org.dromara.dynamictp.starter.cloud.nacos.refresher; import lombok.extern.slf4j.Slf4j; +import org.dromara.dynamictp.common.properties.DtpProperties; import org.dromara.dynamictp.core.refresher.AbstractRefresher; -import org.springframework.cloud.context.scope.refresh.RefreshScopeRefreshedEvent; +import org.springframework.cloud.context.environment.EnvironmentChangeEvent; import org.springframework.context.ApplicationEvent; import org.springframework.context.event.SmartApplicationListener; import org.springframework.lang.NonNull; @@ -33,14 +34,18 @@ @Slf4j public class CloudNacosRefresher extends AbstractRefresher implements SmartApplicationListener { + public CloudNacosRefresher(DtpProperties dtpProperties) { + super(dtpProperties); + } + @Override public boolean supportsEventType(@NonNull Class eventType) { - return RefreshScopeRefreshedEvent.class.isAssignableFrom(eventType); + return EnvironmentChangeEvent.class.isAssignableFrom(eventType); } @Override public void onApplicationEvent(@NonNull ApplicationEvent event) { - if (event instanceof RefreshScopeRefreshedEvent) { + if (needRefresh(((EnvironmentChangeEvent) event).getKeys())) { refresh(environment); } } diff --git a/starter/starter-configcenter/cloud-starter-polaris/src/main/java/org/dromara/dynamictp/starter/cloud/polaris/autoconfigure/DtpPolarisAutoConfiguration.java b/starter/starter-configcenter/cloud-starter-polaris/src/main/java/org/dromara/dynamictp/starter/cloud/polaris/autoconfigure/DtpPolarisAutoConfiguration.java index 03e8d1a1e..f1b3ed98e 100644 --- a/starter/starter-configcenter/cloud-starter-polaris/src/main/java/org/dromara/dynamictp/starter/cloud/polaris/autoconfigure/DtpPolarisAutoConfiguration.java +++ b/starter/starter-configcenter/cloud-starter-polaris/src/main/java/org/dromara/dynamictp/starter/cloud/polaris/autoconfigure/DtpPolarisAutoConfiguration.java @@ -17,9 +17,10 @@ package org.dromara.dynamictp.starter.cloud.polaris.autoconfigure; -import org.dromara.dynamictp.starter.cloud.polaris.refresher.CloudPolarisRefresher; -import org.dromara.dynamictp.core.spring.DtpBaseBeanConfiguration; import com.tencent.cloud.polaris.config.config.PolarisConfigProperties; +import org.dromara.dynamictp.common.properties.DtpProperties; +import org.dromara.dynamictp.core.spring.DtpBaseBeanConfiguration; +import org.dromara.dynamictp.starter.cloud.polaris.refresher.CloudPolarisRefresher; import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; @@ -43,7 +44,7 @@ public class DtpPolarisAutoConfiguration { @Bean @ConditionalOnMissingBean() @ConditionalOnProperty(value = "spring.cloud.polaris.config.enabled", matchIfMissing = true) - public CloudPolarisRefresher cloudPolarisRefresher() { - return new CloudPolarisRefresher(); + public CloudPolarisRefresher cloudPolarisRefresher(DtpProperties dtpProperties) { + return new CloudPolarisRefresher(dtpProperties); } } diff --git a/starter/starter-configcenter/cloud-starter-polaris/src/main/java/org/dromara/dynamictp/starter/cloud/polaris/refresher/CloudPolarisRefresher.java b/starter/starter-configcenter/cloud-starter-polaris/src/main/java/org/dromara/dynamictp/starter/cloud/polaris/refresher/CloudPolarisRefresher.java index 13bb1fcc7..3c6d1d967 100644 --- a/starter/starter-configcenter/cloud-starter-polaris/src/main/java/org/dromara/dynamictp/starter/cloud/polaris/refresher/CloudPolarisRefresher.java +++ b/starter/starter-configcenter/cloud-starter-polaris/src/main/java/org/dromara/dynamictp/starter/cloud/polaris/refresher/CloudPolarisRefresher.java @@ -17,9 +17,10 @@ package org.dromara.dynamictp.starter.cloud.polaris.refresher; -import com.tencent.cloud.polaris.config.spring.event.ConfigChangeSpringEvent; import lombok.extern.slf4j.Slf4j; +import org.dromara.dynamictp.common.properties.DtpProperties; import org.dromara.dynamictp.core.refresher.AbstractRefresher; +import org.springframework.cloud.context.environment.EnvironmentChangeEvent; import org.springframework.context.ApplicationEvent; import org.springframework.context.event.SmartApplicationListener; import org.springframework.lang.NonNull; @@ -33,14 +34,18 @@ @Slf4j public class CloudPolarisRefresher extends AbstractRefresher implements SmartApplicationListener { + public CloudPolarisRefresher(DtpProperties dtpProperties) { + super(dtpProperties); + } + @Override public boolean supportsEventType(@NonNull Class eventType) { - return ConfigChangeSpringEvent.class.isAssignableFrom(eventType); + return EnvironmentChangeEvent.class.isAssignableFrom(eventType); } @Override public void onApplicationEvent(@NonNull ApplicationEvent event) { - if (event instanceof ConfigChangeSpringEvent) { + if (needRefresh(((EnvironmentChangeEvent) event).getKeys())) { refresh(environment); } } diff --git a/starter/starter-configcenter/cloud-starter-zookeeper/src/main/java/org/dromara/dynamictp/starter/cloud/zookeeper/autoconfigure/DtpCloudZkAutoConfiguration.java b/starter/starter-configcenter/cloud-starter-zookeeper/src/main/java/org/dromara/dynamictp/starter/cloud/zookeeper/autoconfigure/DtpCloudZkAutoConfiguration.java index 65320ef85..5ced91641 100644 --- a/starter/starter-configcenter/cloud-starter-zookeeper/src/main/java/org/dromara/dynamictp/starter/cloud/zookeeper/autoconfigure/DtpCloudZkAutoConfiguration.java +++ b/starter/starter-configcenter/cloud-starter-zookeeper/src/main/java/org/dromara/dynamictp/starter/cloud/zookeeper/autoconfigure/DtpCloudZkAutoConfiguration.java @@ -17,8 +17,9 @@ package org.dromara.dynamictp.starter.cloud.zookeeper.autoconfigure; -import org.dromara.dynamictp.starter.cloud.zookeeper.refresher.CloudZookeeperRefresher; +import org.dromara.dynamictp.common.properties.DtpProperties; import org.dromara.dynamictp.core.spring.DtpBaseBeanConfiguration; +import org.dromara.dynamictp.starter.cloud.zookeeper.refresher.CloudZookeeperRefresher; import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; @@ -40,7 +41,7 @@ public class DtpCloudZkAutoConfiguration { @Bean @ConditionalOnMissingBean() @ConditionalOnProperty(value = "spring.cloud.zookeeper.config.enabled", matchIfMissing = true) - public CloudZookeeperRefresher cloudZookeeperRefresher() { - return new CloudZookeeperRefresher(); + public CloudZookeeperRefresher cloudZookeeperRefresher(DtpProperties dtpProperties) { + return new CloudZookeeperRefresher(dtpProperties); } } diff --git a/starter/starter-configcenter/cloud-starter-zookeeper/src/main/java/org/dromara/dynamictp/starter/cloud/zookeeper/refresher/CloudZookeeperRefresher.java b/starter/starter-configcenter/cloud-starter-zookeeper/src/main/java/org/dromara/dynamictp/starter/cloud/zookeeper/refresher/CloudZookeeperRefresher.java index 43ccde462..bb9e0e175 100644 --- a/starter/starter-configcenter/cloud-starter-zookeeper/src/main/java/org/dromara/dynamictp/starter/cloud/zookeeper/refresher/CloudZookeeperRefresher.java +++ b/starter/starter-configcenter/cloud-starter-zookeeper/src/main/java/org/dromara/dynamictp/starter/cloud/zookeeper/refresher/CloudZookeeperRefresher.java @@ -18,8 +18,9 @@ package org.dromara.dynamictp.starter.cloud.zookeeper.refresher; import lombok.extern.slf4j.Slf4j; +import org.dromara.dynamictp.common.properties.DtpProperties; import org.dromara.dynamictp.core.refresher.AbstractRefresher; -import org.springframework.cloud.context.scope.refresh.RefreshScopeRefreshedEvent; +import org.springframework.cloud.context.environment.EnvironmentChangeEvent; import org.springframework.context.ApplicationEvent; import org.springframework.context.event.SmartApplicationListener; import org.springframework.lang.NonNull; @@ -30,14 +31,18 @@ @Slf4j public class CloudZookeeperRefresher extends AbstractRefresher implements SmartApplicationListener { + public CloudZookeeperRefresher(DtpProperties dtpProperties) { + super(dtpProperties); + } + @Override public boolean supportsEventType(@NonNull Class eventType) { - return RefreshScopeRefreshedEvent.class.isAssignableFrom(eventType); + return EnvironmentChangeEvent.class.isAssignableFrom(eventType); } @Override public void onApplicationEvent(@NonNull ApplicationEvent event) { - if (event instanceof RefreshScopeRefreshedEvent) { + if (needRefresh(((EnvironmentChangeEvent) event).getKeys())) { refresh(environment); } } diff --git a/starter/starter-configcenter/starter-apollo/src/main/java/org/dromara/dynamictp/starter/apollo/autoconfigure/DtpApolloAutoConfiguration.java b/starter/starter-configcenter/starter-apollo/src/main/java/org/dromara/dynamictp/starter/apollo/autoconfigure/DtpApolloAutoConfiguration.java index b9de171e8..563f4d8f4 100644 --- a/starter/starter-configcenter/starter-apollo/src/main/java/org/dromara/dynamictp/starter/apollo/autoconfigure/DtpApolloAutoConfiguration.java +++ b/starter/starter-configcenter/starter-apollo/src/main/java/org/dromara/dynamictp/starter/apollo/autoconfigure/DtpApolloAutoConfiguration.java @@ -17,8 +17,9 @@ package org.dromara.dynamictp.starter.apollo.autoconfigure; -import org.dromara.dynamictp.starter.apollo.refresher.ApolloRefresher; +import org.dromara.dynamictp.common.properties.DtpProperties; import org.dromara.dynamictp.core.spring.DtpBaseBeanConfiguration; +import org.dromara.dynamictp.starter.apollo.refresher.ApolloRefresher; import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; @@ -44,7 +45,7 @@ public class DtpApolloAutoConfiguration { @Bean @ConditionalOnMissingBean - public ApolloRefresher apolloRefresher() { - return new ApolloRefresher(); + public ApolloRefresher apolloRefresher(DtpProperties dtpProperties) { + return new ApolloRefresher(dtpProperties); } } diff --git a/starter/starter-configcenter/starter-apollo/src/main/java/org/dromara/dynamictp/starter/apollo/refresher/ApolloRefresher.java b/starter/starter-configcenter/starter-apollo/src/main/java/org/dromara/dynamictp/starter/apollo/refresher/ApolloRefresher.java index dd6c57467..934495d9b 100644 --- a/starter/starter-configcenter/starter-apollo/src/main/java/org/dromara/dynamictp/starter/apollo/refresher/ApolloRefresher.java +++ b/starter/starter-configcenter/starter-apollo/src/main/java/org/dromara/dynamictp/starter/apollo/refresher/ApolloRefresher.java @@ -28,6 +28,7 @@ import lombok.extern.slf4j.Slf4j; import lombok.val; import org.dromara.dynamictp.common.em.ConfigFileTypeEnum; +import org.dromara.dynamictp.common.properties.DtpProperties; import org.dromara.dynamictp.core.handler.ConfigHandler; import org.dromara.dynamictp.core.refresher.AbstractRefresher; import org.springframework.beans.factory.InitializingBean; @@ -49,6 +50,10 @@ public class ApolloRefresher extends AbstractRefresher implements ConfigFileChan private static final Splitter NAMESPACE_SPLITTER = Splitter.on(",").omitEmptyStrings().trimResults(); + public ApolloRefresher(DtpProperties dtpProperties) { + super(dtpProperties); + } + @Override public void onChange(ConfigFileChangeEvent changeEvent) { String namespace = changeEvent.getNamespace(); diff --git a/starter/starter-configcenter/starter-etcd/src/main/java/org/dromara/dynamictp/starter/etcd/autoconfigure/DtpEtcdAutoConfiguration.java b/starter/starter-configcenter/starter-etcd/src/main/java/org/dromara/dynamictp/starter/etcd/autoconfigure/DtpEtcdAutoConfiguration.java index 2164b3db6..426a53e9f 100644 --- a/starter/starter-configcenter/starter-etcd/src/main/java/org/dromara/dynamictp/starter/etcd/autoconfigure/DtpEtcdAutoConfiguration.java +++ b/starter/starter-configcenter/starter-etcd/src/main/java/org/dromara/dynamictp/starter/etcd/autoconfigure/DtpEtcdAutoConfiguration.java @@ -17,9 +17,10 @@ package org.dromara.dynamictp.starter.etcd.autoconfigure; +import io.etcd.jetcd.Client; +import org.dromara.dynamictp.common.properties.DtpProperties; import org.dromara.dynamictp.core.spring.DtpBaseBeanConfiguration; import org.dromara.dynamictp.starter.etcd.refresher.EtcdRefresher; -import io.etcd.jetcd.Client; import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; @@ -38,7 +39,7 @@ public class DtpEtcdAutoConfiguration { @Bean @ConditionalOnMissingBean - public EtcdRefresher etcdRefresher() { - return new EtcdRefresher(); + public EtcdRefresher etcdRefresher(DtpProperties dtpProperties) { + return new EtcdRefresher(dtpProperties); } } diff --git a/starter/starter-configcenter/starter-etcd/src/main/java/org/dromara/dynamictp/starter/etcd/refresher/EtcdRefresher.java b/starter/starter-configcenter/starter-etcd/src/main/java/org/dromara/dynamictp/starter/etcd/refresher/EtcdRefresher.java index 1058900bd..1798b2ac6 100644 --- a/starter/starter-configcenter/starter-etcd/src/main/java/org/dromara/dynamictp/starter/etcd/refresher/EtcdRefresher.java +++ b/starter/starter-configcenter/starter-etcd/src/main/java/org/dromara/dynamictp/starter/etcd/refresher/EtcdRefresher.java @@ -34,6 +34,10 @@ @Slf4j public class EtcdRefresher extends AbstractRefresher implements InitializingBean, Ordered, DisposableBean { + public EtcdRefresher(DtpProperties dtpProperties) { + super(dtpProperties); + } + @Override public void afterPropertiesSet() { DtpProperties.Etcd etcd = dtpProperties.getEtcd(); diff --git a/starter/starter-configcenter/starter-nacos/src/main/java/org/dromara/dynamictp/starter/nacos/autoconfigure/DtpNacosAutoConfiguration.java b/starter/starter-configcenter/starter-nacos/src/main/java/org/dromara/dynamictp/starter/nacos/autoconfigure/DtpNacosAutoConfiguration.java index f78ba5327..541c9b699 100644 --- a/starter/starter-configcenter/starter-nacos/src/main/java/org/dromara/dynamictp/starter/nacos/autoconfigure/DtpNacosAutoConfiguration.java +++ b/starter/starter-configcenter/starter-nacos/src/main/java/org/dromara/dynamictp/starter/nacos/autoconfigure/DtpNacosAutoConfiguration.java @@ -17,6 +17,7 @@ package org.dromara.dynamictp.starter.nacos.autoconfigure; +import org.dromara.dynamictp.common.properties.DtpProperties; import com.alibaba.boot.nacos.config.properties.NacosConfigProperties; import org.dromara.dynamictp.core.spring.DtpBaseBeanConfiguration; import org.dromara.dynamictp.starter.nacos.refresher.NacosRefresher; @@ -41,8 +42,8 @@ public class DtpNacosAutoConfiguration { @Bean @ConditionalOnMissingBean() - public NacosRefresher nacosRefresher() { - return new NacosRefresher(); + public NacosRefresher nacosRefresher(DtpProperties dtpProperties) { + return new NacosRefresher(dtpProperties); } } diff --git a/starter/starter-configcenter/starter-nacos/src/main/java/org/dromara/dynamictp/starter/nacos/refresher/NacosRefresher.java b/starter/starter-configcenter/starter-nacos/src/main/java/org/dromara/dynamictp/starter/nacos/refresher/NacosRefresher.java index 813b85160..aab757b80 100644 --- a/starter/starter-configcenter/starter-nacos/src/main/java/org/dromara/dynamictp/starter/nacos/refresher/NacosRefresher.java +++ b/starter/starter-configcenter/starter-nacos/src/main/java/org/dromara/dynamictp/starter/nacos/refresher/NacosRefresher.java @@ -19,6 +19,7 @@ import com.alibaba.nacos.spring.context.event.config.NacosConfigEvent; import lombok.extern.slf4j.Slf4j; +import org.dromara.dynamictp.common.properties.DtpProperties; import org.dromara.dynamictp.core.refresher.AbstractRefresher; import org.springframework.context.ApplicationEvent; import org.springframework.context.event.SmartApplicationListener; @@ -32,9 +33,13 @@ @Slf4j public class NacosRefresher extends AbstractRefresher implements SmartApplicationListener { + public NacosRefresher(DtpProperties dtpProperties) { + super(dtpProperties); + } + @Override public boolean supportsEventType(Class eventType) { - return NacosConfigEvent.class.isAssignableFrom(eventType); + return NacosConfigEvent.class.isAssignableFrom(eventType); } @Override diff --git a/starter/starter-configcenter/starter-zookeeper/src/main/java/org/dromara/dynamictp/starter/zookeeper/autoconfigure/DtpZkAutoConfiguration.java b/starter/starter-configcenter/starter-zookeeper/src/main/java/org/dromara/dynamictp/starter/zookeeper/autoconfigure/DtpZkAutoConfiguration.java index 4afabf51b..b5752fc4b 100644 --- a/starter/starter-configcenter/starter-zookeeper/src/main/java/org/dromara/dynamictp/starter/zookeeper/autoconfigure/DtpZkAutoConfiguration.java +++ b/starter/starter-configcenter/starter-zookeeper/src/main/java/org/dromara/dynamictp/starter/zookeeper/autoconfigure/DtpZkAutoConfiguration.java @@ -17,11 +17,13 @@ package org.dromara.dynamictp.starter.zookeeper.autoconfigure; +import org.dromara.dynamictp.common.properties.DtpProperties; import org.dromara.dynamictp.core.spring.DtpBaseBeanConfiguration; import org.dromara.dynamictp.starter.zookeeper.refresher.ZookeeperRefresher; import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -35,7 +37,8 @@ public class DtpZkAutoConfiguration { @Bean - public ZookeeperRefresher zookeeperRefresher() { - return new ZookeeperRefresher(); + @ConditionalOnMissingBean() + public ZookeeperRefresher zookeeperRefresher(DtpProperties dtpProperties) { + return new ZookeeperRefresher(dtpProperties); } } diff --git a/starter/starter-configcenter/starter-zookeeper/src/main/java/org/dromara/dynamictp/starter/zookeeper/refresher/ZookeeperRefresher.java b/starter/starter-configcenter/starter-zookeeper/src/main/java/org/dromara/dynamictp/starter/zookeeper/refresher/ZookeeperRefresher.java index 9271bc51b..fa6b878b3 100644 --- a/starter/starter-configcenter/starter-zookeeper/src/main/java/org/dromara/dynamictp/starter/zookeeper/refresher/ZookeeperRefresher.java +++ b/starter/starter-configcenter/starter-zookeeper/src/main/java/org/dromara/dynamictp/starter/zookeeper/refresher/ZookeeperRefresher.java @@ -23,6 +23,7 @@ import org.apache.curator.framework.state.ConnectionState; import org.apache.curator.framework.state.ConnectionStateListener; import org.apache.zookeeper.WatchedEvent; +import org.dromara.dynamictp.common.properties.DtpProperties; import org.dromara.dynamictp.core.refresher.AbstractRefresher; import org.dromara.dynamictp.starter.zookeeper.autoconfigure.ZkConfigEnvironmentProcessor; import org.dromara.dynamictp.starter.zookeeper.util.CuratorUtil; @@ -37,6 +38,10 @@ @Slf4j public class ZookeeperRefresher extends AbstractRefresher implements EnvironmentAware, InitializingBean { + public ZookeeperRefresher(DtpProperties dtpProperties) { + super(dtpProperties); + } + @Override public void afterPropertiesSet() { diff --git a/starter/starter-extension/starter-extension-notify-email/src/main/java/org/dromara/dynamictp/start/extension/notify/email/autoconfigure/NotifyEmailAutoConfiguration.java b/starter/starter-extension/starter-extension-notify-email/src/main/java/org/dromara/dynamictp/start/extension/notify/email/autoconfigure/NotifyEmailAutoConfiguration.java index fa46764cc..aabceed42 100644 --- a/starter/starter-extension/starter-extension-notify-email/src/main/java/org/dromara/dynamictp/start/extension/notify/email/autoconfigure/NotifyEmailAutoConfiguration.java +++ b/starter/starter-extension/starter-extension-notify-email/src/main/java/org/dromara/dynamictp/start/extension/notify/email/autoconfigure/NotifyEmailAutoConfiguration.java @@ -17,7 +17,6 @@ package org.dromara.dynamictp.start.extension.notify.email.autoconfigure; - import org.dromara.dynamictp.core.notifier.DtpNotifier; import org.dromara.dynamictp.extension.notify.email.DtpEmailNotifier; import org.dromara.dynamictp.extension.notify.email.EmailNotifier;