CN113794998B - Information sending method and device based on distributed lock and storage medium - Google Patents
Information sending method and device based on distributed lock and storage medium Download PDFInfo
- Publication number
- CN113794998B CN113794998B CN202110959704.1A CN202110959704A CN113794998B CN 113794998 B CN113794998 B CN 113794998B CN 202110959704 A CN202110959704 A CN 202110959704A CN 113794998 B CN113794998 B CN 113794998B
- Authority
- CN
- China
- Prior art keywords
- information
- sending
- message
- request message
- mobile phone
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
Images
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04W—WIRELESS COMMUNICATION NETWORKS
- H04W4/00—Services specially adapted for wireless communication networks; Facilities therefor
- H04W4/12—Messaging; Mailboxes; Announcements
- H04W4/14—Short messaging services, e.g. short message services [SMS] or unstructured supplementary service data [USSD]
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04W—WIRELESS COMMUNICATION NETWORKS
- H04W28/00—Network traffic management; Network resource management
- H04W28/02—Traffic management, e.g. flow control or congestion control
Landscapes
- Engineering & Computer Science (AREA)
- Computer Networks & Wireless Communication (AREA)
- Signal Processing (AREA)
- Mobile Radio Communication Systems (AREA)
Abstract
The invention discloses an information sending method, an information sending device and a storage medium based on a distributed lock, wherein the method comprises the following steps: receiving a first information sending request message which comprises a receiver mobile phone number and information; generating a sending information identifier according to the mobile phone number, the information and the time period of the receiver; storing the mobile phone number, the information, the time period and the sending information identification of the receiver to a second information sending request message; sending a second information sending request message to the message queue; acquiring a second information sending request message from the message queue; and adding a distributed lock to the sent information identifier, and if the distributed lock is successfully added, sending the information to the mobile phone number of the receiver. The embodiment of the invention solves the problem that the short messages sent by a plurality of short message platform instances from the message queue repeatedly send the same short message to the user, reduces the cost for sending the short message, and avoids the user from receiving a plurality of same short messages, thereby improving the user experience.
Description
Technical Field
The invention relates to the technical field of computers, in particular to an information sending method and device based on a distributed lock and a storage medium.
Background
More and more companies have their own short message service platforms for managing all short message sending services inside the companies. In order to respond to a high-concurrency request for sending short messages, a short message platform usually adopts a message queue to separate the processing of a short message sending application from a short message sending service provider, so that even if a large-flow sudden situation occurs, short message sending information can be temporarily stored in the message queue for caching and then processed one by one, thereby ensuring the high availability of the short message platform. However, the message queue has a problem that is often encountered, that is, the problem of repeated consumption of the same piece of data, so that the same mobile phone number receives multiple pieces of the same content due to the repeated consumption of the message, which not only affects the reliability of the short message platform, but also causes great economic loss, and also affects user experience.
Disclosure of Invention
The invention mainly aims to provide an information sending method, an information sending device and a storage medium based on a distributed lock, and aims to solve the problem of repeated consumption of the same data when a short message is sent through a message queue in the prior art, so that the same mobile phone number receives a plurality of same contents due to the repeated consumption of the message, the reliability of a short message platform is influenced, great economic loss is caused, and the user experience is influenced.
In order to achieve the above object, the present invention provides an information sending method based on a distributed lock, including the following steps:
receiving a first information sending request message, wherein the first information sending request message comprises a receiver mobile phone number and information;
generating a sending information identifier according to the mobile phone number of the receiving party, the information and the time period;
storing the receiver mobile phone number, the information, the time period and the sending information identification to a second information sending request message;
sending the second information sending request message to a message queue;
acquiring the second information sending request message from the message queue;
adding a distributed lock to the sending information identifier; if the distributed lock is added successfully, the information is sent to the mobile phone number of the receiving party; and if the distributed lock is unsuccessfully added, the information is not sent to the mobile phone number of the receiving party.
Optionally, the generating the sending information identifier is implemented by:
and performing MD5 calculation on the mobile phone number of the receiver, the information and the time period to obtain an MD5 value, wherein the MD5 value is used as the transmitted information identifier.
Optionally, the time period is obtained by:
dividing a period of time into a plurality of time periods, wherein the duration of the time periods is set according to the duration of a time interval allowing repeated information transmission;
acquiring the time when the information sending request message is received;
and matching in the time periods according to the time to obtain the matched time period.
Optionally, the adding a distributed lock to the sending information identifier includes:
storing the sending information identification into a Redis database by using a setnx command of the Redis database;
if the storage is successful, indicating that the distributed lock is successfully added; if the store fails, it indicates that the addition of the distributed lock failed.
Optionally, the method further comprises the steps of:
acquiring the time period of the second information sending request message;
acquiring the duration of the time period;
and setting the duration as the timeout time of the setnx command.
Optionally, the method further comprises the steps of:
after receiving the first information sending request message, carrying out validity detection on the mobile phone number of the receiver and the information;
if the validity detection fails, discarding the first information sending request message; and if the validity detection is successful, continuing to process the subsequent steps.
Optionally, the information includes at least one of a short message, a multimedia message, and a video short message.
In addition, in order to achieve the above object, the present invention further provides an information sending apparatus based on a distributed lock, including:
the receiving unit is used for receiving a first information sending request message, wherein the first information sending request message comprises a mobile phone number and information of a receiving party;
the calculation unit is used for generating a sending information identifier according to the mobile phone number of the receiving party, the information and the time period; the mobile phone number of the receiving party, the information, the time period and the sending information identification are stored in a second information sending request message;
a sending unit, configured to send the second information sending request message to a message queue;
the distributed lock unit is used for acquiring the second information sending request message from the message queue; the system is also used for adding a distributed lock to the sending information identifier; if the distributed lock is added successfully, the information is sent to the mobile phone number of the receiving party; and if the distributed lock is failed to be added, the information is not sent to the mobile phone number of the receiver.
In addition, to achieve the above object, the present invention further provides an electronic device, including: a memory, a processor, and a distributed lock-based messaging program stored on the memory and executable on the processor, the distributed lock-based messaging program configured to implement the steps of the distributed lock-based messaging method as described above.
Furthermore, to achieve the above object, the present invention also proposes a computer readable storage medium, on which a computer program is stored, which, when being executed by a processor, implements the steps of the distributed lock-based information transmission method as described above.
The invention solves the problem that the same short message is repeatedly sent to the user when a plurality of short message platform processes or threads send the short message from the message queue by carrying out distributed locking on the sent message in the message queue, reduces the sending cost of the short message, and avoids the user from receiving a plurality of same short messages, thereby improving the user experience.
Drawings
Fig. 1 is a schematic flowchart of a distributed lock-based information sending method according to the present invention.
Fig. 2 is another schematic flow chart of the information sending method based on the distributed lock according to the present invention.
Fig. 3 is a schematic flow chart of the matching time period provided by the present invention.
Fig. 4 is a schematic flow chart of setting the distributed lock timeout period according to the present invention.
Fig. 5 is a block diagram of a distributed lock-based information transmission apparatus according to the present invention.
Fig. 6 is a schematic structural diagram of an electronic device according to the present invention.
The implementation, functional features and advantages of the present invention will be further described with reference to the accompanying drawings.
Detailed Description
In order to make the technical problems, technical solutions and advantageous effects of the present invention more clear and obvious, the present invention is further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
In the following description, suffixes such as "module", "component", or "unit" used to denote elements are used only for facilitating the explanation of the present invention, and have no specific meaning in itself. Thus, "module", "component" or "unit" may be used mixedly.
It should be noted that the terms "first," "second," and the like in the description and claims of the present invention and in the drawings described above are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order.
In one embodiment, as shown in fig. 1, the present invention provides a method for sending information based on distributed locks, where the method includes:
In the embodiment of the application, the short message service platform provides an API (application program interface) interface for calling the service layer, and the service layer realizes information transmission by calling the API interface provided by the short message service platform. If the short message sending API is a post request of an HTTP protocol, the short message sending API can also be realized by adopting other protocols.
The API interface realizes the transmission of an information transmission request message, wherein the information transmission request message carries information contents (such as short messages, multimedia messages, video short messages and the like) to be transmitted and a mobile phone number of a receiver (such as 136880 xxxxx).
After receiving the information sending request message sent by the service layer through the API, the short message service platform acquires the information (such as short messages, multimedia messages, video short messages and other contents) required to be sent by the service layer and the mobile phone number of a receiver from the message, and stores the information and the mobile phone number into a local memory or a database.
And 102, generating a sending information identifier according to the mobile phone number of the receiving party, the information and the time period.
After receiving the information sending request message sent by the application layer, the short message service platform needs to generate a globally unique sending information identifier for the sent information. The sending information identifier is used for uniquely identifying a piece of information to be sent when the information is cached in a subsequent queue.
The business layer has the possibility of repeatedly sending short messages, so that the short message service platform needs to be capable of identifying the repeated short messages. If the service layer receives a plurality of information sending request messages with the same information content and the same information sending request message of the mobile phone number of the receiver within a period of time (for example, 5 minutes, which can be specifically set according to service requirements), the information is repeated. The same transmission information identifier is also required to be generated for the repeated information, so that in the message queue, the repeated information can be judged by the transmission information identifier.
The short message service platform generates a message sending identifier through an MD5 algorithm, and stores a mobile phone number of a receiving party, a time period and information as files in the following mode: the receiver mobile phone number + time slot + information, such as: test short messages of 1380000888820:20: 00-20: 29: 59. Then, MD5 calculation is carried out on the saved files (such as 123.data) to obtain a 16-bit character string (namely, an MD5 value) with 32 bits.
Document | MD5 value |
123.data | E6FACD4408F6621109EB2E5F2D4BFBAA |
The value of MD5 is used as the transmission information identifier of the information transmission request message. The same file, MD5 values obtained by calculation of MD5 algorithm are the same, so the same information and receiver number are received in a period of time, and the generated sending information identifier is also the same. Therefore, it can be judged whether the same information transmission request message is received within a period of time by judging the transmission information identification (MD5 value).
The acquisition of the time period is obtained by the flow shown in fig. 3.
The short message service platform divides 1 day into a plurality of time periods according to the service requirements. The duration of each time period can be set according to the duration of the time interval for allowing the repeated sending of the information, and if the service layer stipulates that the time interval exceeds 10 minutes, the repeated short message is allowed to be sent to the user. If the user registers, the service layer needs to send registration prompt information to the user. When the user registers for many times within 10 minutes, the prompt message only needs to be sent once; when the user registers again after more than 10 minutes, the prompt message needs to be sent again. The short message service platform divides 1 day and 24 hours into a plurality of time periods according to the service requirements
Time period id | Starting time | End time |
1 | 00:00:00 | 00:9:59 |
2 | 00:10:00 | 00:19:59 |
… | … | … |
n | 23:50:00 | 23:59:59 |
And 203, matching in the time periods according to the time to obtain the matched time period.
After receiving the information sending request message, the short message service platform acquires the current time of the received message, for example, the current time is 20:15:25, and the time period of the current time 20:15:25 is 20:10: 00-20: 19: 59. Thereby acquiring the time period corresponding to the information sending request message.
And receiving a plurality of information sending request messages in a time period (such as 20:10: 00-20: 19:59), wherein the time periods corresponding to the plurality of information sending request messages are the same, such as 20:10: 00-20: 19: 59.
And 103, storing the mobile phone number of the receiver, the information, the time period and the transmitted information identification to a second information transmission request message.
And step 104, sending the second information sending request message to a message queue.
After receiving the information sending request message sent by the service layer, the short message service platform performs corresponding processing, and after obtaining a sending information identifier corresponding to the information sending request message, the short message service platform needs to repackage the sending information identifier into the information sending request message, and then sends the information sending request message (i.e. a second information sending request message) containing the sending information identifier to the message queue.
The short message service platform sends the received message sending request message to the message queue, so as to prevent the service layer from sending a large amount of message sending request messages to the short message service platform in a peak period, and when the short message service platform cannot send messages in time through a short message sending function provided by a short message sending service provider, smooth processing is realized through the message queue.
The message queue can be a self-realized message queue in the short message service platform, such as a first-in first-out message queue; or message queue middleware provided by a third party, such as Kafka, RabbitMQ, RockketMQ and the like.
The message queue has a high data processing throughput, such as ten thousand or one hundred thousand. Therefore, when the service layer sends a large amount of information sending request messages at the same time in the service peak period, the message queue can also be stored in time. After storing the large amount of information sending request messages into the message queue, the short message service platform can gradually acquire the information sending request messages from the message queue according to the service processing capacity of the short message service platform, and then send corresponding information (short messages, multimedia messages or video short messages) to corresponding mobile phone numbers.
The short message service platform can use interfaces provided by a plurality of short message service providers to send short messages, so a plurality of threads or processes can be started to send the short messages; or when only one short message service provider is provided, a plurality of threads or processes can be started to call an interface provided by the short message service provider to send the short message.
Each thread or process acquires the second information from the message queue (such as RabbitMQ message queue middleware) step by step according to the service processing capacity of the thread or process. After the second information sending request message is obtained, the information, the mobile phone number of the receiver, the time period and the message sending identifier are taken out from the message, and the following table shows that:
After the thread or process of the short message service platform sending the short message obtains the second message sending request message, the message needs to be locked in a distributed manner, and the corresponding message in the message can be sent only after the distributed locking is successful. If the distributed lock fails, this indicates that the information has been processed by other threads, or that the information is duplicate information.
The distributed lock of the short message service platform is realized through a setnx command of a Redis database. The setnx command is as follows: SET key value.
The key is a transmission message identifier in the second information transmission request message, and the value is a random value. Such as:
set E6FACD4408F6621109EB2E5F2D4BFBAA 123456
the set command of the Redis database can be successfully executed only if the key value does not exist. Therefore, after a certain thread A successfully executes the set command with the key value of E6FACD4408F6621109EB2E5F2D4BFBAA, other threads (such as thread B) can not execute the set command with the key value of E6FACD4408F6621109EB2E5F2D4BFBAA any more. Therefore, the distributed lock function for the second information transmission request message can be realized by using the transmission message identification as the key value of the set command.
And after the thread A acquires the second information sending request message, using the sending message identifier in the message as the key value of the set command, and executing the set command. If the execution is successful, it indicates that no thread has processed the second information sending request message before, that is, it indicates that the thread a obtains the distributed lock of the second information sending request message, and sends the message after obtaining the distributed lock of the message, for example, sends a short message to the mobile phone number of the receiver. The other threads can no longer obtain the distributed lock of the second information transmission request message, and thus cannot process the second information transmission request message.
The same first information sending request message is received in the same time period, and the produced sending message identification is also the same. Therefore, after a certain thread acquires a message from the message queue to transmit, when other threads acquire the same message again, because the transmitted message identifiers of the same message are the same, the set command cannot be successfully executed when the same transmitted message identifier is reused as the key value of the set command. Other threads cannot acquire the distributed lock of the same message, and the same message cannot be sent to the mobile phone number of the receiver.
In the embodiment, by performing distributed locking on the sending information in the message queue, the problem that the sending of the short messages from the message queue by a plurality of short message platform threads or processes is repeated to send the same short message to the user is solved, the sending cost of the short message is reduced, the user is prevented from receiving a plurality of same short messages, and therefore the user experience is improved.
In one embodiment, fig. 2 provides a flowchart of the validity check of the message content after the step 101 in the embodiment of fig. 1.
And 107, carrying out validity detection on the mobile phone number of the receiver and the information.
After receiving the information sending request message sent by the service layer, the short message service platform carries out validity detection on the information carried in the message and the mobile phone number of the receiver. And judging whether the information is one of a valid short message, a valid multimedia message and a valid video short message or not, and whether the mobile phone number of the receiver is a valid mobile phone number or not.
After passing the validity detection, judging that the information is one of the effective short message, the multimedia message and the video short message and the mobile phone number of the receiver is also the effective mobile phone number, indicating that the validity detection is passed, and continuing to carry out the subsequent processing flow; if the information is judged not to be one of the effective short message, the multimedia message and the video short message or the receiver mobile phone number is not the effective mobile phone number, the validity detection is not passed, and the information sending request message is discarded.
In this embodiment, the short message service platform performs validity detection on the received information sending request message, and performs subsequent flow processing only after the detection is passed, so that an illegal message can be prevented from being processed by the subsequent flow, thereby improving the processing capability of the short message service platform, reducing the short message sending cost, avoiding the user from receiving an abnormal short message, and improving the user experience.
In one embodiment, FIG. 4 provides a flow diagram for setting a distributed lock timeout time.
And after the thread or process for sending the short message by the short message service platform acquires the second message sending request message from the message queue, the time period in the message is taken out. For example, the time period is 20:10: 00-20: 19: 59.
And step 302, acquiring the time duration of the time period.
The duration of the time period is obtained, for example, the duration of the time period 20:10: 00-20: 19:59 is 10 minutes (600 seconds).
And 303, setting the time length as the overtime time of the setnx command.
And the thread or process for sending the short message by the short message service platform takes the sending message identifier in the second message sending request message as a key value of the set command, and takes the time period duration as the overtime duration of the set command when the set command is executed. Such as:
set E6FACD4408F6621109EB2E5F2D4BFBAA 123456EX 600
after the set command is executed successfully, the key value can be automatically deleted by the Redis database after the timeout duration expires. After Redis deletes the key value, the thread or process which subsequently sends the short message takes the sending message identifier of the same message as the key value of the set command, and the set command can be successfully executed, so that the same short message can be sent after a period of time.
In this embodiment, when the short message service platform sets the distributed lock, the time duration of the message time period is used as the timeout time duration of the distributed lock. And after timeout, automatically deleting the distributed lock. So that the same information can be sent to the same user after a period of time. Therefore, the service flexibility of the short message sending platform is improved, and the user experience is improved.
In addition, an embodiment of the present invention further provides an information sending apparatus based on a distributed lock, and referring to fig. 5, the information sending apparatus based on a distributed lock includes:
the receiving unit is used for receiving a first information sending request message, wherein the first information sending request message comprises a mobile phone number and information of a receiving party;
the calculation unit is used for generating a sending information identifier according to the mobile phone number of the receiving party, the information and the time period; the mobile phone number of the receiving party, the information, the time period and the sending information identification are stored in a second information sending request message;
a sending unit, configured to send the second information sending request message to message queue middleware;
the distributed locking unit is used for acquiring the second information sending request message from the message queue middleware; the distributed lock is added to the sending information identification; if the distributed lock is added successfully, the information is sent to the mobile phone number of the receiving party; and if the distributed lock is unsuccessfully added, the information is not sent to the mobile phone number of the receiving party.
By the scheme, the problem that the same short message is repeatedly sent to the user when a plurality of short message platform threads or processes send the short message from the message queue is solved by performing distributed locking on the sent message in the message queue, the short message sending cost is reduced, the user is prevented from receiving a plurality of same short messages, and therefore user experience is improved.
It should be noted that each unit in the apparatus may be configured to implement each step in the method, and achieve the corresponding technical effect, which is not described herein again.
Referring to fig. 6, fig. 6 is a schematic structural diagram of an electronic device according to an embodiment of the present invention.
As shown in fig. 6, the electronic device may include: a processor 1001, e.g. a CPU, a communication bus 1002, a user interface 1003, a network interface 1004, a memory 1005. The communication bus 1002 is used to implement connection communication among these components. The user interface 1003 may include a Display screen (Display), an input unit such as a Keyboard (Keyboard), and the optional user interface 1003 may also include a standard wired interface, a wireless interface. The network interface 1004 may optionally include standard wired interfaces, wireless interfaces (e.g., WI-FI, 4G, 5G interfaces). The memory 1005 may be a high-speed RAM memory or a non-volatile memory (e.g., a magnetic disk memory). The memory 1005 may alternatively be a storage device separate from the processor 1001 described previously.
Those skilled in the art will appreciate that the configuration shown in fig. 6 does not constitute a limitation of the electronic device and may include more or fewer components than those shown, or some components may be combined, or a different arrangement of components.
As shown in fig. 6, a memory 1005, which is a kind of computer storage medium, may include therein an operating system, a network communication module, a user interface module, and a distributed lock-based information transmission program.
In the electronic apparatus shown in fig. 6, the network interface 1004 is mainly used for data communication with an external network; the user interface 1003 is mainly used for receiving an input instruction of a user; the electronic device calls, through the processor 1001, the distributed lock-based information transmission program stored in the memory 1005, and performs the following operations:
receiving a first information sending request message, wherein the first information sending request message comprises a receiver mobile phone number and information;
generating a sending information identifier according to the mobile phone number of the receiving party, the information and the time period;
storing the receiver mobile phone number, the information, the time period and the sending information identification to a second information sending request message;
sending the second information sending request message to message queue middleware;
acquiring the second information sending request message from the message queue middleware;
adding a distributed lock to the sending information identifier; if the distributed lock is added successfully, the information is sent to the mobile phone number of the receiving party; and if the distributed lock is unsuccessfully added, the information is not sent to the mobile phone number of the receiving party.
Optionally, the generating the sending information identifier is implemented by:
and performing MD5 calculation on the mobile phone number of the receiver, the information and the time period to obtain an MD5 value, wherein the MD5 value is used as the transmitted information identifier.
Optionally, the time period is obtained by:
dividing a period of time into a plurality of time periods, wherein the duration of the time periods is set according to the duration of a time interval allowing repeated information transmission;
acquiring the moment of receiving the information sending request message;
and matching in the time periods according to the time to obtain the matched time period.
Optionally, the adding a distributed lock to the sending information identifier includes:
storing the sending information identifier into a Redis database by using a setnx command of the Redis database;
if the storage is successful, indicating that the adding of the distributed lock is successful; if the store fails, it indicates that the addition of the distributed lock failed.
Optionally, the method further comprises the steps of:
acquiring the time period of the second information sending request message;
acquiring the duration of the time period;
and setting the time length as the timeout time of the setnx command.
Optionally, the method further comprises the steps of:
after receiving the first information sending request message, carrying out validity detection on the receiver mobile phone number and the information;
if the validity detection fails, discarding the first information sending request message; and if the validity detection is successful, continuing to process the subsequent steps.
Optionally, the information includes at least one of a short message, a multimedia message, and a video short message.
According to the scheme, the problem that the same short message is repeatedly sent to the user when a plurality of short message platform threads or processes send the short message from the message queue is solved by carrying out distributed locking on the sent message in the message queue, the short message sending cost is reduced, the user is prevented from receiving a plurality of same short messages, and therefore user experience is improved.
Furthermore, an embodiment of the present invention further provides a computer-readable storage medium, where an information sending program based on a distributed lock is stored on the computer-readable storage medium, and when executed by a processor, the information sending program based on the distributed lock implements the following operations:
receiving a first information sending request message, wherein the first information sending request message comprises a receiver mobile phone number and information;
generating a sending information identifier according to the mobile phone number of the receiving party, the information and the time period;
storing the receiver mobile phone number, the information, the time period and the sending information identification to a second information sending request message;
sending the second information sending request message to the message queue middleware;
acquiring the second information sending request message from the message queue middleware;
adding a distributed lock to the sending information identifier; if the distributed lock is successfully added, the information is sent to the mobile phone number of the receiver; and if the distributed lock is unsuccessfully added, the information is not sent to the mobile phone number of the receiving party.
Optionally, the generating the sending information identifier is implemented by:
and performing MD5 calculation on the mobile phone number of the receiver, the information and the time period to obtain an MD5 value, wherein the MD5 value is used as the sent information identifier.
Optionally, the time period is obtained by:
dividing a period of time into a plurality of time periods, wherein the duration of the time periods is set according to the duration of a time interval allowing repeated information transmission;
acquiring the time when the information sending request message is received;
and matching in the time periods according to the time to obtain the matched time period.
Optionally, the adding a distributed lock to the sending information identifier includes:
storing the sending information identification into a Redis database by using a setnx command of the Redis database;
if the storage is successful, indicating that the adding of the distributed lock is successful; if the store fails, it indicates that the adding of the distributed lock failed.
Optionally, the method further comprises the steps of:
acquiring the time period of the second information sending request message;
acquiring the duration of the time period;
and setting the time length as the timeout time of the setnx command.
Optionally, the method further comprises the steps of:
after receiving the first information sending request message, carrying out validity detection on the receiving mobile phone number and the information;
if the validity detection fails, discarding the first information sending request message; and if the validity detection is successful, continuing to process the subsequent steps.
Optionally, the information includes at least one of a short message, a multimedia message, and a video short message. .
By the scheme, the problem that the same short message is repeatedly sent to the user when a plurality of short message platform threads or processes send the short message from the message queue is solved by performing distributed locking on the sent message in the message queue, the short message sending cost is reduced, the user is prevented from receiving a plurality of same short messages, and therefore user experience is improved.
It should be noted that, in this document, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or system that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or system. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in the process, method, article, or system in which the element is included.
The above-mentioned serial numbers of the embodiments of the present invention are merely for description and do not represent the merits of the embodiments.
Through the description of the foregoing embodiments, it is clear to those skilled in the art that the method of the foregoing embodiments may be implemented by software plus a necessary general hardware platform, and certainly may also be implemented by hardware, but in many cases, the former is a better implementation. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a storage medium (e.g., ROM/RAM, magnetic disk, optical disk) as described above and includes instructions for enabling a terminal device (e.g., a mobile phone, a computer, a server, a controller, or a network device) to execute the method according to the embodiments of the present invention.
The above description is only a preferred embodiment of the present invention, and is not intended to limit the scope of the present invention, and all equivalent structures or equivalent processes performed by the present invention or directly or indirectly applied to other related technical fields are also included in the scope of the present invention.
Claims (10)
1. An information sending method based on distributed lock, characterized in that the method comprises the following steps:
receiving a first information sending request message, wherein the first information sending request message comprises a receiver mobile phone number and information;
generating a sending information identifier according to the mobile phone number of the receiving party, the information and the time period; the time period is a time range to which the time when the first sending request message is received belongs;
storing the receiver mobile phone number, the information, the time period and the sending information identification to a second information sending request message;
sending the second information sending request message to a message queue;
acquiring the second information sending request message from the message queue;
adding a distributed lock to the sending information identifier; if the distributed lock is successfully added, the information is sent to the mobile phone number of the receiver; and if the distributed lock is failed to be added, the information is not sent to the mobile phone number of the receiver.
2. The method of claim 1, wherein generating the transmission information identifier is performed by:
and performing MD5 calculation on the mobile phone number of the receiver, the information and the time period to obtain an MD5 value, wherein the MD5 value is used as the transmitted information identifier.
3. The method of claim 1, wherein the time period is obtained by:
dividing a period of time into a plurality of time periods, wherein the duration of the time periods is set according to the duration of time intervals allowing the information to be repeatedly sent;
acquiring the moment of receiving the information sending request message;
and matching in the time periods according to the time to obtain the matched time period.
4. The method of claim 1, wherein the adding a distributed lock to the send information identifier comprises:
storing the sending information identifier into a Redis database by using a setnx command of the Redis database;
if the storage is successful, indicating that the distributed lock is successfully added; if the store fails, it indicates that the adding of the distributed lock failed.
5. The method according to claim 4, characterized in that the method further comprises the steps of:
acquiring the time period of the second information sending request message;
acquiring the duration of the time period;
and setting the duration as the timeout time of the setnx command.
6. The method of claim 1, further comprising the steps of:
after receiving the first information sending request message, carrying out validity detection on the mobile phone number of the receiving party and the information;
if the validity detection fails, discarding the first information sending request message; and if the validity detection is successful, continuing to process the subsequent steps.
7. The method of claim 1, wherein the information comprises at least one of a text message, a multimedia message, and a video message.
8. An apparatus for sending information based on a distributed lock, the apparatus comprising:
the receiving unit is used for receiving a first information sending request message, wherein the first information sending request message comprises a mobile phone number and information of a receiving party;
the calculation unit is used for generating a sending information identifier according to the mobile phone number of the receiving party, the information and the time period; the time period is a time range to which the time when the first sending request message is received belongs; the mobile phone number of the receiving party, the information, the time period and the sending information identification are also stored in the mobile phone number of the receiving party to a second information sending request message;
a sending unit, configured to send the second information sending request message to a message queue;
the distributed locking unit is used for acquiring the second information sending request message from the message queue; the distributed lock is added to the sending information identification; if the distributed lock is added successfully, the information is sent to the mobile phone number of the receiving party; and if the distributed lock is unsuccessfully added, the information is not sent to the mobile phone number of the receiving party.
9. An electronic device, characterized in that the electronic device comprises: a memory, a processor and a distributed lock based messaging program stored on the memory and executable on the processor, the distributed lock based messaging program configured to implement the steps of the distributed lock based messaging method according to any of claims 1 to 7.
10. A computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out the steps of the distributed lock-based information transmission method according to any one of claims 1 to 7.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202110959704.1A CN113794998B (en) | 2021-08-20 | 2021-08-20 | Information sending method and device based on distributed lock and storage medium |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202110959704.1A CN113794998B (en) | 2021-08-20 | 2021-08-20 | Information sending method and device based on distributed lock and storage medium |
Publications (2)
Publication Number | Publication Date |
---|---|
CN113794998A CN113794998A (en) | 2021-12-14 |
CN113794998B true CN113794998B (en) | 2022-07-15 |
Family
ID=79181902
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202110959704.1A Active CN113794998B (en) | 2021-08-20 | 2021-08-20 | Information sending method and device based on distributed lock and storage medium |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN113794998B (en) |
Families Citing this family (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN114553815A (en) * | 2022-01-29 | 2022-05-27 | 北京金堤科技有限公司 | Method and device for processing message |
Citations (7)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101872296A (en) * | 2010-06-18 | 2010-10-27 | 中兴通讯股份有限公司 | Device and method for realizing high-capacity mass texting |
CN103503388A (en) * | 2011-09-01 | 2014-01-08 | 华为技术有限公司 | Distributed queue message reading method, device and system |
CN108810832A (en) * | 2018-04-20 | 2018-11-13 | 广州市玄武无线科技股份有限公司 | Short message delivery method, device and computer readable storage medium |
CN109714239A (en) * | 2018-12-27 | 2019-05-03 | 新华三技术有限公司 | A kind of delivery method, VNFM equipment and server managing message |
CN111065061A (en) * | 2019-11-25 | 2020-04-24 | 佛山欧神诺云商科技有限公司 | Short message request sending system and method based on multiple channels and storage medium |
CN111562992A (en) * | 2020-04-14 | 2020-08-21 | 广东博智林机器人有限公司 | Message consumption method and device for client, electronic equipment and storage medium |
CN111741110A (en) * | 2020-06-22 | 2020-10-02 | 北京奇艺世纪科技有限公司 | Message pushing system and method |
Family Cites Families (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US8627333B2 (en) * | 2011-08-03 | 2014-01-07 | International Business Machines Corporation | Message queuing with flexible consistency options |
-
2021
- 2021-08-20 CN CN202110959704.1A patent/CN113794998B/en active Active
Patent Citations (7)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101872296A (en) * | 2010-06-18 | 2010-10-27 | 中兴通讯股份有限公司 | Device and method for realizing high-capacity mass texting |
CN103503388A (en) * | 2011-09-01 | 2014-01-08 | 华为技术有限公司 | Distributed queue message reading method, device and system |
CN108810832A (en) * | 2018-04-20 | 2018-11-13 | 广州市玄武无线科技股份有限公司 | Short message delivery method, device and computer readable storage medium |
CN109714239A (en) * | 2018-12-27 | 2019-05-03 | 新华三技术有限公司 | A kind of delivery method, VNFM equipment and server managing message |
CN111065061A (en) * | 2019-11-25 | 2020-04-24 | 佛山欧神诺云商科技有限公司 | Short message request sending system and method based on multiple channels and storage medium |
CN111562992A (en) * | 2020-04-14 | 2020-08-21 | 广东博智林机器人有限公司 | Message consumption method and device for client, electronic equipment and storage medium |
CN111741110A (en) * | 2020-06-22 | 2020-10-02 | 北京奇艺世纪科技有限公司 | Message pushing system and method |
Non-Patent Citations (1)
Title |
---|
一种高性能的全序组播算法;李磊等;《计算机研究与发展》;20070915(第09期);全文 * |
Also Published As
Publication number | Publication date |
---|---|
CN113794998A (en) | 2021-12-14 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
EP2146466B1 (en) | Methods and systems to resolve message group | |
CN108574722B (en) | Resource synchronization method, device and system | |
CN109451020B (en) | Timeout management method, timeout management device, and computer-readable storage medium | |
CN113794998B (en) | Information sending method and device based on distributed lock and storage medium | |
CN111193789B (en) | Subscription information pushing method, device, computer equipment and readable storage medium | |
CN113794999B (en) | Short message distribution method, device and storage medium | |
CN112087475B (en) | Message pushing method and device for cloud platform component application and message server | |
CN110333916B (en) | Request message processing method, device, computer system and readable storage medium | |
CN113645578B (en) | Method and device for preventing repeated sending of information and storage medium | |
CN101753561B (en) | Business cluster processing method and cluster system | |
CN110493735B (en) | Short message processing method and device | |
CN110971535B (en) | Communication congestion control method, device, equipment and storage medium | |
CN107977380B (en) | Method and device for generating page | |
CN112787978B (en) | Data acquisition method and device, computer equipment and computer-readable storage medium | |
CN111309744A (en) | Object processing method and device, electronic equipment and computer readable storage medium | |
CN114221925A (en) | Message pushing method and device, electronic equipment and storage medium | |
CN113138862A (en) | Message processing method, server, device, system and storage medium | |
CN113395240A (en) | Data acquisition method, device, equipment and medium | |
CN109104702B (en) | Information interception method, device and storage medium | |
CN112702270B (en) | Node calling method, system and storage medium based on event distribution mechanism | |
CN115334466B (en) | Message sending method and device, electronic equipment and storage medium | |
CN112115020B (en) | Database connection pool abnormity monitoring method and device and computer equipment | |
CN109918278B (en) | Method and device for monitoring operation times of user system and computer storage medium | |
CN114254027A (en) | Data processing method, device, equipment and storage medium | |
CN115293730A (en) | Vehicle engineering data sending method, device, equipment and readable storage medium |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |