High-availability short message service method and device, medium and equipment
Through the priority determination and downgrade mechanism, the performance degradation problem of SMS service under high load and failure is solved, and the reliability of SMS sending and timely processing of services are achieved.
Patent Information
- Application Number
- CN202410497355.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-04-24
- Publication Date
- 2024-08-23
AI Technical Summary
The existing SMS service system's performance degrades or completely fails under high load and failure conditions, and it cannot effectively handle large-scale concurrent requests, resulting in unreliable SMS delivery.
By determining the priority of the text message, the first SMS service is used to perform the sending task. If it fails, the downgrade mode is enabled. The available service is selected from multiple second SMS services through the polling mechanism to perform the task, and the exception log is recorded for alarm notification. Turn on The heartbeat detection mechanism detects service recovery to turn off degraded mode.
Ensure that high-priority text messages can be sent in time, handle abnormal situations in a timely manner, and restore normal services in a timely manner to achieve high-availability text message sending functions.
Smart Images

Figure CN118540662A
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of short message, and in particular to a high-availability short message service method and device, medium and equipment. Background Art
[0002] With the development of technology, almost all software will involve SMS business. The existing SMS service system has limited processing capabilities for large-scale concurrent requests, which may cause the SMS service to degrade in performance or fail completely under high load and failure conditions. Summary of the invention
[0003] In view of at least one of the above technical problems, an embodiment of the present invention provides a high-availability SMS service method and apparatus, medium, and equipment.
[0004] According to a first aspect, a high-availability SMS service method provided by an embodiment of the present invention includes:
[0005] Upon receiving a text message initiation request from a cloud service, determining the priority of the text message;
[0006] According to the priority of the text message, using the first text message service to execute the task of sending the text message;
[0007] If the sending result received from the first SMS service is a failure, the downgrade mode is turned on;
[0008] In the degraded mode, a second SMS service is selected from a plurality of second SMS services through a polling mechanism to execute the task of sending the SMS;
[0009] Recording an abnormal log of the first SMS service, and issuing an alarm notification according to the abnormal log, so that a relevant business service person can handle the abnormality;
[0010] A heartbeat detection mechanism is executed for the first SMS service to detect abnormal recovery of the first SMS service, and when the first SMS service returns to normal, the degraded mode is turned off.
[0011] In one embodiment, the step of using the first SMS service to execute the task of sending the SMS according to the priority of the SMS includes:
[0012] If the priority of the SMS is the highest priority, immediately use the first SMS service to execute the task of sending the SMS;
[0013] If the priority of the short message is other than the highest priority, the short message is placed in a corresponding position in the temporary message queue according to the priority of the short message, and the first short message service is used to perform asynchronous sending processing on each short message in the temporary message queue;
[0014] Among them, the verification code SMS has the highest priority.
[0015] In one embodiment, the selecting a second SMS service from a plurality of second SMS services to execute the SMS sending task through a polling mechanism includes:
[0016] A1. Initialize the polling strategy value to 0;
[0017] A2. putting each of the second SMS services into an SMS service queue;
[0018] A3, taking the polling strategy value modulo the number of second SMS services in the SMS service queue to obtain a modulo value;
[0019] A4. Selecting a corresponding second SMS service from the SMS service queue according to the module value;
[0020] A5. Add 1 to the polling strategy value;
[0021] A6. Perform health detection on the selected second SMS service;
[0022] A7. If it is determined through health detection that the selected second SMS service is in an available state, the selected second SMS service is used to execute the task of sending the SMS;
[0023] A8. If it is determined through health detection that the selected second SMS service is in an unavailable state, return to A3.
[0024] In one embodiment, executing a heartbeat detection mechanism for the first SMS service includes:
[0025] S1. Create an independent thread and enable the heartbeat detection mechanism;
[0026] S2. Create a Socket connection with the server of the first SMS service through the independent thread, create input and output streams after the Socket connection is established, and define a heartbeat packet;
[0027] S3, sending a heartbeat packet to the server of the first SMS service through the input and output stream of the Socket connection at a first preset time interval through the independent thread, and waiting for a response from the server;
[0028] S4. If no response from the server is received within a timeout period, the independent thread sleeps for a second preset time and then returns to S3;
[0029] S5. If a response from the server is received before the timeout, the Socket connection and input / output streams are closed, and the heartbeat detection mechanism is closed.
[0030] In one embodiment, the method provided by the embodiment of the present invention further includes:
[0031] While using the first SMS service to execute the SMS sending task, the SMS data is cached by redis, and the cached SMS data is periodically persisted in the database;
[0032] The SMS data includes at least one of the SMS type, the total number of SMS and frequency statistics.
[0033] In one embodiment, each SMS service is deployed on multiple independent server nodes. When a SMS service is executing the task of sending the SMS, the task of sending the SMS is distributed to a server node of the SMS service through load balancing, and the server node executes the task of sending the SMS.
[0034] In one embodiment, upon receiving a text message initiation request from a cloud service, determining the priority of the text message includes:
[0035] When receiving a text message initiation request from a cloud service, reading the service identifier configured for the text message;
[0036] Determining the type of the text message according to the service identifier;
[0037] The priority of the text message is determined according to the type of the text message.
[0038] According to a second aspect, a high-availability SMS service device provided by an embodiment of the present invention includes:
[0039] A priority determination module, used to determine the priority of the SMS when receiving an SMS initiation request from the cloud service;
[0040] A first execution module, configured to execute the task of sending the short message by using a first short message service according to the priority of the short message;
[0041] A downgrade activation module, configured to activate a downgrade mode if a sending result feedback from the first SMS service is a failure;
[0042] A second execution module, configured to select a second SMS service from a plurality of second SMS services through a polling mechanism to execute the SMS sending task in the degradation mode;
[0043] A log recording module, used for recording an abnormal log of the first SMS service, and making an alarm notification according to the abnormal log, so that a relevant business service person can handle the abnormality;
[0044] The heartbeat detection module is used to execute a heartbeat detection mechanism for the first SMS service to detect abnormal recovery of the first SMS service, and to close the degradation mode when the first SMS service returns to normal.
[0045] According to a third aspect, an embodiment of the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed in a computer, enables the computer to execute the method provided in the first aspect.
[0046] According to a fourth aspect, an embodiment of the present invention provides a computing device, including a memory and a processor, wherein the memory stores executable code, and when the processor executes the executable code, the method provided in the first aspect is implemented.
[0047] The high-availability SMS service method, device, medium, and equipment provided by the embodiment of the present invention use the first SMS service to execute the SMS sending task based on the priority of the SMS to ensure that the SMS with a relatively high priority can be sent in time. Moreover, if the first SMS service fails to send, the downgrade mode is turned on. In the downgrade mode, the second SMS service will be selected by a polling strategy, and the selected second SMS service will be used to execute the SMS sending task, which can ensure the execution of the SMS sending task. At the same time, the abnormal log will be recorded, and an alarm notification will be made according to the abnormal log, so that the relevant business personnel can know the abnormal situation in time and then handle it. The heartbeat detection mechanism will also be turned on to detect the abnormal recovery of the first SMS service, and when the first SMS service returns to normal, the downgrade mode will be turned off. It can be seen that the heartbeat detection mechanism can timely know whether the first SMS service has returned to normal, and then the downgrade mode is turned off in time, and then the SMS sending task is restored to the first SMS service. It can be seen that the method provided by the embodiment of the present invention can ensure that the SMS task can be executed, and the SMS with a high priority can be sent in time, and the relevant business personnel can know the abnormal situation of the first SMS service in time, handle it in time, and can know whether the first SMS service has returned to normal in time, and turn off the downgrade mode in time. In summary, the embodiments of the present invention realize a highly available SMS sending service, and can normally realize the SMS sending function even in high load and fault conditions. BRIEF DESCRIPTION OF THE DRAWINGS
[0048] Figure 1 A schematic diagram of a process of a high-availability SMS service method in one embodiment of the present invention;
[0049] Figure 2 A schematic diagram of a process of a heartbeat detection mechanism in one embodiment of the present invention;
[0050] Figure 3 A schematic diagram of a polling strategy process in one embodiment of the present invention;
[0051] Figure 4 1 is a structural block diagram of a high-availability SMS service device in one embodiment of the present invention. DETAILED DESCRIPTION
[0052] In a first aspect, an embodiment of the present invention provides a high-availability SMS service method, see Figure 1 The method comprises the following steps S110 to S160:
[0053] S110, upon receiving a text message initiation request from a cloud service, determining a priority of the text message;
[0054] In actual scenarios, priorities are set at levels 1-10, with level 1 being the lowest and level 10 being the highest. Priorities are then pre-assigned to various types of SMS templates. For example, a verification code SMS template has the highest priority, which is level 10.
[0055] In one embodiment, when receiving a text message initiation request from a cloud service, determining the priority of the text message in S110 may include:
[0056] When receiving a text message initiation request from a cloud service, reading the service identifier configured for the text message;
[0057] Determining the type of the text message according to the service identifier;
[0058] The priority of the text message is determined according to the type of the text message.
[0059] That is to say, the SMS initiation request will carry a service identifier configured for the SMS, and the type of the SMS to be sent can be known based on the service identifier, and then the priority of the SMS to be sent can be determined based on the type.
[0060] S120, using a first SMS service to execute the task of sending the SMS according to the priority of the SMS;
[0061] The embodiment of the present invention involves a first SMS service and a second SMS service. Currently, the commonly used SMS services are Huoshan, Ali, and Huawei. Huoshan can be used as the first SMS service, and Ali and Huawei can be used as the second SMS service.
[0062] In one embodiment, the step of using the first SMS service to execute the task of sending the SMS according to the priority of the SMS in S120 may include:
[0063] If the priority of the SMS is the highest priority, immediately use the first SMS service to execute the task of sending the SMS;
[0064] If the priority of the short message is other than the highest priority, the short message is placed in a corresponding position in the temporary message queue according to the priority of the short message, and the first short message service is used to perform asynchronous sending processing on each short message in the temporary message queue;
[0065] Among them, the verification code SMS has the highest priority.
[0066] It can be seen that if the priority of the SMS to be sent is the highest priority, then the first SMS service needs to be used to send the SMS immediately. For example, the timeliness requirement of the verification code SMS is very high, so the priority of the verification code SMS is set to the highest priority, and the first SMS service needs to be used to execute the sending task immediately for the verification code SMS.
[0067] For SMS messages of other priorities except the highest priority, the timeliness requirement is not so high, so these SMS messages are placed in the temporary message queue, and the higher the priority, the higher the order in the temporary message queue. Then, the first SMS service is used to asynchronously send each SMS message in the temporary message queue, and the SMS messages at the front are sent first.
[0068] S130: if the sending result of the first SMS service feedback is a failure, start the downgrade mode;
[0069] It is understandable that if the first SMS service successfully sends the SMS, the sending result will be fed back as success. If the SMS sending task of the first SMS service fails, the sending result will be fed back as failure. If the sending result is failure, the downgrade mode will be turned on.
[0070] S140, in the degraded mode, selecting a second SMS service from a plurality of second SMS services through a polling mechanism to execute the task of sending the SMS;
[0071] In the downgrade mode, the second SMS service is used to execute the SMS sending task. Since there are multiple second SMS services, the embodiment of the present invention adopts a polling mechanism to select a second SMS service from multiple second SMS services to execute the SMS sending task.
[0072] In one embodiment, see Figure 3 The step of selecting a second SMS service from a plurality of second SMS services through a polling mechanism to execute the SMS sending task in S140 may include:
[0073] A1. Initialize the polling strategy value to 0;
[0074] A2. putting each of the second SMS services into an SMS service queue;
[0075] A3, taking the polling strategy value modulo the number of second SMS services in the SMS service queue to obtain a modulo value;
[0076] A4. Selecting a corresponding second SMS service from the SMS service queue according to the module value;
[0077] A5. Add 1 to the polling strategy value;
[0078] A6. Perform health detection on the selected second SMS service;
[0079] A7. If it is determined through health detection that the selected second SMS service is in an available state, the selected second SMS service is used to execute the task of sending the SMS;
[0080] A8. If it is determined through health detection that the selected second SMS service is in an unavailable state, return to A3.
[0081] It can be seen that each second SMS service is placed in the service queue smsServers, and the number of second SMS services is modulo by the polling strategy value to obtain the modulus value smsMod, and then the corresponding second SMS service is selected from multiple second SMS services according to the modulus value smsMod. For example, if the modulus value is x, the yth second SMS service can be selected from multiple second SMS services, and x can be equal to y. Of course, x and y can also be other one-to-one correspondences. The selected second SMS service is subjected to a health check, for example, the selected second SMS service is subjected to a health check by means of http. If the health check passes, the selected second SMS service is used to perform the SMS sending task. If the health check fails, the number of second SMS services is modulo by the polling strategy value after adding 1 to obtain a new modulus value, and then a second SMS service is selected by using the new modulus value, and then it is determined whether the newly selected second SMS service passes the health check. A3-A6 is repeatedly executed until the selected second SMS service is available. Then the available second SMS service is used to perform the SMS sending task.
[0082] Of course, if an exception occurs during the second SMS service's SMS sending task, another second SMS service can be used to perform the task. In addition, an exception log is recorded, and an alarm notification is made according to the exception log, so that the relevant business service personnel can handle the abnormal second SMS service.
[0083] S150, recording an abnormal log of the first SMS service, and issuing an alarm notification according to the abnormal log, so that a relevant service provider can handle the abnormality;
[0084] That is, since the first SMS service is abnormal, the abnormal log of the first SMS service is recorded, and then an alarm notification is made according to the abnormal log, so that the relevant business service personnel will perform relevant processing on the first SMS service.
[0085] S160: Execute a heartbeat detection mechanism for the first SMS service to detect abnormal recovery of the first SMS service, and turn off the degradation mode when the first SMS service returns to normal.
[0086] That is, the heartbeat detection mechanism is turned on to detect whether the first SMS service has returned to normal. If it has not returned to normal, it means that the relevant business service personnel have not restored the first SMS service. If it has returned to normal, the degradation mode is turned off, so that the next SMS initiation request will use the first SMS service to execute the SMS sending task.
[0087] In one embodiment, see Figure 2 The step of executing the heartbeat detection mechanism for the first SMS service in S160 may include:
[0088] S1. Create an independent thread and enable the heartbeat detection mechanism;
[0089] That is to say, an independent thread is created, and the independent thread executes the following steps.
[0090] S2. Create a Socket connection with the server of the first SMS service through the independent thread, create input and output streams after the Socket connection is established, and define a heartbeat packet;
[0091] S3, sending a heartbeat packet to the server of the first SMS service through the input and output stream of the Socket connection at a first preset time interval through the independent thread, and waiting for a response from the server;
[0092] For example, the first preset time is 5 minutes, so the independent thread will send a heartbeat packet every 5 minutes.
[0093] S4. If no response from the server is received within a timeout period, the independent thread sleeps for a second preset time and then returns to S3;
[0094] For example, if the timeout is set to 5 minutes, that is, if no response is received within 5 minutes of sending the heartbeat packet, the independent thread will sleep. For example, sleep for 1 minute. After the sleep period ends, it returns to S3 and continues to send heartbeat packets.
[0095] S5. If a response from the server is received before the timeout, the Socket connection and input / output streams are closed, and the heartbeat detection mechanism is closed.
[0096] For example, if a response is received within 5 minutes of sending the heartbeat packet, it means that the first SMS service has been restored. At this time, the Socket connection and the input and output streams are closed, and the heartbeat detection mechanism is turned off.
[0097] It can be seen that through the above heartbeat detection mechanism, it is possible to know in time whether the first SMS service has returned to normal, and when it has returned to normal, it can be applied to the SMS sending task.
[0098] In one embodiment, the method provided by the embodiment of the present invention may further include:
[0099] While using the first SMS service to execute the SMS sending task, the SMS data is cached by redis, and the cached SMS data is periodically persisted in the database;
[0100] The SMS data includes at least one of the SMS type, the total number of SMS and frequency statistics.
[0101] It can be seen that while executing the task of sending SMS messages, the SMS data will be cached and then persisted in the database at a regular interval, which is convenient for subsequent SMS data analysis.
[0102] In one embodiment, each SMS service is deployed on multiple independent server nodes. When a SMS service is executing the task of sending the SMS, the task of sending the SMS is distributed to a server node of the SMS service through load balancing, and the server node executes the task of sending the SMS.
[0103] The above SMS service is the first SMS service and also the second SMS service. That is to say, each SMS service is deployed on multiple server nodes. When a SMS service is needed to execute the SMS sending task, which server node of the SMS service is used to execute it can be distributed through load balancing, and the server node to which it is distributed will execute the SMS sending task, which can improve the concurrent processing capability.
[0104] It is understandable that in order to solve the problems of low availability, poor scalability, and slow message delivery of SMS services, so that users cannot receive verification code SMS in time, in an embodiment of the present invention, the priority of the verification code SMS can be set to the highest, and the sending task of the verification code SMS can be executed immediately. That is, based on the SMS priority policy, the highest priority SMS service is processed first, and the low priority SMS service is written into the temporary message queue for asynchronous processing. In order to solve the problem that SMS cannot be sent normally after an SMS service exception occurs, an embodiment of the present invention sets a degraded mode, and a second SMS service can be used to execute the SMS sending task in the degraded mode. In order to solve the problem that managers cannot grasp the SMS abnormalities and SMS-related data in time, the abnormal log is recorded, and the abnormal log is used for alarm notification, and the SMS data is cached, and the cached SMS data is persisted to the database at regular intervals.
[0105] In a second aspect, an embodiment of the present invention provides a high-availability SMS service device, see Figure 4 , the device 100 comprises:
[0106] The priority determination module 110 is used to determine the priority of the SMS when receiving the SMS initiation request of the cloud service;
[0107] A first execution module 120, configured to execute the task of sending the SMS using a first SMS service according to the priority of the SMS;
[0108] A downgrade activation module 130, configured to activate a downgrade mode if the result of sending the first SMS service feedback is a failure;
[0109] A second execution module 140 is used to select a second SMS service from a plurality of second SMS services through a polling mechanism to execute the SMS sending task in the degradation mode;
[0110] A log recording module 150, configured to record an abnormal log of the first SMS service, and to issue an alarm notification according to the abnormal log, so that a relevant service provider can handle the abnormality;
[0111] The heartbeat detection module 160 is used to execute a heartbeat detection mechanism for the first SMS service to detect abnormal recovery of the first SMS service, and to close the degradation mode when the first SMS service returns to normal.
[0112] In one embodiment, the first execution module is specifically used for: if the priority of the text message is the highest priority, then the first text message service is used immediately to execute the task of sending the text message; if the priority of the text message is other priorities except the highest priority, then the text message is placed in the corresponding position in the temporary message queue according to the priority of the text message, and the first text message service is used to perform asynchronous sending processing on each text message in the temporary message queue; among which, the verification code text message has the highest priority.
[0113] In one embodiment, the second execution module includes:
[0114] The initialization unit is used to execute: A1, initializing the polling strategy value to 0;
[0115] A queue adding unit, used to execute: A2, putting each of the second SMS services into an SMS service queue;
[0116] A modulus calculation unit, configured to execute: A3, taking the modulus of the polling strategy value and the number of second SMS services in the SMS service queue to obtain a modulus value;
[0117] A service selection unit, configured to execute: A4, selecting a corresponding second SMS service from the SMS service queue according to the module value;
[0118] A policy updating unit, configured to execute: A5, adding 1 to the polling policy value;
[0119] A health detection unit, configured to execute: A6, performing health detection on the selected second SMS service;
[0120] A task execution unit, used to execute: A7, if it is determined through health detection that the selected second SMS service is in an available state, then use the selected second SMS service to execute the task of sending the SMS;
[0121] The step returns to the unit for executing A8. If it is determined through health detection that the selected second SMS service is in an unavailable state, the step returns to the modulo calculation unit for executing A3.
[0122] In one embodiment, the heartbeat detection module includes:
[0123] The thread creation unit is used to execute: S1, create an independent thread, and start the heartbeat detection mechanism;
[0124] The connection establishing unit is used to execute: S2, establishing a Socket connection with the server of the first SMS service through the independent thread, creating input and output streams after the Socket connection is established, and defining a heartbeat packet;
[0125] The heartbeat sending unit is used to execute: S3, through the independent thread, sending a heartbeat packet to the server of the first short message service through the input and output flow of the Socket connection every first preset time, and waiting for a response from the server;
[0126] The thread sleeping unit is used to execute: S4, if no response from the server is received within a timeout period, the independent thread sleeps for a second preset time and then returns to S3;
[0127] The mechanism closing unit is used to execute: S5. If a response from the server is received before timeout, the Socket connection and input and output streams are closed, and the heartbeat detection mechanism is closed.
[0128] In one embodiment, the apparatus provided by the embodiment of the present invention may further include:
[0129] A data cache unit is used to cache SMS data through redis while using the first SMS service to execute the SMS sending task, and to periodically persist the cached SMS data in a database; wherein the SMS data includes at least one of the SMS type, the total number of SMS and frequency statistics.
[0130] In one embodiment, each SMS service is deployed on multiple independent server nodes. When a SMS service is executing the task of sending the SMS, the task of sending the SMS is distributed to a server node of the SMS service through load balancing, and the server node executes the task of sending the SMS.
[0131] In one embodiment, the priority determination module includes:
[0132] An identification acquisition unit, configured to read a service identification configured for a text message upon receiving a text message initiation request of a cloud service;
[0133] A type determination unit, used to determine the type of the short message according to the service identifier;
[0134] The priority determination unit is used to determine the priority of the short message according to the type of the short message.
[0135] It is understandable that the explanation, specific implementation, beneficial effects, examples, etc. of the relevant contents in the device provided in the embodiment of the present invention can be found in the corresponding parts of the method provided in the first aspect, and will not be repeated here.
[0136] In a third aspect, an embodiment of the present invention provides a computer-readable medium, on which computer instructions are stored. When the computer instructions are executed by a processor, the processor executes the method provided in the first aspect.
[0137] Specifically, a system or device equipped with a storage medium can be provided, on which software program code that implements the functions of any of the above-mentioned embodiments is stored, and a computer (or CPU or MPU) of the system or device can be enabled to read and execute the program code stored in the storage medium.
[0138] In this case, the program code itself read from the storage medium can realize the function of any one of the above-mentioned embodiments, and thus the program code and the storage medium storing the program code constitute a part of the present invention.
[0139] The storage medium embodiments for providing the program code include a floppy disk, a hard disk, a magneto-optical disk, an optical disk (such as CD-ROM, CD-R, CD-RW, DVD-ROM, DVD-RAM, DVD-RW, DVD+RW), a magnetic tape, a non-volatile memory card, and a ROM. Alternatively, the program code can be downloaded from a server computer by a communication network.
[0140] In addition, it should be clear that the functions of any of the above embodiments can be implemented not only by executing the program code read by the computer, but also by enabling an operating system operating on the computer to complete part or all of the actual operations based on instructions from the program code.
[0141] In addition, it can be understood that the program code read from the storage medium is written to a memory provided in an expansion board inserted into the computer or to a memory provided in an expansion module connected to the computer, and then based on the instructions of the program code, a CPU installed on the expansion board or expansion module is enabled to perform part or all of the actual operations, thereby realizing the functions of any of the above-mentioned embodiments.
[0142] It is understandable that the explanation, specific implementation methods, beneficial effects, examples, etc. of the relevant contents in the computer-readable medium provided in the embodiment of the present invention can be found in the corresponding parts of the method provided in the first aspect, and will not be repeated here.
[0143] In a fourth aspect, an embodiment of the present specification provides a computing device, including a memory and a processor, wherein the memory stores executable code, and when the processor executes the executable code, it implements the method in any embodiment of the specification.
[0144] It is understandable that the explanation, specific implementation, beneficial effects, examples, etc. of the relevant contents in the computing device provided in the embodiment of the present invention can be found in the corresponding parts of the method provided in the first aspect, and will not be repeated here.
[0145] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0146] Those skilled in the art should be aware that in one or more of the above examples, the functions described in the present invention can be implemented by hardware, software, widgets, or any combination thereof. When implemented by software, these functions can be stored in a computer-readable medium or transmitted as one or more instructions or codes on a computer-readable medium.
[0147] The specific implementation methods described above further illustrate the objectives, technical solutions and beneficial effects of the present invention in detail. It should be understood that the above description is only a specific implementation method of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc. made on the basis of the technical solution of the present invention should be included in the scope of protection of the present invention.
Claims
1. A high availability SMS service method, characterized in that: include: Upon receiving a text message initiation request from a cloud service, determining the priority of the text message; According to the priority of the text message, using the first text message service to execute the task of sending the text message; If the sending result received from the first SMS service is a failure, the downgrade mode is turned on; In the degraded mode, a second SMS service is selected from a plurality of second SMS services through a polling mechanism to execute the task of sending the SMS; Recording an abnormal log of the first SMS service, and issuing an alarm notification according to the abnormal log, so that a relevant business service person can handle the abnormality; A heartbeat detection mechanism is executed for the first SMS service to detect abnormal recovery of the first SMS service, and when the first SMS service returns to normal, the degraded mode is turned off.
2. The method according to claim 1, characterized in that The step of using the first SMS service to execute the task of sending the SMS according to the priority of the SMS includes: If the priority of the SMS is the highest priority, immediately use the first SMS service to execute the task of sending the SMS; If the priority of the short message is other than the highest priority, the short message is placed in a corresponding position in the temporary message queue according to the priority of the short message, and the first short message service is used to perform asynchronous sending processing on each short message in the temporary message queue; Among them, the verification code SMS has the highest priority.
3. The method according to claim 1, characterized in that The step of selecting a second SMS service from a plurality of second SMS services through a polling mechanism to execute the task of sending the SMS includes: A1. Initialize the polling strategy value to 0; A2. putting each of the second SMS services into an SMS service queue; A3, taking the polling strategy value modulo the number of second SMS services in the SMS service queue to obtain a modulo value; A4. Selecting a corresponding second SMS service from the SMS service queue according to the module value; A5. Add 1 to the polling strategy value; A6. Perform health detection on the selected second SMS service; A7. If it is determined through health detection that the selected second SMS service is in an available state, the selected second SMS service is used to execute the task of sending the SMS; A8. If it is determined through health detection that the selected second SMS service is in an unavailable state, return to A3.
4. The method according to claim 1, characterized in that The executing of the heartbeat detection mechanism for the first SMS service includes: S1. Create an independent thread and enable the heartbeat detection mechanism; S2. Create a Socket connection with the server of the first SMS service through the independent thread, create input and output streams after the Socket connection is established, and define a heartbeat packet; S3, sending a heartbeat packet to the server of the first SMS service through the input and output stream of the Socket connection at a first preset time interval through the independent thread, and waiting for a response from the server; S4. If no response from the server is received within a timeout period, the independent thread sleeps for a second preset time and then returns to S3; S5. If a response from the server is received before the timeout, the Socket connection and input / output streams are closed, and the heartbeat detection mechanism is closed.
5. The method according to claim 1, characterized in that Also includes: While using the first SMS service to execute the SMS sending task, the SMS data is cached by redis, and the cached SMS data is periodically persisted in the database; The SMS data includes at least one of the SMS type, the total number of SMS and frequency statistics.
6. The method according to claim 1, characterized in that Each SMS service is deployed on multiple independent server nodes. When a SMS service is executing the SMS sending task, the SMS sending task is distributed to a server node of the SMS service through load balancing, and the server node executes the SMS sending task.
7. The method according to claim 1, characterized in that When receiving a text message initiation request from a cloud service, determining the priority of the text message includes: When receiving a text message initiation request from a cloud service, reading the service identifier configured for the text message; Determining the type of the text message according to the service identifier; The priority of the text message is determined according to the type of the text message.
8. A high-availability SMS service device, characterized in that: include: A priority determination module, used to determine the priority of the SMS when receiving an SMS initiation request from the cloud service; A first execution module, configured to execute the task of sending the short message by using a first short message service according to the priority of the short message; A downgrade activation module, configured to activate a downgrade mode if a sending result feedback from the first SMS service is a failure; A second execution module, configured to select a second SMS service from a plurality of second SMS services through a polling mechanism to execute the SMS sending task in the degradation mode; A log recording module, used for recording an abnormal log of the first SMS service, and making an alarm notification according to the abnormal log, so that a relevant business service person can handle the abnormality; The heartbeat detection module is used to execute a heartbeat detection mechanism for the first SMS service to detect abnormal recovery of the first SMS service, and to close the degradation mode when the first SMS service returns to normal.
9. A computer-readable storage medium, characterized in that: A computer program is stored thereon, and when the computer program is executed in a computer, the computer is caused to execute the method according to any one of claims 1 to 7.
10. A computing device, characterized in that The method comprises a memory and a processor, wherein the memory stores executable codes, and when the processor executes the executable codes, the method according to any one of claims 1 to 7 is implemented.
