tomsun28 commented on code in PR #3481:
URL: https://github.com/apache/hertzbeat/pull/3481#discussion_r2363454232
##########
hertzbeat-alerter/src/main/java/org/apache/hertzbeat/alert/notice/AlertNoticeDispatch.java:
##########
@@ -121,14 +128,16 @@ public void dispatchAlarm(GroupAlert groupAlert) {
}
private void sendNotify(GroupAlert alert) {
- matchNoticeRulesByAlert(alert).ifPresent(noticeRules ->
noticeRules.forEach(rule -> workerPool.executeNotify(() -> rule.getReceiverId()
- .forEach(receiverId -> {
+ matchNoticeRulesByAlert(alert).ifPresent(noticeRules ->
noticeRules.forEach(rule -> workerPool.executeNotify(() -> {
+ rule.getReceiverId().forEach(receiverId -> {
+ restTemplateThreadPool.execute(() -> {
try {
- sendNoticeMsg(getOneReceiverById(receiverId),
- getOneTemplateById(rule.getTemplateId()),
alert);
- } catch (AlertNoticeException e) {
- log.warn("DispatchTask sendNoticeMsg error, message:
{}", e.getMessage());
+ sendNoticeMsg(getOneReceiverById(receiverId),
getOneTemplateById(rule.getTemplateId()), alert);
+ } catch (Exception e) {
+ log.warn("Async notification failed for receiver {}:
{}", receiverId, e.getMessage());
Review Comment:
Looking back at this PR again, it is not recommended that the alterer module
use the manager module's bean, and the notification uses two thread pools.
suggest that use the `workerPool` instead of `restTemplateThreadPool` directly.
```
matchNoticeRulesByAlert(alert).ifPresent(noticeRules ->
noticeRules.forEach(rule -> rule.getReceiverId()
.forEach(receiverId -> {
workerPool.executeNotify(() -> {
try {
sendNoticeMsg(getOneReceiverById(receiverId),
getOneTemplateById(rule.getTemplateId()), alert);
} catch (AlertNoticeException e) {
log.warn("DispatchTask sendNoticeMsg error,
message: {}", e.getMessage());
}
});
})));
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]