background
In the daily system, alarm is an indispensable part, there are many ways to alarm at present, the most common are direct log, wechat alarm, SMS alarm, email alarm, etc.; When it comes to alarm, it is generally unavoidable to set some basic information in advance, such as alarm mode, alarm frequency, alarm user, switch, etc.
Another common problem is that the general use of a single alarm, such as no matter what type of alarm are all reached by SMS, and then you will find that the mobile phone is often submerged in the state, over time will not be sensitive to the alarm message
The target
So we are going to design a general alarm framework
- You can choose your own alarm method,
- Support user – defined alarm mode expansion
- Supports dynamic alarm configuration,
- Support user – defined alarm rule expansion
- Support alarm mode automatic switching rule setting
- Support alarm mode self-defined automatic switching rule expansion
design
In general, alarm can be divided into three steps as follows:
- Submit alarm: Interface to external consumers
- Select alarm: select specific alarm execution unit according to alarm related information
- Execute alarm: implement specific alarm logic
In terms of task division, it is relatively clear and simple, but the content of each piece must be extensible.
-
Select alarm:
- Establish alarm rules
- Alarm rule loader
ConfLoader
- Trigger for alarm rule change
ConfChangeTrigger
- Alarm rule resolver
ConfParse
: Parses text format alarm rules into business objectsAlarmSelector
: Select specific alarm actuator according to alarm rules and alarm typesAlarmExecute
-
Alarm execution:
- Thread pool execution (to prevent impact on the main business process)
- Dynamic extension of AlarmExecute (support for user-defined alarm implementation)
- Actual alarm logic
According to the above debunking, there are some things that must be done when the application starts
- The choice of ConfLoader
- Alarm rule loading
- Load AlarmExecute (including default + custom implementation)
The following figure shows the steps for alarm rule resolution at application startup
As for the alarm actuator loading is relatively simple, as shown in the following figure
Therefore, the entire workflow is shown below
Task disassemble
After the previous task design, I have a general context of what needs to be done. Therefore, before the formal implementation, I will disassemble the task of the whole architecture to see how the specific execution steps can be taken
- The most direct is to design the alarm actuator
AlarmExecute
- Defining the basic interface
- Make custom extension rules
- The next step is to design alarm rules
- How do I load alarm rules?
- Detailed definition of alarm rules
- Analysis of alarm rules: namely, according to the alarm type to obtain the alarm actuator
- Alarm rule dynamic update support
- Alarm thread pool
- Maintain alarm queue
- Alarm count and frequency control
- Encapsulate external interfaces
Therefore, it can be seen from the above analysis that the structure of this system is quite simple. The whole system only needs four parts, among which the first two are the most important, which will be explained separately later
summary
To make something, of course, is to hope that it can bring some use, or to learn something, it is not worth the effort to toss about, so what is the use of this alarm system, or can learn from it?
USES:
- Supports flexible alarm rules and customized expansion of specific alarm services
- The goal is to unify the use of the alarm posture, that is, no matter what alarm, is a posture, but the internal can play a variety of patterns, convenient and simple for the user
Study:
Put aside the specific knowledge points, you can abstract some common usable places, probably the following two points
- How can we support dynamic scalability of functionality
- Use of thread pools
IV. The other
Related blog
- Alarm system QuickAlarm overview
- Design and implementation of alarm actuator for QuickAlarm alarm system
- Setting and loading of alarm rules for alarm system QuickAlarm
- Alarm rule parsing for Alarm system QuickAlarm
- Alarm system QuickAlarm frequency statistics and interface encapsulation
- Alarm System QuickAlarm User manual
project
- Project address: Quick-alarm
- Blog address: Little Grey Blog
The statement
As far as the letter book is inferior, has been on the content, pure one’s words, because of my ability is general, the opinion is not complete, if there is a problem, welcome criticism and correction