From de18fd509e2d600c979fc561e03743f722ab7827 Mon Sep 17 00:00:00 2001 From: "chen.ma" Date: Thu, 18 Nov 2021 22:10:23 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=E6=B6=88=E6=81=AF=E6=8A=A5?= =?UTF-8?q?=E8=AD=A6=E9=80=9A=E7=9F=A5=E6=A8=A1=E5=9D=97,=20=E4=BB=A5?= =?UTF-8?q?=E6=8A=A5=E8=AD=A6=E5=B9=B3=E5=8F=B0=E3=80=81=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E7=BA=AC=E5=BA=A6=E6=8B=86=E5=88=86.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...mInfoMapper.java => NotifyInfoMapper.java} | 6 +- .../model/{AlarmInfo.java => NotifyInfo.java} | 20 +++- .../model/biz/alarm/AlarmListRespDTO.java | 29 ----- .../model/biz/alarm/AlarmQueryReqDTO.java | 22 ---- .../model/biz/notify/NotifyListRespDTO.java | 29 +++++ .../model/biz/notify/NotifyQueryReqDTO.java | 37 +++++++ .../config/model/biz/notify/NotifyReqDTO.java | 59 ++++++++++ .../model/biz/notify/NotifyRespDTO.java | 59 ++++++++++ .../config/service/biz/AlarmService.java | 24 ---- .../config/service/biz/NotifyService.java | 56 ++++++++++ .../service/biz/impl/AlarmServiceImpl.java | 48 -------- .../service/biz/impl/NotifyServiceImpl.java | 104 ++++++++++++++++++ .../console/controller/AlarmController.java | 36 ------ .../console/controller/NotifyController.java | 60 ++++++++++ .../starter/alarm/AlarmControlDTO.java | 8 +- .../starter/alarm/AlarmControlHandler.java | 31 +++--- .../starter/alarm/BaseSendMessageService.java | 61 +++++++--- .../starter/alarm/DingSendMessageHandler.java | 15 ++- .../{AlarmNotifyDTO.java => NotifyDTO.java} | 16 ++- ...ssageEnum.java => NotifyPlatformEnum.java} | 4 +- .../starter/alarm/SendMessageHandler.java | 4 +- .../starter/alarm/SendMessageService.java | 3 +- .../starter/alarm/ThreadPoolAlarmManage.java | 39 +++---- .../starter/config/MessageAlarmConfig.java | 7 +- 24 files changed, 539 insertions(+), 238 deletions(-) rename hippo4j-config/src/main/java/cn/hippo4j/config/mapper/{AlarmInfoMapper.java => NotifyInfoMapper.java} (60%) rename hippo4j-config/src/main/java/cn/hippo4j/config/model/{AlarmInfo.java => NotifyInfo.java} (72%) delete mode 100644 hippo4j-config/src/main/java/cn/hippo4j/config/model/biz/alarm/AlarmListRespDTO.java delete mode 100644 hippo4j-config/src/main/java/cn/hippo4j/config/model/biz/alarm/AlarmQueryReqDTO.java create mode 100644 hippo4j-config/src/main/java/cn/hippo4j/config/model/biz/notify/NotifyListRespDTO.java create mode 100644 hippo4j-config/src/main/java/cn/hippo4j/config/model/biz/notify/NotifyQueryReqDTO.java create mode 100644 hippo4j-config/src/main/java/cn/hippo4j/config/model/biz/notify/NotifyReqDTO.java create mode 100644 hippo4j-config/src/main/java/cn/hippo4j/config/model/biz/notify/NotifyRespDTO.java delete mode 100644 hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/AlarmService.java create mode 100644 hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/NotifyService.java delete mode 100644 hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/impl/AlarmServiceImpl.java create mode 100644 hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/impl/NotifyServiceImpl.java delete mode 100644 hippo4j-console/src/main/java/cn/hippo4j/console/controller/AlarmController.java create mode 100644 hippo4j-console/src/main/java/cn/hippo4j/console/controller/NotifyController.java rename hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/{AlarmNotifyDTO.java => NotifyDTO.java} (69%) rename hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/{SendMessageEnum.java => NotifyPlatformEnum.java} (63%) diff --git a/hippo4j-config/src/main/java/cn/hippo4j/config/mapper/AlarmInfoMapper.java b/hippo4j-config/src/main/java/cn/hippo4j/config/mapper/NotifyInfoMapper.java similarity index 60% rename from hippo4j-config/src/main/java/cn/hippo4j/config/mapper/AlarmInfoMapper.java rename to hippo4j-config/src/main/java/cn/hippo4j/config/mapper/NotifyInfoMapper.java index 1427eb21..a683848b 100644 --- a/hippo4j-config/src/main/java/cn/hippo4j/config/mapper/AlarmInfoMapper.java +++ b/hippo4j-config/src/main/java/cn/hippo4j/config/mapper/NotifyInfoMapper.java @@ -1,15 +1,15 @@ package cn.hippo4j.config.mapper; -import cn.hippo4j.config.model.AlarmInfo; +import cn.hippo4j.config.model.NotifyInfo; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import org.apache.ibatis.annotations.Mapper; /** - * Alarm info mapper. + * Notify info mapper. * * @author chen.ma * @date 2021/11/17 22:04 */ @Mapper -public interface AlarmInfoMapper extends BaseMapper { +public interface NotifyInfoMapper extends BaseMapper { } diff --git a/hippo4j-config/src/main/java/cn/hippo4j/config/model/AlarmInfo.java b/hippo4j-config/src/main/java/cn/hippo4j/config/model/NotifyInfo.java similarity index 72% rename from hippo4j-config/src/main/java/cn/hippo4j/config/model/AlarmInfo.java rename to hippo4j-config/src/main/java/cn/hippo4j/config/model/NotifyInfo.java index 9aa8809f..0fde98f0 100644 --- a/hippo4j-config/src/main/java/cn/hippo4j/config/model/AlarmInfo.java +++ b/hippo4j-config/src/main/java/cn/hippo4j/config/model/NotifyInfo.java @@ -1,5 +1,6 @@ package cn.hippo4j.config.model; +import com.baomidou.mybatisplus.annotation.FieldFill; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; @@ -7,14 +8,14 @@ import lombok.Data; import java.util.Date; /** - * 报警管理. + * 通知管理. * * @author chen.ma * @date 2021/11/17 22:03 */ @Data -@TableName("alarm") -public class AlarmInfo { +@TableName("notify") +public class NotifyInfo { /** * id @@ -41,6 +42,11 @@ public class AlarmInfo { */ private String platform; + /** + * 通知类型 + */ + private String type; + /** * 密钥 */ @@ -60,16 +66,24 @@ public class AlarmInfo { /** * 创建时间 */ + @TableField(fill = FieldFill.INSERT) private Date gmtCreate; /** * 修改时间 */ + @TableField(fill = FieldFill.INSERT_UPDATE) private Date gmtModified; + /** + * 是否启用 + */ + private Integer enable; + /** * 是否删除 */ + @TableField(fill = FieldFill.INSERT) private Integer delFlag; } diff --git a/hippo4j-config/src/main/java/cn/hippo4j/config/model/biz/alarm/AlarmListRespDTO.java b/hippo4j-config/src/main/java/cn/hippo4j/config/model/biz/alarm/AlarmListRespDTO.java deleted file mode 100644 index 39beed04..00000000 --- a/hippo4j-config/src/main/java/cn/hippo4j/config/model/biz/alarm/AlarmListRespDTO.java +++ /dev/null @@ -1,29 +0,0 @@ -package cn.hippo4j.config.model.biz.alarm; - -import cn.hippo4j.config.model.AlarmInfo; -import lombok.AllArgsConstructor; -import lombok.Data; - -import java.util.List; - -/** - * Alarm list resp dto. - * - * @author chen.ma - * @date 2021/11/17 22:53 - */ -@Data -@AllArgsConstructor -public class AlarmListRespDTO { - - /** - * 线程池ID - */ - private String threadPoolId; - - /** - * 报警配置 - */ - private List alarmNotifyList; - -} diff --git a/hippo4j-config/src/main/java/cn/hippo4j/config/model/biz/alarm/AlarmQueryReqDTO.java b/hippo4j-config/src/main/java/cn/hippo4j/config/model/biz/alarm/AlarmQueryReqDTO.java deleted file mode 100644 index 458326e2..00000000 --- a/hippo4j-config/src/main/java/cn/hippo4j/config/model/biz/alarm/AlarmQueryReqDTO.java +++ /dev/null @@ -1,22 +0,0 @@ -package cn.hippo4j.config.model.biz.alarm; - -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import lombok.Data; - -import java.util.List; - -/** - * Alarm query req dto. - * - * @author chen.ma - * @date 2021/11/17 22:52 - */ -@Data -public class AlarmQueryReqDTO extends Page { - - /** - * groupKeys - */ - private List groupKeys; - -} diff --git a/hippo4j-config/src/main/java/cn/hippo4j/config/model/biz/notify/NotifyListRespDTO.java b/hippo4j-config/src/main/java/cn/hippo4j/config/model/biz/notify/NotifyListRespDTO.java new file mode 100644 index 00000000..ce34d053 --- /dev/null +++ b/hippo4j-config/src/main/java/cn/hippo4j/config/model/biz/notify/NotifyListRespDTO.java @@ -0,0 +1,29 @@ +package cn.hippo4j.config.model.biz.notify; + +import cn.hippo4j.config.model.NotifyInfo; +import lombok.AllArgsConstructor; +import lombok.Data; + +import java.util.List; + +/** + * Notify list resp dto. + * + * @author chen.ma + * @date 2021/11/17 22:53 + */ +@Data +@AllArgsConstructor +public class NotifyListRespDTO { + + /** + * 通知 Key + */ + private String notifyKey; + + /** + * 通知配置 + */ + private List notifyList; + +} diff --git a/hippo4j-config/src/main/java/cn/hippo4j/config/model/biz/notify/NotifyQueryReqDTO.java b/hippo4j-config/src/main/java/cn/hippo4j/config/model/biz/notify/NotifyQueryReqDTO.java new file mode 100644 index 00000000..c9b14954 --- /dev/null +++ b/hippo4j-config/src/main/java/cn/hippo4j/config/model/biz/notify/NotifyQueryReqDTO.java @@ -0,0 +1,37 @@ +package cn.hippo4j.config.model.biz.notify; + +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import lombok.Data; + +import java.util.List; + +/** + * Notify query req dto. + * + * @author chen.ma + * @date 2021/11/17 22:52 + */ +@Data +public class NotifyQueryReqDTO extends Page { + + /** + * groupKeys + */ + private List groupKeys; + + /** + * 租户id + */ + private String tenantId; + + /** + * 项目id + */ + private String itemId; + + /** + * 线程池id + */ + private String tpId; + +} diff --git a/hippo4j-config/src/main/java/cn/hippo4j/config/model/biz/notify/NotifyReqDTO.java b/hippo4j-config/src/main/java/cn/hippo4j/config/model/biz/notify/NotifyReqDTO.java new file mode 100644 index 00000000..21b7a314 --- /dev/null +++ b/hippo4j-config/src/main/java/cn/hippo4j/config/model/biz/notify/NotifyReqDTO.java @@ -0,0 +1,59 @@ +package cn.hippo4j.config.model.biz.notify; + +import lombok.Data; + +/** + * 消息通知入参实体. + * + * @author chen.ma + * @date 2021/11/18 20:15 + */ +@Data +public class NotifyReqDTO { + + /** + * 租户id + */ + private String tenantId; + + /** + * 项目id + */ + private String itemId; + + /** + * 线程池id + */ + private String tpId; + + /** + * 通知平台 + */ + private String platform; + + /** + * 通知类型 + */ + private String type; + + /** + * 密钥 + */ + private String secretKey; + + /** + * 报警间隔 + */ + private Integer interval; + + /** + * 接收者 + */ + private String receives; + + /** + * 是否启用 + */ + private Integer enable; + +} diff --git a/hippo4j-config/src/main/java/cn/hippo4j/config/model/biz/notify/NotifyRespDTO.java b/hippo4j-config/src/main/java/cn/hippo4j/config/model/biz/notify/NotifyRespDTO.java new file mode 100644 index 00000000..4e10b9f3 --- /dev/null +++ b/hippo4j-config/src/main/java/cn/hippo4j/config/model/biz/notify/NotifyRespDTO.java @@ -0,0 +1,59 @@ +package cn.hippo4j.config.model.biz.notify; + +import lombok.Data; + +/** + * 消息通知返回. + * + * @author chen.ma + * @date 2021/11/18 20:07 + */ +@Data +public class NotifyRespDTO { + + /** + * 租户id + */ + private String tenantId; + + /** + * 项目id + */ + private String itemId; + + /** + * 线程池id + */ + private String tpId; + + /** + * 通知平台 + */ + private String platform; + + /** + * 通知类型 + */ + private String type; + + /** + * 密钥 + */ + private String secretKey; + + /** + * 报警间隔 + */ + private Integer interval; + + /** + * 接收者 + */ + private String receives; + + /** + * 是否启用 + */ + private Integer enable; + +} diff --git a/hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/AlarmService.java b/hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/AlarmService.java deleted file mode 100644 index d6df4c0c..00000000 --- a/hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/AlarmService.java +++ /dev/null @@ -1,24 +0,0 @@ -package cn.hippo4j.config.service.biz; - -import cn.hippo4j.config.model.biz.alarm.AlarmListRespDTO; -import cn.hippo4j.config.model.biz.alarm.AlarmQueryReqDTO; - -import java.util.List; - -/** - * 报警管理. - * - * @author chen.ma - * @date 2021/11/17 22:01 - */ -public interface AlarmService { - - /** - * 查询报警配置集合. - * - * @param reqDTO - * @return - */ - List listAlarmConfig(AlarmQueryReqDTO reqDTO); - -} diff --git a/hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/NotifyService.java b/hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/NotifyService.java new file mode 100644 index 00000000..64e1bd8f --- /dev/null +++ b/hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/NotifyService.java @@ -0,0 +1,56 @@ +package cn.hippo4j.config.service.biz; + +import cn.hippo4j.config.model.biz.notify.NotifyListRespDTO; +import cn.hippo4j.config.model.biz.notify.NotifyQueryReqDTO; +import cn.hippo4j.config.model.biz.notify.NotifyReqDTO; +import cn.hippo4j.config.model.biz.notify.NotifyRespDTO; +import com.baomidou.mybatisplus.core.metadata.IPage; + +import java.util.List; + +/** + * 通知管理. + * + * @author chen.ma + * @date 2021/11/17 22:01 + */ +public interface NotifyService { + + /** + * 查询通知配置集合. + * + * @param reqDTO + * @return + */ + List listNotifyConfig(NotifyQueryReqDTO reqDTO); + + /** + * 分页查询. + * + * @param reqDTO + * @return + */ + IPage queryPage(NotifyQueryReqDTO reqDTO); + + /** + * 新增通知配置. + * + * @param reqDTO + */ + void save(NotifyReqDTO reqDTO); + + /** + * 修改通知配置. + * + * @param reqDTO + */ + void update(NotifyReqDTO reqDTO); + + /** + * 删除通知配置. + * + * @param reqDTO + */ + void delete(NotifyReqDTO reqDTO); + +} diff --git a/hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/impl/AlarmServiceImpl.java b/hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/impl/AlarmServiceImpl.java deleted file mode 100644 index 7ddddb9b..00000000 --- a/hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/impl/AlarmServiceImpl.java +++ /dev/null @@ -1,48 +0,0 @@ -package cn.hippo4j.config.service.biz.impl; - -import cn.hippo4j.common.toolkit.GroupKey; -import cn.hippo4j.config.mapper.AlarmInfoMapper; -import cn.hippo4j.config.model.AlarmInfo; -import cn.hippo4j.config.model.biz.alarm.AlarmListRespDTO; -import cn.hippo4j.config.model.biz.alarm.AlarmQueryReqDTO; -import cn.hippo4j.config.service.biz.AlarmService; -import cn.hutool.core.collection.CollUtil; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.baomidou.mybatisplus.core.toolkit.Wrappers; -import com.google.common.collect.Lists; -import lombok.AllArgsConstructor; -import org.springframework.stereotype.Service; - -import java.util.List; - -/** - * 报警管理. - * - * @author chen.ma - * @date 2021/11/17 22:02 - */ -@Service -@AllArgsConstructor -public class AlarmServiceImpl implements AlarmService { - - private final AlarmInfoMapper alarmInfoMapper; - - @Override - public List listAlarmConfig(AlarmQueryReqDTO reqDTO) { - List alarmListRespList = Lists.newArrayList(); - reqDTO.getGroupKeys().forEach(each -> { - String[] parseKey = GroupKey.parseKey(each); - LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery(AlarmInfo.class) - .eq(AlarmInfo::getTenantId, parseKey[2]) - .eq(AlarmInfo::getItemId, parseKey[1]) - .eq(AlarmInfo::getTpId, parseKey[0]); - List alarmInfos = alarmInfoMapper.selectList(queryWrapper); - if (CollUtil.isNotEmpty(alarmInfos)) { - alarmListRespList.add(new AlarmListRespDTO(parseKey[0], alarmInfos)); - } - }); - - return alarmListRespList; - } - -} diff --git a/hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/impl/NotifyServiceImpl.java b/hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/impl/NotifyServiceImpl.java new file mode 100644 index 00000000..d83b5ce8 --- /dev/null +++ b/hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/impl/NotifyServiceImpl.java @@ -0,0 +1,104 @@ +package cn.hippo4j.config.service.biz.impl; + +import cn.hippo4j.common.toolkit.GroupKey; +import cn.hippo4j.config.enums.DelEnum; +import cn.hippo4j.config.mapper.NotifyInfoMapper; +import cn.hippo4j.config.model.NotifyInfo; +import cn.hippo4j.config.model.biz.notify.NotifyListRespDTO; +import cn.hippo4j.config.model.biz.notify.NotifyQueryReqDTO; +import cn.hippo4j.config.model.biz.notify.NotifyReqDTO; +import cn.hippo4j.config.model.biz.notify.NotifyRespDTO; +import cn.hippo4j.config.service.biz.NotifyService; +import cn.hippo4j.config.toolkit.BeanUtil; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.StrUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.google.common.collect.Lists; +import lombok.AllArgsConstructor; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * 通知管理. + * + * @author chen.ma + * @date 2021/11/17 22:02 + */ +@Service +@AllArgsConstructor +public class NotifyServiceImpl implements NotifyService { + + private final NotifyInfoMapper notifyInfoMapper; + + @Override + public List listNotifyConfig(NotifyQueryReqDTO reqDTO) { + List notifyListRespList = Lists.newArrayList(); + reqDTO.getGroupKeys().forEach(each -> { + String[] parseKey = GroupKey.parseKey(each); + List notifyInfos = listNotifyCommon("CONFIG", parseKey); + if (CollUtil.isNotEmpty(notifyInfos)) { + notifyListRespList.add(new NotifyListRespDTO(StrUtil.builder(parseKey[0], "+", "CONFIG").toString(), notifyInfos)); + } + + List alarmInfos = listNotifyCommon("ALARM", parseKey); + if (CollUtil.isNotEmpty(alarmInfos)) { + notifyListRespList.add(new NotifyListRespDTO(StrUtil.builder(parseKey[0], "+", "ALARM").toString(), alarmInfos)); + } + }); + + return notifyListRespList; + } + + @Override + public IPage queryPage(NotifyQueryReqDTO reqDTO) { + LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery(NotifyInfo.class) + .eq(StrUtil.isNotBlank(reqDTO.getTenantId()), NotifyInfo::getTenantId, reqDTO.getTenantId()) + .eq(StrUtil.isNotBlank(reqDTO.getItemId()), NotifyInfo::getItemId, reqDTO.getItemId()) + .eq(StrUtil.isNotBlank(reqDTO.getTpId()), NotifyInfo::getTpId, reqDTO.getTpId()); + + IPage resultPage = notifyInfoMapper.selectPage(reqDTO, queryWrapper); + return resultPage.convert(each -> BeanUtil.convert(each, NotifyRespDTO.class)); + } + + @Override + public void save(NotifyReqDTO reqDTO) { + notifyInfoMapper.insert(BeanUtil.convert(reqDTO, NotifyInfo.class)); + } + + @Override + public void update(NotifyReqDTO reqDTO) { + NotifyInfo notifyInfo = BeanUtil.convert(reqDTO, NotifyInfo.class); + LambdaUpdateWrapper updateWrapper = Wrappers.lambdaUpdate(NotifyInfo.class) + .eq(NotifyInfo::getTenantId, reqDTO.getTenantId()) + .eq(NotifyInfo::getItemId, reqDTO.getItemId()) + .eq(NotifyInfo::getTpId, reqDTO.getTpId()); + + notifyInfoMapper.update(notifyInfo, updateWrapper); + } + + @Override + public void delete(NotifyReqDTO reqDTO) { + LambdaUpdateWrapper updateWrapper = Wrappers.lambdaUpdate(NotifyInfo.class) + .eq(NotifyInfo::getTenantId, reqDTO.getTenantId()) + .eq(NotifyInfo::getItemId, reqDTO.getItemId()) + .eq(NotifyInfo::getTpId, reqDTO.getTpId()); + + notifyInfoMapper.delete(updateWrapper); + } + + private List listNotifyCommon(String type, String[] parseKey) { + LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery(NotifyInfo.class) + .eq(NotifyInfo::getTenantId, parseKey[2]) + .eq(NotifyInfo::getItemId, parseKey[1]) + .eq(NotifyInfo::getTpId, parseKey[0]) + .eq(NotifyInfo::getEnable, DelEnum.NORMAL) + .eq(NotifyInfo::getType, type); + List notifyInfos = notifyInfoMapper.selectList(queryWrapper); + return notifyInfos; + } + +} diff --git a/hippo4j-console/src/main/java/cn/hippo4j/console/controller/AlarmController.java b/hippo4j-console/src/main/java/cn/hippo4j/console/controller/AlarmController.java deleted file mode 100644 index f3024971..00000000 --- a/hippo4j-console/src/main/java/cn/hippo4j/console/controller/AlarmController.java +++ /dev/null @@ -1,36 +0,0 @@ -package cn.hippo4j.console.controller; - -import cn.hippo4j.common.constant.Constants; -import cn.hippo4j.common.web.base.Result; -import cn.hippo4j.common.web.base.Results; -import cn.hippo4j.config.model.biz.alarm.AlarmListRespDTO; -import cn.hippo4j.config.model.biz.alarm.AlarmQueryReqDTO; -import cn.hippo4j.config.service.biz.AlarmService; -import lombok.AllArgsConstructor; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import java.util.List; - -/** - * 报警管理. - * - * @author chen.ma - * @date 2021/11/17 22:00 - */ -@RestController -@AllArgsConstructor -@RequestMapping(Constants.BASE_PATH + "/alarm") -public class AlarmController { - - private final AlarmService alarmService; - - @PostMapping("/list/config") - public Result> listAlarmConfig(@RequestBody AlarmQueryReqDTO reqDTO) { - List resultData = alarmService.listAlarmConfig(reqDTO); - return Results.success(resultData); - } - -} diff --git a/hippo4j-console/src/main/java/cn/hippo4j/console/controller/NotifyController.java b/hippo4j-console/src/main/java/cn/hippo4j/console/controller/NotifyController.java new file mode 100644 index 00000000..7ef71825 --- /dev/null +++ b/hippo4j-console/src/main/java/cn/hippo4j/console/controller/NotifyController.java @@ -0,0 +1,60 @@ +package cn.hippo4j.console.controller; + +import cn.hippo4j.common.constant.Constants; +import cn.hippo4j.common.web.base.Result; +import cn.hippo4j.common.web.base.Results; +import cn.hippo4j.config.model.biz.notify.NotifyListRespDTO; +import cn.hippo4j.config.model.biz.notify.NotifyQueryReqDTO; +import cn.hippo4j.config.model.biz.notify.NotifyReqDTO; +import cn.hippo4j.config.model.biz.notify.NotifyRespDTO; +import cn.hippo4j.config.service.biz.NotifyService; +import com.baomidou.mybatisplus.core.metadata.IPage; +import lombok.AllArgsConstructor; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +/** + * 通知管理. + * + * @author chen.ma + * @date 2021/11/17 22:00 + */ +@RestController +@AllArgsConstructor +@RequestMapping(Constants.BASE_PATH + "/notify") +public class NotifyController { + + private final NotifyService notifyService; + + @PostMapping("/list/config") + public Result> listNotifyConfig(@RequestBody NotifyQueryReqDTO reqDTO) { + List resultData = notifyService.listNotifyConfig(reqDTO); + return Results.success(resultData); + } + + @PostMapping("/query/page") + public Result> queryPage(@RequestBody NotifyQueryReqDTO reqDTO) { + IPage resultPage = notifyService.queryPage(reqDTO); + return Results.success(resultPage); + } + + @PostMapping("/save") + public Result saveNotifyConfig(@RequestBody NotifyReqDTO reqDTO) { + notifyService.save(reqDTO); + return Results.success(); + } + + @PostMapping("/update") + public Result updateNotifyConfig(@RequestBody NotifyReqDTO reqDTO) { + notifyService.update(reqDTO); + return Results.success(); + } + + @DeleteMapping("/remove") + public Result removeNotifyConfig(@RequestBody NotifyReqDTO reqDTO) { + notifyService.delete(reqDTO); + return Results.success(); + } + +} diff --git a/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/AlarmControlDTO.java b/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/AlarmControlDTO.java index 8d7cdd8a..bcafcf79 100644 --- a/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/AlarmControlDTO.java +++ b/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/AlarmControlDTO.java @@ -1,5 +1,6 @@ package cn.hippo4j.starter.alarm; +import cn.hutool.core.util.StrUtil; import lombok.Builder; import lombok.Data; @@ -18,6 +19,11 @@ public class AlarmControlDTO { */ private String threadPool; + /** + * 推送报警平台 + */ + private String platform; + /** * 推送报警类型 */ @@ -29,7 +35,7 @@ public class AlarmControlDTO { * @return */ public String buildPk() { - return threadPool + "_" + typeEnum; + return StrUtil.builder(threadPool, "+", platform).toString(); } } diff --git a/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/AlarmControlHandler.java b/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/AlarmControlHandler.java index 890229c8..7b0c9249 100644 --- a/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/AlarmControlHandler.java +++ b/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/AlarmControlHandler.java @@ -2,10 +2,11 @@ package cn.hippo4j.starter.alarm; import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSON; import com.google.common.cache.Cache; -import com.google.common.cache.CacheBuilder; +import com.google.common.collect.Maps; -import java.util.concurrent.TimeUnit; +import java.util.Map; /** * 报警控制组件. @@ -15,13 +16,7 @@ import java.util.concurrent.TimeUnit; */ public class AlarmControlHandler { - private final Cache cache; - - public AlarmControlHandler(long alarmInterval) { - cache = CacheBuilder.newBuilder() - .expireAfterWrite(alarmInterval, TimeUnit.MINUTES) - .build(); - } + public static Map> THREAD_POOL_ALARM_CACHE = Maps.newConcurrentMap(); /** * 控制消息推送报警频率. @@ -29,13 +24,17 @@ public class AlarmControlHandler { * @param alarmControl * @return */ - public boolean isSend(AlarmControlDTO alarmControl) { - String pkId = cache.getIfPresent(alarmControl.buildPk()); - - if (StrUtil.isBlank(pkId)) { - // val 无意义 - cache.put(alarmControl.buildPk(), IdUtil.simpleUUID()); - return true; + public boolean isSendAlarm(AlarmControlDTO alarmControl) { + Cache cache = THREAD_POOL_ALARM_CACHE.get(alarmControl.buildPk()); + if (cache != null) { + String pkId = cache.getIfPresent(alarmControl.getTypeEnum().name()); + if (StrUtil.isBlank(pkId)) { + // val 无意义 + cache.put(alarmControl.getTypeEnum().name(), IdUtil.simpleUUID()); + return true; + } else { + System.out.println(JSON.toJSONString(alarmControl)); + } } return false; diff --git a/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/BaseSendMessageService.java b/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/BaseSendMessageService.java index 671a92e8..47e6db85 100644 --- a/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/BaseSendMessageService.java +++ b/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/BaseSendMessageService.java @@ -9,7 +9,10 @@ import cn.hippo4j.starter.core.DynamicThreadPoolExecutor; import cn.hippo4j.starter.core.GlobalThreadPoolManage; import cn.hippo4j.starter.remote.HttpAgent; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson.JSON; +import com.google.common.cache.Cache; +import com.google.common.cache.CacheBuilder; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import lombok.AllArgsConstructor; @@ -21,6 +24,7 @@ import org.springframework.beans.factory.InitializingBean; import java.util.List; import java.util.Map; +import java.util.concurrent.TimeUnit; /** * Base send message service. @@ -38,14 +42,17 @@ public class BaseSendMessageService implements InitializingBean, SendMessageServ @NonNull private final BootstrapProperties properties; - private final static Map> ALARM_NOTIFY_CONFIG = Maps.newHashMap(); + @NonNull + private final AlarmControlHandler alarmControlHandler; + public final static Map> ALARM_NOTIFY_CONFIG = Maps.newHashMap(); private final Map sendMessageHandlers = Maps.newHashMap(); @Override - public void sendAlarmMessage(DynamicThreadPoolExecutor threadPoolExecutor) { - List notifyList = ALARM_NOTIFY_CONFIG.get(threadPoolExecutor.getThreadPoolId()); + public void sendAlarmMessage(MessageTypeEnum typeEnum, DynamicThreadPoolExecutor executor) { + String buildKey = StrUtil.builder(executor.getThreadPoolId(), "+", "ALARM").toString(); + List notifyList = ALARM_NOTIFY_CONFIG.get(buildKey); if (CollUtil.isEmpty(notifyList)) { log.warn("Please configure alarm notification on the server."); return; @@ -59,7 +66,9 @@ public class BaseSendMessageService implements InitializingBean, SendMessageServ return; } - messageHandler.sendAlarmMessage(each, threadPoolExecutor); + if (isSendAlarm(each.getTpId(), each.setTypeEnum(typeEnum))) { + messageHandler.sendAlarmMessage(each, executor); + } } catch (Exception ex) { log.warn("Failed to send thread pool alarm notification.", ex); } @@ -68,7 +77,8 @@ public class BaseSendMessageService implements InitializingBean, SendMessageServ @Override public void sendChangeMessage(PoolParameterInfo parameter) { - List notifyList = ALARM_NOTIFY_CONFIG.get(parameter.getTpId()); + String buildKey = StrUtil.builder(parameter.getTpId(), "+", "CONFIG").toString(); + List notifyList = ALARM_NOTIFY_CONFIG.get(buildKey); if (CollUtil.isEmpty(notifyList)) { log.warn("Please configure alarm notification on the server."); return; @@ -109,22 +119,41 @@ public class BaseSendMessageService implements InitializingBean, SendMessageServ Result result = null; try { - result = httpAgent.httpPostByDiscovery("/v1/cs/alarm/list/config", new ThreadPoolAlarmReqDTO(groupKeys)); + result = httpAgent.httpPostByDiscovery("/v1/cs/notify/list/config", new ThreadPoolNotifyReqDTO(groupKeys)); } catch (Throwable ex) { - log.error("Get dynamic thread pool alarm configuration error.", ex); - throw ex; + log.error("Get dynamic thread pool notify configuration error.", ex); } - if (result.isSuccess() || result.getData() != null) { + if (result != null && result.isSuccess() && result.getData() != null) { String resultDataStr = JSON.toJSONString(result.getData()); - List resultData = JSON.parseArray(resultDataStr, ThreadPoolAlarmNotify.class); - resultData.forEach(each -> ALARM_NOTIFY_CONFIG.put(each.getThreadPoolId(), each.getAlarmNotifyList())); + List resultData = JSON.parseArray(resultDataStr, ThreadPoolNotify.class); + resultData.forEach(each -> ALARM_NOTIFY_CONFIG.put(each.getNotifyKey(), each.getNotifyList())); + + ALARM_NOTIFY_CONFIG.forEach((key, val) -> + val.stream().filter(each -> StrUtil.equals("ALARM", each.getType())) + .forEach(each -> { + Cache cache = CacheBuilder.newBuilder() + .expireAfterWrite(each.getInterval(), TimeUnit.MINUTES) + .build(); + AlarmControlHandler.THREAD_POOL_ALARM_CACHE.put(StrUtil.builder(each.getTpId(), "+", each.getPlatform()).toString(), cache); + }) + ); } } + private boolean isSendAlarm(String threadPoolId, NotifyDTO notifyInfo) { + AlarmControlDTO alarmControl = AlarmControlDTO.builder() + .threadPool(threadPoolId) + .platform(notifyInfo.getPlatform()) + .typeEnum(notifyInfo.getTypeEnum()) + .build(); + + return alarmControlHandler.isSendAlarm(alarmControl); + } + @Data @AllArgsConstructor - static class ThreadPoolAlarmReqDTO { + static class ThreadPoolNotifyReqDTO { /** * groupKeys @@ -134,17 +163,17 @@ public class BaseSendMessageService implements InitializingBean, SendMessageServ } @Data - static class ThreadPoolAlarmNotify { + static class ThreadPoolNotify { /** - * 线程池ID + * 通知 Key */ - private String threadPoolId; + private String notifyKey; /** * 报警配置 */ - private List alarmNotifyList; + private List notifyList; } diff --git a/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/DingSendMessageHandler.java b/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/DingSendMessageHandler.java index 1c329e2c..a98bc02f 100644 --- a/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/DingSendMessageHandler.java +++ b/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/DingSendMessageHandler.java @@ -37,20 +37,20 @@ public class DingSendMessageHandler implements SendMessageHandler { @Override public String getType() { - return SendMessageEnum.DING.name(); + return NotifyPlatformEnum.DING.name(); } @Override - public void sendAlarmMessage(AlarmNotifyDTO notifyConfig, DynamicThreadPoolExecutor pool) { + public void sendAlarmMessage(NotifyDTO notifyConfig, DynamicThreadPoolExecutor pool) { dingAlarmSendMessage(notifyConfig, pool); } @Override - public void sendChangeMessage(AlarmNotifyDTO notifyConfig, PoolParameterInfo parameter) { + public void sendChangeMessage(NotifyDTO notifyConfig, PoolParameterInfo parameter) { dingChangeSendMessage(notifyConfig, parameter); } - private void dingAlarmSendMessage(AlarmNotifyDTO notifyConfig, DynamicThreadPoolExecutor pool) { + private void dingAlarmSendMessage(NotifyDTO notifyConfig, DynamicThreadPoolExecutor pool) { List receives = StrUtil.split(notifyConfig.getReceives(), ','); String afterReceives = Joiner.on(", @").join(receives); @@ -61,6 +61,7 @@ public class DingSendMessageHandler implements SendMessageHandler { "线程池ID:%s \n\n " + "应用名称:%s \n\n " + "应用实例:%s \n\n " + + "报警类型:%s \n\n " + " --- \n\n " + "核心线程数:%d \n\n " + "最大线程数:%d \n\n " + @@ -89,6 +90,8 @@ public class DingSendMessageHandler implements SendMessageHandler { instanceInfo.getAppName(), // 实例信息 instanceInfo.getIdentify(), + // 报警类型 + notifyConfig.getTypeEnum(), // 核心线程数 pool.getCorePoolSize(), // 最大线程数 @@ -124,7 +127,7 @@ public class DingSendMessageHandler implements SendMessageHandler { execute(notifyConfig, "动态线程池告警", text, receives); } - private void dingChangeSendMessage(AlarmNotifyDTO notifyConfig, PoolParameterInfo parameter) { + private void dingChangeSendMessage(NotifyDTO notifyConfig, PoolParameterInfo parameter) { String threadPoolId = parameter.getTpId(); DynamicThreadPoolWrapper poolWrap = GlobalThreadPoolManage.getExecutorService(threadPoolId); if (poolWrap == null) { @@ -190,7 +193,7 @@ public class DingSendMessageHandler implements SendMessageHandler { execute(notifyConfig, "动态线程池通知", text, receives); } - private void execute(AlarmNotifyDTO notifyConfig, String title, String text, List mobiles) { + private void execute(NotifyDTO notifyConfig, String title, String text, List mobiles) { String url = "https://oapi.dingtalk.com/robot/send?access_token="; String serverUrl = url + notifyConfig.getSecretKey(); DingTalkClient dingTalkClient = new DefaultDingTalkClient(serverUrl); diff --git a/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/AlarmNotifyDTO.java b/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/NotifyDTO.java similarity index 69% rename from hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/AlarmNotifyDTO.java rename to hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/NotifyDTO.java index 4b92e4e5..93a514cc 100644 --- a/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/AlarmNotifyDTO.java +++ b/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/NotifyDTO.java @@ -1,15 +1,17 @@ package cn.hippo4j.starter.alarm; import lombok.Data; +import lombok.experimental.Accessors; /** - * 报警通知实体. + * 通知实体. * * @author chen.ma * @date 2021/11/17 22:12 */ @Data -public class AlarmNotifyDTO { +@Accessors(chain = true) +public class NotifyDTO { /** * 租户id @@ -31,6 +33,11 @@ public class AlarmNotifyDTO { */ private String platform; + /** + * 通知类型 + */ + private String type; + /** * 密钥 */ @@ -46,4 +53,9 @@ public class AlarmNotifyDTO { */ private String receives; + /** + * 报警类型 + */ + private MessageTypeEnum typeEnum; + } diff --git a/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/SendMessageEnum.java b/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/NotifyPlatformEnum.java similarity index 63% rename from hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/SendMessageEnum.java rename to hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/NotifyPlatformEnum.java index f11d2ccf..bedff82f 100644 --- a/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/SendMessageEnum.java +++ b/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/NotifyPlatformEnum.java @@ -1,12 +1,12 @@ package cn.hippo4j.starter.alarm; /** - * Send message enum. + * Notify platform enum. * * @author chen.ma * @date 2021/8/15 15:50 */ -public enum SendMessageEnum { +public enum NotifyPlatformEnum { DING diff --git a/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/SendMessageHandler.java b/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/SendMessageHandler.java index 0361967f..ca26ff86 100644 --- a/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/SendMessageHandler.java +++ b/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/SendMessageHandler.java @@ -24,7 +24,7 @@ public interface SendMessageHandler { * @param notifyConfig * @param threadPoolExecutor */ - void sendAlarmMessage(AlarmNotifyDTO notifyConfig, DynamicThreadPoolExecutor threadPoolExecutor); + void sendAlarmMessage(NotifyDTO notifyConfig, DynamicThreadPoolExecutor threadPoolExecutor); /** * Send change message. @@ -32,6 +32,6 @@ public interface SendMessageHandler { * @param notifyConfig * @param parameter */ - void sendChangeMessage(AlarmNotifyDTO notifyConfig, PoolParameterInfo parameter); + void sendChangeMessage(NotifyDTO notifyConfig, PoolParameterInfo parameter); } diff --git a/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/SendMessageService.java b/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/SendMessageService.java index 0f754ac5..66930beb 100644 --- a/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/SendMessageService.java +++ b/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/SendMessageService.java @@ -14,9 +14,10 @@ public interface SendMessageService { /** * Send alarm message. * + * @param typeEnum * @param threadPoolExecutor */ - void sendAlarmMessage(DynamicThreadPoolExecutor threadPoolExecutor); + void sendAlarmMessage(MessageTypeEnum typeEnum, DynamicThreadPoolExecutor threadPoolExecutor); /** * Send change message. diff --git a/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/ThreadPoolAlarmManage.java b/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/ThreadPoolAlarmManage.java index fa1b704f..dd73e404 100644 --- a/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/ThreadPoolAlarmManage.java +++ b/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/alarm/ThreadPoolAlarmManage.java @@ -5,10 +5,10 @@ import cn.hippo4j.common.model.PoolParameterInfo; import cn.hippo4j.starter.config.MessageAlarmConfig; import cn.hippo4j.starter.core.DynamicThreadPoolExecutor; import cn.hippo4j.starter.toolkit.CalculateUtil; -import cn.hippo4j.starter.toolkit.thread.ResizableCapacityLinkedBlockIngQueue; import lombok.extern.slf4j.Slf4j; import java.util.Optional; +import java.util.concurrent.BlockingQueue; /** * Alarm manage. @@ -24,19 +24,11 @@ public class ThreadPoolAlarmManage { */ private static final SendMessageService SEND_MESSAGE_SERVICE; - /** - * 报警间隔控制 - */ - private static final AlarmControlHandler ALARM_CONTROL_HANDLER; - static { SEND_MESSAGE_SERVICE = Optional.ofNullable(ApplicationContextHolder.getInstance()) .map(each -> each.getBean(MessageAlarmConfig.SEND_MESSAGE_BEAN_NAME, SendMessageService.class)) .orElse(null); - - ALARM_CONTROL_HANDLER = Optional.ofNullable(ApplicationContextHolder.getInstance()) - .map(each -> each.getBean(AlarmControlHandler.class)) - .orElse(null); + System.out.println(); } /** @@ -49,16 +41,16 @@ public class ThreadPoolAlarmManage { return; } ThreadPoolAlarm threadPoolAlarm = threadPoolExecutor.getThreadPoolAlarm(); - ResizableCapacityLinkedBlockIngQueue blockIngQueue = - (ResizableCapacityLinkedBlockIngQueue) threadPoolExecutor.getQueue(); + BlockingQueue blockIngQueue = threadPoolExecutor.getQueue(); int queueSize = blockIngQueue.size(); int capacity = queueSize + blockIngQueue.remainingCapacity(); int divide = CalculateUtil.divide(queueSize, capacity); - boolean isSend = divide > threadPoolAlarm.getCapacityAlarm() + boolean isSend = threadPoolAlarm.getIsAlarm() + && divide > threadPoolAlarm.getCapacityAlarm() && isSendMessage(threadPoolExecutor, MessageTypeEnum.CAPACITY); if (isSend) { - SEND_MESSAGE_SERVICE.sendAlarmMessage(threadPoolExecutor); + SEND_MESSAGE_SERVICE.sendAlarmMessage(MessageTypeEnum.CAPACITY, threadPoolExecutor); } } @@ -76,10 +68,13 @@ public class ThreadPoolAlarmManage { int maximumPoolSize = threadPoolExecutor.getMaximumPoolSize(); int divide = CalculateUtil.divide(activeCount, maximumPoolSize); - boolean isSend = divide > threadPoolExecutor.getThreadPoolAlarm().getLivenessAlarm() + ThreadPoolAlarm threadPoolAlarm = threadPoolExecutor.getThreadPoolAlarm(); + + boolean isSend = threadPoolAlarm.getIsAlarm() + && divide > threadPoolAlarm.getLivenessAlarm() && isSendMessage(threadPoolExecutor, MessageTypeEnum.CAPACITY); if (isSend) { - SEND_MESSAGE_SERVICE.sendAlarmMessage(threadPoolExecutor); + SEND_MESSAGE_SERVICE.sendAlarmMessage(MessageTypeEnum.CAPACITY, threadPoolExecutor); } } @@ -93,8 +88,9 @@ public class ThreadPoolAlarmManage { return; } - if (isSendMessage(threadPoolExecutor, MessageTypeEnum.REJECT)) { - SEND_MESSAGE_SERVICE.sendAlarmMessage(threadPoolExecutor); + ThreadPoolAlarm threadPoolAlarm = threadPoolExecutor.getThreadPoolAlarm(); + if (threadPoolAlarm.getIsAlarm() && isSendMessage(threadPoolExecutor, MessageTypeEnum.REJECT)) { + SEND_MESSAGE_SERVICE.sendAlarmMessage(MessageTypeEnum.REJECT, threadPoolExecutor); } } @@ -119,11 +115,8 @@ public class ThreadPoolAlarmManage { * @return */ private static boolean isSendMessage(DynamicThreadPoolExecutor threadPoolExecutor, MessageTypeEnum typeEnum) { - AlarmControlDTO alarmControl = AlarmControlDTO.builder() - .threadPool(threadPoolExecutor.getThreadPoolId()) - .typeEnum(typeEnum) - .build(); - return ALARM_CONTROL_HANDLER.isSend(alarmControl); + // ignore + return true; } } diff --git a/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/config/MessageAlarmConfig.java b/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/config/MessageAlarmConfig.java index 774aa6fc..ceb0907e 100644 --- a/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/config/MessageAlarmConfig.java +++ b/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/config/MessageAlarmConfig.java @@ -28,8 +28,8 @@ public class MessageAlarmConfig { @DependsOn("applicationContextHolder") @Bean(MessageAlarmConfig.SEND_MESSAGE_BEAN_NAME) - public SendMessageService sendMessageService(HttpAgent httpAgent) { - return new BaseSendMessageService(httpAgent, properties); + public SendMessageService sendMessageService(HttpAgent httpAgent, AlarmControlHandler alarmControlHandler) { + return new BaseSendMessageService(httpAgent, properties, alarmControlHandler); } @Bean @@ -40,8 +40,7 @@ public class MessageAlarmConfig { @Bean public AlarmControlHandler alarmControlHandler() { - Long alarmInterval = properties.getAlarmInterval(); - return new AlarmControlHandler(alarmInterval); + return new AlarmControlHandler(); } }