From c2da994e31bec043b2a210a4e58f7785c8ca8166 Mon Sep 17 00:00:00 2001 From: "chen.ma" Date: Thu, 10 Mar 2022 08:43:38 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B6=88=E6=81=AF=E6=8A=A5=E8=AD=A6=E6=8E=A8?= =?UTF-8?q?=E9=80=81=E4=BC=98=E5=8C=96.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../notify/BaseSendMessageServiceImpl.java | 12 +++--- .../platform/DingSendMessageHandler.java | 4 +- .../platform/LarkSendMessageHandler.java | 4 +- .../platform/WeChatSendMessageHandler.java | 4 +- .../cn/hippo4j/common/toolkit/MDCUtil.java | 25 ------------ .../ThreadPoolNotifyAlarmHandler.java | 16 +++----- .../core/toolkit/TraceContextUtil.java | 40 +++++++++++++++++++ 7 files changed, 59 insertions(+), 46 deletions(-) delete mode 100644 hippo4j-common/src/main/java/cn/hippo4j/common/toolkit/MDCUtil.java create mode 100644 hippo4j-core/src/main/java/cn/hippo4j/core/toolkit/TraceContextUtil.java diff --git a/hippo4j-common/src/main/java/cn/hippo4j/common/notify/BaseSendMessageServiceImpl.java b/hippo4j-common/src/main/java/cn/hippo4j/common/notify/BaseSendMessageServiceImpl.java index eafe706f..7e26cff5 100644 --- a/hippo4j-common/src/main/java/cn/hippo4j/common/notify/BaseSendMessageServiceImpl.java +++ b/hippo4j-common/src/main/java/cn/hippo4j/common/notify/BaseSendMessageServiceImpl.java @@ -50,7 +50,8 @@ public class BaseSendMessageServiceImpl implements HippoSendMessageService, Comm return; } - if (isSendAlarm(each.getThreadPoolId(), each.setTypeEnum(typeEnum))) { + if (isSendAlarm(each.getThreadPoolId(), each.getPlatform(), typeEnum)) { + alarmNotifyRequest.setNotifyTypeEnum(typeEnum); messageHandler.sendAlarmMessage(each, alarmNotifyRequest); } } catch (Exception ex) { @@ -88,14 +89,15 @@ public class BaseSendMessageServiceImpl implements HippoSendMessageService, Comm * Is send alarm. * * @param threadPoolId - * @param notifyInfo + * @param platform + * @param typeEnum * @return */ - private boolean isSendAlarm(String threadPoolId, NotifyConfigDTO notifyInfo) { + private boolean isSendAlarm(String threadPoolId, String platform, NotifyTypeEnum typeEnum) { AlarmControlDTO alarmControl = AlarmControlDTO.builder() .threadPool(threadPoolId) - .platform(notifyInfo.getPlatform()) - .typeEnum(notifyInfo.getTypeEnum()) + .platform(platform) + .typeEnum(typeEnum) .build(); return alarmControlHandler.isSendAlarm(alarmControl); diff --git a/hippo4j-common/src/main/java/cn/hippo4j/common/notify/platform/DingSendMessageHandler.java b/hippo4j-common/src/main/java/cn/hippo4j/common/notify/platform/DingSendMessageHandler.java index 9feeffd4..059e782c 100644 --- a/hippo4j-common/src/main/java/cn/hippo4j/common/notify/platform/DingSendMessageHandler.java +++ b/hippo4j-common/src/main/java/cn/hippo4j/common/notify/platform/DingSendMessageHandler.java @@ -40,7 +40,7 @@ public class DingSendMessageHandler implements SendMessageHandler { - if (StringUtil.isNotBlank(executeTimeoutTrace)) { - alarmNotifyRequest.setExecuteTimeoutTrace(executeTimeoutTrace); - } - hippoSendMessageService.sendAlarmMessage(NotifyTypeEnum.TIMEOUT, alarmNotifyRequest); - }; + String executeTimeoutTrace = TraceContextUtil.getAndRemove(); + if (StringUtil.isNotBlank(executeTimeoutTrace)) { + alarmNotifyRequest.setExecuteTimeoutTrace(executeTimeoutTrace); + } + Runnable task = () -> hippoSendMessageService.sendAlarmMessage(NotifyTypeEnum.TIMEOUT, alarmNotifyRequest); EXECUTE_TIMEOUT_EXECUTOR.execute(task); } catch (Throwable ex) { log.error("Send thread pool execution timeout alarm error.", ex); diff --git a/hippo4j-core/src/main/java/cn/hippo4j/core/toolkit/TraceContextUtil.java b/hippo4j-core/src/main/java/cn/hippo4j/core/toolkit/TraceContextUtil.java new file mode 100644 index 00000000..101865fe --- /dev/null +++ b/hippo4j-core/src/main/java/cn/hippo4j/core/toolkit/TraceContextUtil.java @@ -0,0 +1,40 @@ +package cn.hippo4j.core.toolkit; + +import org.slf4j.MDC; + +import static cn.hippo4j.common.constant.Constants.EXECUTE_TIMEOUT_TRACE; + +/** + * MD util. + * + * @author chen.ma + * @date 2022/3/3 08:30 + */ +public class TraceContextUtil { + + /** + * Execute timeout trace key. + */ + private static String EXECUTE_TIMEOUT_TRACE_KEY = EXECUTE_TIMEOUT_TRACE; + + /** + * Get and remove. + * + * @return + */ + public static String getAndRemove() { + String val = MDC.get(EXECUTE_TIMEOUT_TRACE_KEY); + MDC.remove(EXECUTE_TIMEOUT_TRACE_KEY); + return val; + } + + /** + * Set execute timeout trace key. + * + * @param key + */ + public static void setExecuteTimeoutTraceKey(String key) { + EXECUTE_TIMEOUT_TRACE_KEY = key; + } + +}