Skip to content

Commit

Permalink
optimize cloud refresher and perfect example
Browse files Browse the repository at this point in the history
  • Loading branch information
yanhom1314 committed Dec 16, 2023
1 parent 5075cce commit 9cab076
Show file tree
Hide file tree
Showing 41 changed files with 365 additions and 317 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -91,6 +98,16 @@ protected void doRefresh(DtpProperties properties) {
publishEvent(properties);
}

protected boolean needRefresh(Set<String> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,35 +24,25 @@ spring:
- platform: lark
urlKey: 0d944ae7-b24a-40 # 替换
receivers: test1,test2 # 接受人飞书名称/openid
- platform: email
receivers: [email protected],[email protected] # 收件人
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: [email protected]
# 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
port: 8777

# 开启 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
Expand Up @@ -24,35 +24,13 @@ spring:
- platform: lark
urlKey: 0d944ae7-b24a-40 # 替换
receivers: test1,test2 # 接受人飞书名称/openid
- platform: email
receivers: [email protected],[email protected] # 收件人
dubboTp: # dubbo 线程池配置
- threadPoolName: dubboTp#20880 # 名称规则:dubboTp + "#" + 协议端口
threadPoolAliasName: 测试线程池
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: [email protected]
# 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
Expand All @@ -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: '*' # 测试使用,线上不要用*,按需开启
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -25,8 +24,6 @@ spring:
- platform: lark
urlKey: 0d944ae7-b24a-40 # 替换
receivers: test1,test2 # 接受人飞书名称/openid
- platform: email
receivers: [email protected],[email protected] # 收件人
dubboTp: # dubbo 线程池配置
- threadPoolName: dubboTp#20880 # 名称规则:dubboTp + "#" + 协议端口
threadPoolAliasName: 测试线程池
Expand All @@ -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: [email protected]
# 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:
Expand All @@ -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: '*' # 测试使用,线上不要用*,按需开启
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -25,8 +24,6 @@ spring:
- platform: lark
urlKey: 0d944ae7-b24a-40 # 替换
receivers: test1,test2 # 接受人飞书名称/openid
- platform: email
receivers: [email protected],[email protected] # 收件人
dubboTp: # dubbo 线程池配置
- threadPoolName: dubboTp#20880 # 名称规则:dubboTp + "#" + 协议端口
threadPoolAliasName: 测试线程池
Expand All @@ -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: [email protected]
# 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:
Expand All @@ -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: '*' # 测试使用,线上不要用*,按需开启
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -25,8 +24,6 @@ spring:
- platform: lark
urlKey: 0d944ae7-b24a-40 # 替换
receivers: test1,test2 # 接受人飞书名称/openid
- platform: email
receivers: [email protected],[email protected] # 收件人
dubboTp: # dubbo 线程池配置
- threadPoolName: dubboTp#20880 # 名称规则:dubboTp + "#" + 协议端口
threadPoolAliasName: 测试线程池
Expand All @@ -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: [email protected]
# 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:
Expand All @@ -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: '*' # 测试使用,线上不要用*,按需开启
Loading

0 comments on commit 9cab076

Please sign in to comment.