etcd 应用接入
etcd 应用接入dynamictp大约 4 分钟
提示
动态线程池配置文件,建议单独开一个文件放到配置中心 etcd
如果配置中心支持 yml 格式,建议最好使用 yml 文件配置,可读性、可操作性更友好
给出的是全配置项,使用不到的项或者使用默认值的项都可以删除,减少配置量
集成失败 90% 以上情况都是使用姿势有误 / 版本兼容问题,有版本兼容性问题可以提 Issues 或加群反馈
警告
- 下述配置项的值都是随便填写的,请不要直接使用该值,根据自己项目做调整
maven 依赖
SpringBoot1x、2x 用此依赖
<dependency>
<groupId>org.dromara.dynamictp</groupId>
<artifactId>dynamic-tp-spring-boot-starter-etcd</artifactId>
<version>1.2.0</version>
</dependency>
SpringBoot3x 用此依赖
<dependency>
<groupId>org.dromara.dynamictp</groupId>
<artifactId>dynamic-tp-spring-boot-starter-etcd</artifactId>
<version>1.2.0-x</version>
</dependency>
线程池配置文件
properties 格式
dynamictp.enabled=true # 是否启用 dynamictp,默认true
dynamictp.enabledCollect=true # 是否开启监控指标采集,默认true
dynamictp.collectorTypes=micrometer,logging # 监控数据采集器类型(logging | micrometer | internal_logging | JMX),默认micrometer
dynamictp.logPath=/home/logs/dynamictp/user-center/ # 监控日志数据路径,默认 ${user.home}/logs,采集类型非logging不用配置
dynamictp.monitorInterval=5 # 监控时间间隔(报警检测、指标采集),默认5s
# 告警渠道
dynamictp.platforms[0].platform=wechat # 第一个通知平台为微信
dynamictp.platforms[0].platformId=1 # 平台id,自定义
dynamictp.platforms[0].urlKey=3a700-127-4bd-a798-c53d8b69c # webhook 中的 key
dynamictp.platforms[0].receivers=test1,test2 # 接受人企微账号
dynamictp.platforms[1].platform=ding # 第二个通知平台为钉钉
dynamictp.platforms[1].platformId=2 # 平台id,自定义
dynamictp.platforms[1].urlKey=f80dad441fcd655438f4a08dcd6a # webhook 中的 access_token
dynamictp.platforms[1].secret=SECb5441fa6f375d5b9d21 # 安全设置在验签模式下才的秘钥,非验签模式没有此值
dynamictp.platforms[1].receivers=18888888888 # 钉钉账号手机号
dynamictp.platforms[2].platform=lark # 第三个通知平台为飞书
dynamictp.platforms[2].platformId=3 # 平台id,自定义
dynamictp.platforms[2].urlKey=0d944ae7-b24a-40 # webhook 中的 token
dynamictp.platforms[2].secret=3a750012874bdac5c3d8b69c # 安全设置在签名校验模式下才的秘钥,非验签模式没有此值
dynamictp.platforms[2].receivers=test1,test2 # 接受人username / openid
dynamictp.platforms[3].platform=email # 第四个通知平台为邮件
dynamictp.platforms[3].platformId=4 # 平台id,自定义
dynamictp.platforms[3].receivers=123456@qq.com,789789@qq.com # 收件人邮箱,多个用逗号隔开
# 全局配置
dynamictp.globalExecutorProps.rejectedHandlerType=CallerRunsPolicy
dynamictp.globalExecutorProps.queueType=VariableLinkedBlockingQueue
dynamictp.globalExecutorProps.waitForTasksToCompleteOnShutdown=true
dynamictp.globalExecutorProps.awaitTerminationSeconds=3
dynamictp.globalExecutorProps.taskWrapperNames=swTrace,ttl,mdc
dynamictp.globalExecutorProps.queueTimeout=300
dynamictp.globalExecutorProps.runTimeout=300
dynamictp.globalExecutorProps.notifyItems[0].type=change
dynamictp.globalExecutorProps.notifyItems[0].enabled=true
dynamictp.globalExecutorProps.notifyItems[1].type=capacity
dynamictp.globalExecutorProps.notifyItems[1].enabled=true
dynamictp.globalExecutorProps.notifyItems[1].threshold=80
dynamictp.globalExecutorProps.notifyItems[1].platformIds=2
dynamictp.globalExecutorProps.notifyItems[1].interval=120
dynamictp.globalExecutorProps.notifyItems[2].type=liveness
dynamictp.globalExecutorProps.notifyItems[2].enabled=true
dynamictp.globalExecutorProps.notifyItems[2].threshold=80
dynamictp.globalExecutorProps.notifyItems[3].type=reject
dynamictp.globalExecutorProps.notifyItems[3].enabled=true
dynamictp.globalExecutorProps.notifyItems[3].threshold=100
dynamictp.globalExecutorProps.notifyItems[4].type=run_timeout
dynamictp.globalExecutorProps.notifyItems[4].enabled=true
dynamictp.globalExecutorProps.notifyItems[4].threshold=100
dynamictp.globalExecutorProps.notifyItems[5].type=queue_timeout
dynamictp.globalExecutorProps.notifyItems[5].enabled=true
dynamictp.globalExecutorProps.notifyItems[5].threshold=100
# 线程池配置
dynamictp.executors[0].threadPoolName=dtpExecutor1 # 线程池名称,必填
dynamictp.executors[0].threadPoolAliasName=测试线程池 # 线程池别名,可选
dynamictp.executors[0].executorType=common # 线程池类型 common、eager、ordered、scheduled、priority,默认 common
dynamictp.executors[0].corePoolSize=6 # 核心线程数,默认1
dynamictp.executors[0].maximumPoolSize=8 # 最大线程数,默认cpu核数
dynamictp.executors[0].queueCapacity=2000 # 队列容量,默认1024
dynamictp.executors[0].queueType=VariableLinkedBlockingQueue # 任务队列,查看源码QueueTypeEnum枚举类,默认VariableLinkedBlockingQueue
dynamictp.executors[0].rejectedHandlerType=CallerRunsPolicy # 拒绝策略,查看RejectedTypeEnum枚举类,默认AbortPolicy
dynamictp.executors[0].keepAliveTime=60 # 空闲线程等待超时时间,默认60
dynamictp.executors[0].threadNamePrefix=test # 线程名前缀,默认dtp
dynamictp.executors[0].allowCoreThreadTimeOut=false # 是否允许核心线程池超时,默认false
dynamictp.executors[0].waitForTasksToCompleteOnShutdown=true # 参考spring线程池设计,优雅关闭线程池,默认true
dynamictp.executors[0].awaitTerminationSeconds=5 # 优雅关闭线程池时,阻塞等待线程池中任务执行时间,默认3,单位(s)
dynamictp.executors[0].preStartAllCoreThreads=false # 是否预热所有核心线程,默认false
dynamictp.executors[0].runTimeout=200 # 任务执行超时阈值,单位(ms),默认0(不统计)
dynamictp.executors[0].queueTimeout=100 # 任务在队列等待超时阈值,单位(ms),默认0(不统计)
dynamictp.executors[0].taskWrapperNames=ttl,mdc # 任务包装器名称,继承TaskWrapper接口
dynamictp.executors[0].notifyEnabled=true # 是否开启报警,默认true
dynamictp.executors[0].platformIds=1,2
json 格式
{
"dynamictp": {
"enabled": true,
"enabledCollect": true,
"collectorTypes": "micrometer,logging",
"logPath": "/home/logs/dynamictp/user-center/",
"monitorInterval": 5,
"platforms": [
{
"platform": "wechat",
"platformId": 1,
"urlKey": "3a700-127-4bd-a798-c53d8b69c",
"receivers": "test1,test2"
},
{
"platform": "ding",
"platformId": 2,
"urlKey": "f80dad441fcd655438f4a08dcd6a",
"secret": "SECb5441fa6f375d5b9d21",
"receivers": "18888888888"
},
{
"platform": "lark",
"platformId": 3,
"urlKey": "0d944ae7-b24a-40",
"secret": "3a750012874bdac5c3d8b69c",
"receivers": "test1,test2"
},
{
"platform": "email",
"platformId": 4,
"receivers": "123456@qq.com,789789@qq.com"
}
],
"globalExecutorProps": {
"rejectedHandlerType": "CallerRunsPolicy",
"queueType": "VariableLinkedBlockingQueue",
"waitForTasksToCompleteOnShutdown": true,
"awaitTerminationSeconds": 3,
"taskWrapperNames": ["swTrace", "ttl", "mdc"],
"queueTimeout": 300,
"runTimeout": 300,
"notifyItems": [
{
"type": "change",
"enabled": true
},
{
"type": "capacity",
"enabled": true,
"threshold": 80,
"platformIds": [2],
"interval": 120
},
{
"type": "liveness",
"enabled": true,
"threshold": 80
},
{
"type": "reject",
"enabled": true,
"threshold": 100
},
{
"type": "run_timeout",
"enabled": true,
"threshold": 100
},
{
"type": "queue_timeout",
"enabled": true,
"threshold": 100
}
]
},
"executors": [
{
"threadPoolName": "dtpExecutor1",
"threadPoolAliasName": "测试线程池",
"executorType": "common",
"corePoolSize": 6,
"maximumPoolSize": 8,
"queueCapacity": 2000,
"queueType": "VariableLinkedBlockingQueue",
"rejectedHandlerType": "CallerRunsPolicy",
"keepAliveTime": 60,
"threadNamePrefix": "test",
"allowCoreThreadTimeOut": false,
"waitForTasksToCompleteOnShutdown": true,
"awaitTerminationSeconds": 5,
"preStartAllCoreThreads": false,
"runTimeout": 200,
"queueTimeout": 100,
"taskWrapperNames": ["ttl", "mdc"],
"notifyEnabled": true,
"platformIds": [1, 2]
}
]
}
}
application.yml 配置
dynamictp:
config-type: properties
etcd:
endpoints: http://127.0.0.1:2379
auth-enable: false
key: /config/user-center-dtp
application:
name: user-center