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; + } + +}