The messages in the work group are afraid of being too quiet and too frequent

During the development process, you will encounter a variety of development problems, server downtime, network jitter, bugs in the code itself, and so on. For bugs in the code, we can advance funds and send alarm messages to warn us to intervene and deal with them as soon as possible.

By adding swarm robots to the enterprise DingTalk group, alarm information is sent to the group through the robot. As for how DingTalk bots are created, APIs for sending messages, etc., please refer to the official documentation

The same routine, enterprise WeChat is also, in the enterprise WeChat group, add group robots. Send alarm messages through the bot. Please refer to the official documentation for details

Unlike the above, the mail is sent to individuals, of course, it can also be sent in batches, only the way to send text format is realized, as for the markdown format, it remains to be examined. Sending an e-mail is relatively simple, so I will not go into detail here.

@Alarm tag is used on a method, and an exception occurs in the marked method, the configuration information is read and the exception stack information is sent according to the configuration. Here’s how to use it:

Alarm message title: Can be defined as business information, such as tutor identity calculation

Alarm message display type: currently supports text text type, markdown type

Message template ID: Consistent with the template id configured in the configuration file

Whether an alert message is also required under normal circumstances, the default value is fasle, which means that it is not needed. Of course, some business scenarios also need to be sent under normal circumstances, such as payment billing notifications.

Defines an abstract interface, AlarmTemplateProvider, to be implemented by concrete subclasses

The abstract class BaseAlarmTemplateProvider implements the abstract interface

The implementation of the YamlAlarmTemplateProvider class, which reads the template from the configuration file, will be loaded into the spring bean container when the project starts

The abstract class BaseAlarmTemplateProvider has two other subclasses, MemoryAlarmTemplateProvider and JdbcAlarmTemplateProvider. However, these two subclasses have not yet implemented the logic, and can be extended by themselves in the future.

Both classes have Function interfaces, which are functional interfaces that can be used externally to implement their own logic.

This class holds a container internally, which is mainly used to cache the real sending class

An abstract interface that provides only one method for sending

The same routine as the abstract template provider AlarmTemplateProvider, the interface has an abstract implementation class BaseWarnService, which exposes the send method externally for sending messages, and implements the specific sending logic internally with the doSendMarkdown, doSendText method, of course, the specific sending logic still has to be implemented by its subclasses.

It mainly implements the logic of DingTalk sending alarm information

It mainly implements the logic of sending enterprise WeChat alarm information

It mainly implements the email alarm logic

Using the springboot custom starter, and then configuring the class under the configuration file spring.factories under the META-INF package

Auto-assembly class for loading custom beans

Mainly with the help of spring’s facet technology and springboot’s automatic assembly principle, the alarm logic is realized. There is no intrusion into the business code, only need to mark the annotation on the business code, you can achieve pluggable functions, relatively lightweight.