未验证 提交 7f2dc005 编写于 作者: 高云峰 提交者: GitHub

DingtalkHook polish (#6773)

1.take 'getUrl' out of inner loop for better performance
2.use try-with-resources auto close CloseableHttpClient
上级 3a7d6c0e
......@@ -76,24 +76,19 @@ public class DingtalkHookCallback implements AlarmCallback {
if (this.alarmRulesWatcher.getDingtalkSettings() == null || this.alarmRulesWatcher.getDingtalkSettings().getWebhooks().isEmpty()) {
return;
}
CloseableHttpClient httpClient = HttpClients.custom().build();
try {
try (CloseableHttpClient httpClient = HttpClients.custom().build()) {
DingtalkSettings dingtalkSettings = this.alarmRulesWatcher.getDingtalkSettings();
dingtalkSettings.getWebhooks().forEach(webHookUrl -> {
String url = getUrl(webHookUrl);
alarmMessages.forEach(alarmMessage -> {
String url = getUrl(webHookUrl);
String requestBody = String.format(
this.alarmRulesWatcher.getDingtalkSettings().getTextTemplate(), alarmMessage.getAlarmMessage()
);
sendAlarmMessage(httpClient, url, requestBody);
});
});
} finally {
try {
httpClient.close();
} catch (IOException e) {
log.error(e.getMessage(), e);
}
} catch (IOException e) {
log.error(e.getMessage(), e);
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册