0.0.3.0
优化钉钉通知配置
This commit is contained in:
parent
75f3c50151
commit
2674bf35e8
@ -89,7 +89,7 @@ public class ExistsTransactionalRetryServiceTest {
|
|||||||
.thenReturn(new Result(0, "5"))
|
.thenReturn(new Result(0, "5"))
|
||||||
;
|
;
|
||||||
try {
|
try {
|
||||||
for (int i = 0; i < 10; i++) {
|
for (int i = 0; i < 100; i++) {
|
||||||
threadPoolExecutor.execute(() -> testExistsTransactionalRetryService.testSimpleInsert(UUID.randomUUID().toString()));
|
threadPoolExecutor.execute(() -> testExistsTransactionalRetryService.testSimpleInsert(UUID.randomUUID().toString()));
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -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;
|
||||||
|
|
||||||
|
}
|
@ -1,8 +1,10 @@
|
|||||||
package com.x.retry.common.core.alarm.strategy;
|
package com.x.retry.common.core.alarm.strategy;
|
||||||
|
|
||||||
import com.x.retry.common.core.alarm.AlarmContext;
|
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.enums.AlarmTypeEnum;
|
||||||
import com.x.retry.common.core.util.DingDingUtils;
|
import com.x.retry.common.core.util.DingDingUtils;
|
||||||
|
import com.x.retry.common.core.util.JsonUtil;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -22,15 +24,17 @@ public class DingdingAlarm extends AbstractAlarm<AlarmContext> {
|
|||||||
@Override
|
@Override
|
||||||
public boolean asyncSendMessage(AlarmContext context) {
|
public boolean asyncSendMessage(AlarmContext context) {
|
||||||
|
|
||||||
|
DingDingAttribute dingDingAttribute = JsonUtil.parseObject(context.getNotifyAttribute(), DingDingAttribute.class);
|
||||||
threadPoolExecutor.execute(() ->
|
threadPoolExecutor.execute(() ->
|
||||||
DingDingUtils.sendMessage(DingDingUtils.buildSendRequest(context.getTitle(), context.getText()), context.getNotifyAttribute()));
|
DingDingUtils.sendMessage(DingDingUtils.buildSendRequest(context.getTitle(), context.getText()), dingDingAttribute.getDingDingUrl()));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean syncSendMessage(AlarmContext context) {
|
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
|
@Override
|
||||||
|
@ -33,7 +33,7 @@ public class EmailAlarm extends AbstractAlarm<AlarmContext> {
|
|||||||
String notifyAttribute = alarmContext.getNotifyAttribute();
|
String notifyAttribute = alarmContext.getNotifyAttribute();
|
||||||
EmailAttribute emailAttribute = JsonUtil.parseObject(notifyAttribute, EmailAttribute.class);
|
EmailAttribute emailAttribute = JsonUtil.parseObject(notifyAttribute, EmailAttribute.class);
|
||||||
emailAttribute.setAuth(true);
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ import org.springframework.util.StringUtils;
|
|||||||
*/
|
*/
|
||||||
public class DingDingUtils {
|
public class DingDingUtils {
|
||||||
/**
|
/**
|
||||||
* 防止文本过长钉钉限流,目前最大为200
|
* 防止文本过长钉钉限流,目前最大为4000
|
||||||
*
|
*
|
||||||
* @param text
|
* @param text
|
||||||
* @return
|
* @return
|
||||||
@ -20,8 +20,8 @@ public class DingDingUtils {
|
|||||||
private static String subTextLength(String text) {
|
private static String subTextLength(String text) {
|
||||||
int length = text.length();
|
int length = text.length();
|
||||||
|
|
||||||
if (length > 1024) {
|
if (length > 4000) {
|
||||||
return text.substring(0, 1024);
|
return text.substring(0, 4000);
|
||||||
} else {
|
} else {
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
@ -32,19 +32,17 @@ public class AlarmNotifyThreadSchedule {
|
|||||||
private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||||
|
|
||||||
private static String retryErrorMoreThresholdTextMessageFormatter =
|
private static String retryErrorMoreThresholdTextMessageFormatter =
|
||||||
"<font face=\"微软雅黑\" color=#ff0000 size=4>{}环境 重试失败数据监控</font> \r\n" +
|
"<font face=\"微软雅黑\" color=#ff0000 size=4>{}环境 重试失败数据监控</font> </br>" +
|
||||||
"> 名称:{} \r\n" +
|
"> 名称:{} </br>" +
|
||||||
"> ID:{} \r\n" +
|
"> 时间窗口:{} ~ {} </br>" +
|
||||||
"> 时间窗口:{} ~ {} \r\n" +
|
|
||||||
"> **共计:{}** \n"
|
"> **共计:{}** \n"
|
||||||
;
|
;
|
||||||
|
|
||||||
private static String retryTaskMoreThresholdTextMessageFormatter =
|
private static String retryTaskMoreThresholdTextMessageFormatter =
|
||||||
"<font face=\"微软雅黑\" color=#ff0000 size=4>{}环境 重试数据监控</font> \r\n" +
|
"<font face=\"微软雅黑\" color=#ff0000 size=4>{}环境 重试数据监控</font> </br>" +
|
||||||
"> 名称:{} \r\n" +
|
"> 名称:{} </br>" +
|
||||||
"> ID:{} \r\n" +
|
"> 时间:{} </br>" +
|
||||||
"> 时间:{} \r\n" +
|
"> **共计:{}** </br>"
|
||||||
"> **共计:{}** \n"
|
|
||||||
;
|
;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@ -78,7 +76,6 @@ public class AlarmNotifyThreadSchedule {
|
|||||||
.text(retryTaskMoreThresholdTextMessageFormatter,
|
.text(retryTaskMoreThresholdTextMessageFormatter,
|
||||||
EnvironmentUtils.getActiveProfile(),
|
EnvironmentUtils.getActiveProfile(),
|
||||||
groupConfig.getGroupName(),
|
groupConfig.getGroupName(),
|
||||||
groupConfig.getGroupName(),
|
|
||||||
LocalDateTime.now().format(formatter),
|
LocalDateTime.now().format(formatter),
|
||||||
count)
|
count)
|
||||||
.title("组:[{}])重试数据过多", groupConfig.getGroupName())
|
.title("组:[{}])重试数据过多", groupConfig.getGroupName())
|
||||||
@ -116,7 +113,6 @@ public class AlarmNotifyThreadSchedule {
|
|||||||
.text(retryErrorMoreThresholdTextMessageFormatter,
|
.text(retryErrorMoreThresholdTextMessageFormatter,
|
||||||
EnvironmentUtils.getActiveProfile(),
|
EnvironmentUtils.getActiveProfile(),
|
||||||
groupConfig.getGroupName(),
|
groupConfig.getGroupName(),
|
||||||
groupConfig.getGroupName(),
|
|
||||||
now.minusMinutes(30).format(formatter),
|
now.minusMinutes(30).format(formatter),
|
||||||
now.format(formatter),
|
now.format(formatter),
|
||||||
count)
|
count)
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
spring:
|
spring:
|
||||||
|
profiles:
|
||||||
|
active: dev
|
||||||
datasource:
|
datasource:
|
||||||
name: x_retry
|
name: x_retry
|
||||||
url: jdbc:mysql://localhost:3306/x_retry?useSSL=false&characterEncoding=utf8&useUnicode=true
|
url: jdbc:mysql://localhost:3306/x_retry?useSSL=false&characterEncoding=utf8&useUnicode=true
|
||||||
|
Loading…
Reference in New Issue
Block a user