优化钉钉通知配置
This commit is contained in:
byteblogs168 2023-01-14 20:47:43 +08:00
parent 75f3c50151
commit 2674bf35e8
7 changed files with 34 additions and 18 deletions

View File

@ -89,7 +89,7 @@ public class ExistsTransactionalRetryServiceTest {
.thenReturn(new Result(0, "5"))
;
try {
for (int i = 0; i < 10; i++) {
for (int i = 0; i < 100; i++) {
threadPoolExecutor.execute(() -> testExistsTransactionalRetryService.testSimpleInsert(UUID.randomUUID().toString()));
}
} catch (Exception e) {

View File

@ -0,0 +1,14 @@
package com.x.retry.common.core.alarm;
import lombok.Data;
/**
* @author: www.byteblogs.com
* @date : 2022-05-04 16:13
*/
@Data
public class DingDingAttribute {
private String dingDingUrl;
}

View File

@ -1,8 +1,10 @@
package com.x.retry.common.core.alarm.strategy;
import com.x.retry.common.core.alarm.AlarmContext;
import com.x.retry.common.core.alarm.DingDingAttribute;
import com.x.retry.common.core.enums.AlarmTypeEnum;
import com.x.retry.common.core.util.DingDingUtils;
import com.x.retry.common.core.util.JsonUtil;
import org.springframework.stereotype.Component;
import java.util.List;
@ -22,15 +24,17 @@ public class DingdingAlarm extends AbstractAlarm<AlarmContext> {
@Override
public boolean asyncSendMessage(AlarmContext context) {
DingDingAttribute dingDingAttribute = JsonUtil.parseObject(context.getNotifyAttribute(), DingDingAttribute.class);
threadPoolExecutor.execute(() ->
DingDingUtils.sendMessage(DingDingUtils.buildSendRequest(context.getTitle(), context.getText()), context.getNotifyAttribute()));
DingDingUtils.sendMessage(DingDingUtils.buildSendRequest(context.getTitle(), context.getText()), dingDingAttribute.getDingDingUrl()));
return true;
}
@Override
public boolean syncSendMessage(AlarmContext context) {
return DingDingUtils.sendMessage(DingDingUtils.buildSendRequest(context.getTitle(), context.getNotifyAttribute()), context.getNotifyAttribute());
DingDingAttribute dingDingAttribute = JsonUtil.parseObject(context.getNotifyAttribute(), DingDingAttribute.class);
return DingDingUtils.sendMessage(DingDingUtils.buildSendRequest(context.getTitle(), context.getText()), dingDingAttribute.getDingDingUrl());
}
@Override

View File

@ -33,7 +33,7 @@ public class EmailAlarm extends AbstractAlarm<AlarmContext> {
String notifyAttribute = alarmContext.getNotifyAttribute();
EmailAttribute emailAttribute = JsonUtil.parseObject(notifyAttribute, EmailAttribute.class);
emailAttribute.setAuth(true);
MailUtil.send(emailAttribute, emailAttribute.getTos(), alarmContext.getTitle(), alarmContext.getText(), false);
MailUtil.send(emailAttribute, emailAttribute.getTos(), alarmContext.getTitle(), alarmContext.getText(), true);
return true;
}

View File

@ -12,7 +12,7 @@ import org.springframework.util.StringUtils;
*/
public class DingDingUtils {
/**
* 防止文本过长钉钉限流目前最大为200
* 防止文本过长钉钉限流目前最大为4000
*
* @param text
* @return
@ -20,8 +20,8 @@ public class DingDingUtils {
private static String subTextLength(String text) {
int length = text.length();
if (length > 1024) {
return text.substring(0, 1024);
if (length > 4000) {
return text.substring(0, 4000);
} else {
return text;
}

View File

@ -32,19 +32,17 @@ public class AlarmNotifyThreadSchedule {
private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
private static String retryErrorMoreThresholdTextMessageFormatter =
"<font face=\"微软雅黑\" color=#ff0000 size=4>{}环境 重试失败数据监控</font> \r\n" +
"> 名称:{} \r\n" +
"> ID:{} \r\n" +
"> 时间窗口:{} ~ {} \r\n" +
"<font face=\"微软雅黑\" color=#ff0000 size=4>{}环境 重试失败数据监控</font> </br>" +
"> 名称:{} </br>" +
"> 时间窗口:{} ~ {} </br>" +
"> **共计:{}** \n"
;
private static String retryTaskMoreThresholdTextMessageFormatter =
"<font face=\"微软雅黑\" color=#ff0000 size=4>{}环境 重试数据监控</font> \r\n" +
"> 名称:{} \r\n" +
"> ID:{} \r\n" +
"> 时间:{} \r\n" +
"> **共计:{}** \n"
"<font face=\"微软雅黑\" color=#ff0000 size=4>{}环境 重试数据监控</font> </br>" +
"> 名称:{} </br>" +
"> 时间:{} </br>" +
"> **共计:{}** </br>"
;
@Autowired
@ -78,7 +76,6 @@ public class AlarmNotifyThreadSchedule {
.text(retryTaskMoreThresholdTextMessageFormatter,
EnvironmentUtils.getActiveProfile(),
groupConfig.getGroupName(),
groupConfig.getGroupName(),
LocalDateTime.now().format(formatter),
count)
.title("组:[{}])重试数据过多", groupConfig.getGroupName())
@ -116,7 +113,6 @@ public class AlarmNotifyThreadSchedule {
.text(retryErrorMoreThresholdTextMessageFormatter,
EnvironmentUtils.getActiveProfile(),
groupConfig.getGroupName(),
groupConfig.getGroupName(),
now.minusMinutes(30).format(formatter),
now.format(formatter),
count)

View File

@ -1,4 +1,6 @@
spring:
profiles:
active: dev
datasource:
name: x_retry
url: jdbc:mysql://localhost:3306/x_retry?useSSL=false&characterEncoding=utf8&useUnicode=true