A message sending method, system, device and medium
By obtaining the exception level of the message received by the server, adjusting the message transmission frequency and determining the storage strategy based on the number of unsuccessful sending times, the problem of low message transmission reliability in the prior art is solved, and more efficient message delivery is achieved.
Patent Information
- Application Number
- CN202411857591.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-17
- Publication Date
- 2025-05-23
- Estimated Expiration
- 2044-12-17
AI Technical Summary
In the prior art, after the message is sent, the server feedback is used to determine whether the message is successfully sent, but when the network is poor or the server load is too large, the system resources are wasted and the message sending reliability is low.
By obtaining the exception level of the server receiving the message, the transmission frequency of the message sent to the server is determined, and the message is sent according to the frequency; after the message sent successfully by the server feedback has not been received, the storage policy of the message is determined based on the number of unsuccessful sending times, so that it can be sent again at the appropriate time.
Reasonably control the frequency of message sending, reduce the risk of data loss, and improve the reliability of message sending.
Smart Images

Figure CN119316098B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a message sending method, system, device and medium. Background Art
[0002] In the prior art, after the local notification message is sent to the server, the local machine usually determines whether the notification message is sent successfully by monitoring the status returned by the server. However, due to various reasons such as network fluctuations, busy servers, server downtime, etc., the server may not be able to receive the notification message sent by the local machine for a period of time. Server abnormalities can lead to various situations. For example, when the local machine does not receive the success information fed back by the server after sending a message, the retransmission mechanism will be triggered. The retransmission mechanism will repeatedly retransmit and cause waste of system resources; if the local machine does not receive the feedback message from the server for a period of time, it will assume that the message has been sent successfully, resulting in message loss; when the message has been successfully sent but the server has not fed back, the retransmission mechanism will be triggered, resulting in waste of resources. When the server is abnormal, it will cause waste of local system resources and message loss.
[0003] In the prior art, after sending a message, whether the message is successfully sent is determined based on information fed back by the server. However, when the network condition is poor or the server load is too large, it will cause a waste of system resources and result in low reliability of message sending.
[0004] Therefore, a method is urgently needed to solve the problem of low reliability of message sending. Summary of the invention
[0005] Based on this, it is necessary to provide a message sending method, system, device and medium for the above-mentioned technical problems, which can solve the problem of low reliability of message sending.
[0006] The present invention adopts the following technical solutions:
[0007] The present invention provides a message sending method, comprising:
[0008] In response to a message sending instruction, obtaining an abnormality level of the message received by the server;
[0009] According to the abnormality level, determine the frequency of sending messages to the server, and send the messages in the message queue to the server according to the sending frequency;
[0010] After not receiving the message sending success information fed back by the server, determine the message storage strategy according to the number of unsuccessful message sending to the server, and store the message in the message queue according to the message storage strategy so that the message can be sent to the server again.
[0011] Preferably, obtaining the abnormal level of the message received by the server specifically includes:
[0012] Count the number of errors in sending messages to the server within a preset time period;
[0013] According to the number of times, the abnormal level of the message received by the server is determined.
[0014] Preferably, according to the abnormality level, determining the sending frequency of sending messages to the server, and sending the messages in the message queue to the server according to the sending frequency, specifically includes:
[0015] If the abnormality level is abnormal, the sending frequency is determined to be the first frequency, and the messages in the message queue are sent to the server in a first-in-first-out order according to the first frequency;
[0016] If the abnormal level is normal, the sending frequency is determined to be the second frequency, and the messages in the message queue are sent to the server in a first-in-first-out order according to the second frequency.
[0017] Preferably, the message storage strategy is determined according to the number of unsuccessful attempts to send the message to the server, specifically including:
[0018] Determine the error type of the message based on the number of unsuccessful attempts to send the message to the server;
[0019] In the case where the error type is a short-term error, the storage strategy is determined to place the message at the top of the message queue;
[0020] In the case where the error type is a long-term error, the storage strategy is determined to place the message at the bottom of the message queue.
[0021] Preferably, the method further comprises:
[0022] When the number of messages in long-term error is greater than a preset error threshold, the abnormality level of the server is adjusted to abnormal.
[0023] Preferably, the method further comprises:
[0024] Receive the pending message sent by the sender;
[0025] Check the memory of the message queue. If the memory of the message queue is larger than the maximum carrying memory, the message to be sent will be persistently stored.
[0026] If the memory of the message queue is less than or equal to the maximum carrying memory, the message to be sent is stored in the message queue.
[0027] Preferably, the method further comprises:
[0028] When the memory of the message queue is less than the preset storage memory, the persistently stored messages to be sent are stored in the message queue.
[0029] The present invention provides a message sending system, which includes: a sending module, a monitoring module and a resending module;
[0030] The sending module is used to obtain the abnormal level of the message received by the server in response to the message sending instruction; determine the sending frequency of the message to the server according to the abnormal level, and send the message in the message queue to the server according to the sending frequency;
[0031] The monitoring module is used to count the number of times the message is sent to the server in a preset time; determine the abnormal level of the server receiving the message according to the number; after not receiving the message sending success information fed back by the server, determine the message storage strategy according to the number of unsuccessful message sending to the server;
[0032] The resending module is used to store the message in the message queue according to the message storage strategy so that the message can be sent to the server again.
[0033] The present invention provides a message sending device, comprising:
[0034] An acquisition module, used for acquiring the abnormal level of the message received by the server in response to the message sending instruction;
[0035] A first sending module, used to determine a sending frequency of sending messages to the server according to the abnormality level, and send the messages in the message queue to the server according to the sending frequency;
[0036] The second sending module is used to determine the message storage strategy according to the number of unsuccessful message sending attempts to the server after failing to receive the message sending success information from the server, and store the message in the message queue according to the message storage strategy so that the message can be sent to the server again.
[0037] The present invention provides a computer-readable storage medium, wherein the storage medium stores a computer program, and when the computer program is executed by a processor, the above-mentioned message sending method is implemented.
[0038] The present invention provides a computer device, comprising a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the processor implements the above-mentioned message sending method when executing the program.
[0039] At least one of the above technical solutions adopted by the present invention can achieve the following beneficial effects:
[0040] In the present invention, before sending a message to a server, the abnormal level of the server receiving the message is first obtained, and the sending frequency of the message to the server is determined according to the abnormal level of the server, and the message is sent to the server according to the sending frequency. In this way, the message sending frequency can be reasonably controlled. When the server is abnormal, the sending frequency can be adjusted in time, which can reduce the risk of data loss and improve the reliability of message sending. Moreover, after the message sending success information is not received from the server, the message storage strategy is determined according to the number of unsuccessful message sending to the server. In this way, the message can be stored in the message queue according to the storage strategy, so that the message can be sent to the server at an appropriate time, thereby further improving the reliability of message sending. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] The drawings described herein are used to provide a further understanding of the present invention and constitute a part of the present invention. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the drawings:
[0042] Figure 1 A schematic diagram of a message sending method provided by the present invention;
[0043] Figure 2 A flow chart of a message sending method provided by the present invention;
[0044] Figure 3 A device diagram of a message sending method provided by the present invention;
[0045] Figure 4 A schematic diagram of a computer device for a message sending method provided by the present invention. DETAILED DESCRIPTION
[0046] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the specific embodiments of the present invention and the corresponding drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.
[0047] The devices that execute the solutions of this specification include servers, desktops, laptops, terminals, etc. For the convenience of description, the following description is based on computer devices as the execution subject.
[0048] The technical solutions provided by various embodiments of the present invention are described in detail below in conjunction with the accompanying drawings.
[0049] Figure 1 The present invention is a flow chart of a message sending method, which specifically includes the following steps:
[0050] S101: In response to a message sending instruction, obtaining an abnormality level of a message received by a server.
[0051] In an exemplary embodiment, obtaining the abnormal level of the message received by the server specifically includes: counting the number of message sending errors to the server within a preset time period; and determining the abnormal level of the message received by the server according to the number.
[0052] Specifically, the preset time length is a time period from a certain moment before the current moment to the current moment, the number of message sending errors in the time period is counted, and the abnormal level of the server receiving the message is determined according to the number of message sending errors. The abnormal level may include multiple levels, for example, the abnormal level of the server can be set to normal, level one abnormal, level two abnormal, level three abnormal, level four abnormal, level five abnormal. If the number of message sending errors is zero, the abnormal level of the server is normal, and the greater the number of message sending errors, the higher the abnormal level of the server.
[0053] In an exemplary embodiment, the method also includes: receiving a message to be sent from a sender; detecting the memory of a message queue, and if the memory of the message queue is greater than the maximum carrying memory, persistently storing the message to be sent; if the memory of the message queue is less than or equal to the maximum carrying memory, storing the message to be sent in the message queue.
[0054] Specifically, according to engineering practice, the maximum load memory is set to 1. Before sending a message to the server, the memory of the message queue is checked. If the memory of the message queue is greater than 1, the message is persistently stored. If the memory of the message queue is less than or equal to 1, the message is stored in the message queue.
[0055] S102: Determine a sending frequency of messages to the server according to the abnormality level, and send the messages in the message queue to the server according to the sending frequency.
[0056] In an exemplary embodiment, the sending frequency of sending messages to the server is determined according to the exception level, and the messages in the message queue are sent to the server according to the sending frequency, specifically including: if the exception level is abnormal, the sending frequency is determined to be a first frequency, and the messages in the message queue are sent to the server in a first-in-first-out order according to the first frequency; if the exception level is normal, the sending frequency is determined to be a second frequency, and the messages in the message queue are sent to the server in a first-in-first-out order according to the second frequency.
[0057] Specifically, the first frequency is a low frequency, and the second frequency is a high frequency. If the abnormality level of the server is normal, the message in the message queue is sent to the server at a high frequency; if the abnormality level of the server is abnormal, the message in the message queue is sent to the server according to the sending frequency corresponding to the different levels of the abnormality, and the higher the abnormality level, the lower the sending frequency. For example, the abnormality level of the server is a first-level abnormality, a second-level abnormality, a third-level abnormality, a fourth-level abnormality, and a fifth-level abnormality. From the first-level abnormality to the fifth-level abnormality, the sending frequency changes from high to low. When the abnormality level of the server is a first level, it is sent according to 80% of the sending frequency when the abnormality level of the server is normal, when the abnormality level of the server is a second level, it is sent according to 60% of the sending frequency when the abnormality level of the server is normal, when the abnormality level of the server is a third level, it is sent according to 40% of the sending frequency when the abnormality level of the server is normal, when the abnormality level of the server is a fourth level, it is sent according to 20% of the sending frequency when the abnormality level of the server is normal, and when the abnormality level of the server is a fifth level, it is sent according to one message per second.
[0058] Specifically, when the server status is abnormal, the sending frequency is reduced according to the abnormality level. When a large number of messages cannot be sent, a sending frequency similar to the heartbeat mechanism can be maintained for message sending. When a message is successfully sent, the abnormality level is gradually reduced and the message sending frequency is gradually increased. When all notifications can be successfully sent after a period of time, it is assumed that the server has returned to normal working status and the abnormal status of the server is resolved.
[0059] S103: After not receiving the message sending success information fed back by the server, determine the message storage strategy according to the number of unsuccessful message sending to the server, and store the message in the message queue according to the message storage strategy so that the message can be sent to the server again.
[0060] In an exemplary embodiment, a storage strategy for a message is determined based on the number of unsuccessful attempts to send a message to a server, specifically including: determining an error type of the message based on the number of unsuccessful attempts to send a message to a server; when the error type is a short-term error, determining a storage strategy to place the message at the top of a message queue; when the error type is a long-term error, determining a storage strategy to place the message at the bottom of a message queue.
[0061] Specifically, under normal circumstances, after successfully receiving a message, the server will quickly feedback success information, and after receiving the success information fed back by the server, the sent information in the queue will be deleted. The types of unsuccessful message sending are divided into short-term errors and long-term errors. Short-term errors are usually caused by network instability, delays and other reasons. For short-term errors, the message is placed at the top of the message queue and resent immediately; if the message is still not successfully sent after multiple resends, the error type of the message is upgraded to a long-term error. For messages of the long-term error type, these messages will be placed at the bottom of the message queue and resent after a period of time. For example, if a message with an error type of short-term error is still unsuccessful after three repeated sends, the error type of the message is upgraded to a long-term error.
[0062] In an exemplary embodiment, the method further includes: when the number of messages in long-term error is greater than a preset error threshold, adjusting the abnormality level of the server to abnormal.
[0063] Specifically, the preset error threshold is generally set to a larger value. When the monitoring module detects a large number of long-term error type messages, the server's abnormality level is adjusted to abnormal. For example, the ratio of the number of failed message transmissions to the total number of transmissions within a preset time of one minute is counted. When the ratio is 10%, the server's abnormality level is adjusted to a first-level abnormality. When the ratio is 20%, the server's abnormality level is adjusted to a second-level abnormality. When the ratio is 30%, the server's abnormality level is adjusted to a third-level abnormality. When the ratio is 40%, the server's abnormality level is adjusted to a fourth-level abnormality. When the ratio is 50%, the server's abnormality level is adjusted to a fifth-level abnormality.
[0064] In an exemplary embodiment, the method further includes: when the memory of the message queue is smaller than the preset storage memory, storing the persistently stored messages to be sent in the message queue.
[0065] Specifically, according to engineering practice, the preset storage memory is set to 2. When the memory of the message queue is less than 2, the persistently stored messages to be sent are gradually loaded into the message queue and sent in sequence in the first-in-first-out order. This method effectively prevents the memory overflow of the message queue.
[0066] In an exemplary embodiment, the present invention further provides a message sending method, which is described by taking a computer device including a sending module, a monitoring module and a resending module as an example. Figure 2 As shown, the specific process is:
[0067] S201: When the sending module has a notification message to send to the server, it first determines whether the memory of the message queue exceeds threshold 1. If it does not exceed threshold 1, the message is placed in the message queue. If it exceeds threshold 1, the message is persistently stored and when the memory of the message queue is less than 2, the persistently stored messages are gradually loaded into the message queue.
[0068] S202: The monitoring module counts the number of message sending errors to evaluate the abnormality level of the server, and dynamically adjusts the abnormality level of the server.
[0069] S203: The sending module executes a corresponding sending strategy according to the abnormality level of the server evaluated by the monitoring module. If the fault level of the server is normal, high frequency sending is performed; if the abnormality level of the server is abnormal, low frequency sending is performed.
[0070] S204: The sending module sends the messages in the message queue in sequence according to the first-in-first-out order.
[0071] S205: The sending module receives the message that the message is sent successfully, and deletes the message from the message queue to determine that the message is sent successfully. If the message is sent successfully, the message sending process ends.
[0072] S206: If the sending module does not receive the message sending success information fed back by the server within a period of time, it confirms that the message sending fails. If the message sending fails, the type of the message failure is determined.
[0073] S207: If it is a short-term error, the resending module will give priority to resending the message. If it fails to be sent after multiple attempts, the message will be upgraded to a long-term error. If it is a long-term error, the resending module will choose to place these messages that have not been successfully sent at the bottom of the message queue and resend them again after a period of time.
[0074] When applying a message sending method provided by the present invention, it is not necessary to Figure 1 The steps are executed in the order shown. The specific execution order of the steps can be determined according to needs, and the present invention does not limit this.
[0075] The above is a message sending method provided by one or more embodiments of the present invention. Based on the same idea, the present invention also provides a corresponding message sending system, which includes: a sending module, a monitoring module, and a retransmission module.
[0076] The sending module is used to obtain the abnormal level of the message received by the server in response to the message sending instruction; determine the sending frequency of the message to the server according to the abnormal level, and send the message in the message queue to the server according to the sending frequency;
[0077] A monitoring module, configured to count the number of times of message sending errors to the server within a preset duration; determine the exception level of the server's received messages according to the number of times; after not receiving the information indicating successful message sending feedback from the server, determine the message storage policy according to the number of times of unsuccessful message sending to the server.
[0078] A resending module, configured to store the messages into the message queue according to the message storage policy, so that the messages are sent to the server again.
[0079] Specifically, the sending module is configured to sequentially send the messages in the message queue in a first-in, first-out order at a corresponding sending frequency according to the exception level of the server. The monitoring module is configured to count the number of message sending errors, evaluate the server status according to the number of errors, dynamically adjust the exception level of the server, and adjust the message storage policy according to the type of message errors. The resending module is configured to execute a corresponding resending policy according to the type of message errors.
[0080] The above is a message sending method of the present invention. Based on the same concept, the present invention also provides a corresponding message sending device, as Figure 3 shown.
[0081] Figure 3 A schematic diagram of a message sending device provided by the present invention, including:
[0082] An obtaining module 301, configured to obtain the exception level of the server's received messages in response to a message sending instruction;
[0083] A first sending module 302, configured to determine the sending frequency of sending messages to the server according to the exception level, and send the messages in the message queue to the server according to the sending frequency;
[0084] A second sending module 303, configured to determine the message storage policy according to the number of times of unsuccessful message sending to the server after not receiving the information indicating successful message sending feedback from the server, and store the messages into the message queue according to the message storage policy, so that the messages are sent to the server again.
[0085] For the specific limitations on a message sending device, reference can be made to the limitations on a message sending method in the above text, which will not be elaborated here. Each module in the above message sending device can be implemented in whole or in part by software, hardware, and their combination. The above modules can be embedded in the processor in the computer device in a hardware form or be independent of it, or be stored in the memory in the computer device in a software form, so that the processor can call and execute the operations corresponding to the above modules.
[0086] The present invention also provides a computer-readable storage medium, which stores a computer program, which can be used to execute the above Figure 1 A method for sending messages is provided.
[0087] The present invention also provides Figure 4 The structural diagram of the computer device shown in FIG. Figure 4 As shown in the figure, at the hardware level, the computer device includes a processor, an internal bus, a network interface, a memory, and a non-volatile memory, and may also include other hardware required for the business. The processor reads the corresponding computer program from the non-volatile memory into the memory and then runs it to achieve the above Figure 1 A method for sending messages is provided.
[0088] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided by the present invention can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory or optical memory, etc. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM).
[0089] The technical features of the above embodiments may be arbitrarily combined. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of the present invention.
Claims
1. A message sending method, characterized in that: include: In response to a message sending instruction, obtaining an abnormality level of the message received by the server; Determine a sending frequency of sending messages to the server according to the abnormality level, and send the messages in the message queue to the server according to the sending frequency; After not receiving the message sent successfully fed back by the server, determining the storage strategy of the message according to the number of unsuccessful times of sending the message to the server, specifically including: determining the error type of the message according to the number of unsuccessful times of sending the message to the server; when the error type is a short-term error, determining the storage strategy to place the message at the top of the message queue; when the error type is a long-term error, determining the storage strategy to place the message at the bottom of the message queue; when the number of messages in long-term errors is greater than a preset error threshold, adjusting the abnormality level of the server to abnormal; And according to the storage strategy of the message, the message is stored in the message queue so that the message is sent to the server again, specifically including: receiving the message to be sent sent by the sender; detecting the memory of the message queue, if the memory of the message queue is greater than the maximum carrying memory, the message to be sent is persistently stored; if the memory of the message queue is less than or equal to the maximum carrying memory, the message to be sent is stored in the message queue; when the memory of the message queue is less than the preset storage memory, the persistently stored message to be sent is stored in the message queue.
2. The method according to claim 1, characterized in that The obtaining of the abnormal level of the message received by the server specifically includes: Counting the number of times a message is sent incorrectly to the server within a preset time period; The abnormal level of the message received by the server is determined according to the number of times.
3. The method according to claim 1, characterized in that Determining the frequency of sending messages to the server according to the abnormality level, and sending the messages in the message queue to the server according to the sending frequency, specifically includes: If the abnormality level is abnormal, determining the sending frequency to be a first frequency, and sending the messages in the message queue to the server in a first-in-first-out order according to the first frequency; If the abnormality level is normal, the sending frequency is determined to be a second frequency, and the messages in the message queue are sent to the server in a first-in-first-out order according to the second frequency.
4. A message sending system, characterized in that: The system comprises: a sending module, a monitoring module and a resending module; A sending module, configured to obtain an abnormality level of a message received by a server in response to a message sending instruction; determine a sending frequency of messages to the server according to the abnormality level, and send the messages in the message queue to the server according to the sending frequency; A monitoring module is used to count the number of message sending errors to the server within a preset time period; determine the abnormal level of the server receiving the message according to the number; after not receiving the message sending success information fed back by the server, determine the storage strategy of the message according to the number of unsuccessful sending of the message to the server, specifically including: determining the error type of the message according to the number of unsuccessful sending of the message to the server; when the error type is a short-term error, determine the storage strategy to place the message at the top of the message queue; when the error type is a long-term error, determine the storage strategy to place the message at the bottom of the message queue; when the number of messages in long-term errors is greater than a preset error threshold, adjust the abnormal level of the server to abnormal; A resending module is used to store the message in the message queue according to the storage strategy of the message so that the message is sent to the server again, specifically including: receiving the message to be sent sent by the sender; detecting the memory of the message queue, if the memory of the message queue is greater than the maximum carrying memory, persistently storing the message to be sent; if the memory of the message queue is less than or equal to the maximum carrying memory, storing the message to be sent in the message queue; when the memory of the message queue is less than the preset storage memory, storing the persistently stored message to be sent in the message queue.
5. A message sending device, characterized in that: include: An acquisition module, used for acquiring the abnormal level of the message received by the server in response to the message sending instruction; A first sending module, used to determine a sending frequency of sending messages to the server according to the abnormality level, and send the messages in the message queue to the server according to the sending frequency; The second sending module is used to determine the storage strategy of the message according to the number of unsuccessful sending of the message to the server after not receiving the message sending success information fed back by the server, and store the message in the message queue according to the storage strategy of the message, so that the message can be sent to the server again, specifically including: determining the error type of the message according to the number of unsuccessful sending of the message to the server; if the error type is a short-term error, determining the storage strategy to place the message at the top of the message queue; if the error type is a long-term error, determining the storage strategy to place the message at the top of the message queue Bottom; when the number of messages in long-term error is greater than the preset error threshold, the exception level of the server is adjusted to exception; and according to the storage strategy of the message, the message is stored in the message queue, so that the message is sent to the server again to receive the message to be sent sent by the sender; the memory of the message queue is detected, if the memory of the message queue is greater than the maximum load memory, the message to be sent is persistently stored; if the memory of the message queue is less than or equal to the maximum load memory, the message to be sent is stored in the message queue; when the memory of the message queue is less than the preset storage memory, the persistently stored message to be sent is stored in the message queue.
6. A computer-readable storage medium, characterized in that: The storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 3 is implemented.
Citation Information
Patent Citations
Request packet sending frequency control method and apparatus
CN105024933A
Data retransmission method and device, electronic equipment and storage medium
CN115033395A