[go: up one dir, main page]

CN115767448B - Message sending method, device, equipment and storage medium - Google Patents

Message sending method, device, equipment and storage medium Download PDF

Info

Publication number
CN115767448B
CN115767448B CN202211564511.7A CN202211564511A CN115767448B CN 115767448 B CN115767448 B CN 115767448B CN 202211564511 A CN202211564511 A CN 202211564511A CN 115767448 B CN115767448 B CN 115767448B
Authority
CN
China
Prior art keywords
message
sending
service
asynchronous
service message
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
Application number
CN202211564511.7A
Other languages
Chinese (zh)
Other versions
CN115767448A (en
Inventor
朱永科
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Jingdong Technology Information Technology Co Ltd
Original Assignee
Jingdong Technology Information Technology Co Ltd
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by Jingdong Technology Information Technology Co Ltd filed Critical Jingdong Technology Information Technology Co Ltd
Priority to CN202211564511.7A priority Critical patent/CN115767448B/en
Publication of CN115767448A publication Critical patent/CN115767448A/en
Application granted granted Critical
Publication of CN115767448B publication Critical patent/CN115767448B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Landscapes

  • Computer And Data Communications (AREA)

Abstract

The embodiment of the invention discloses a message sending method, a message sending device, message sending equipment and a storage medium. The method is applied to the service end and comprises the following steps: responding to a sending trigger instruction of a first service message, and acquiring a current message sending mode of a service end by calling a preloaded message sending component; if the current message sending mode is an asynchronous sending mode, writing the first service message into a cache queue based on the route configuration information; generating an asynchronous transmission task corresponding to a second service message based on the second service message to be transmitted in the buffer queue, wherein the second service message comprises the first service message; and executing an asynchronous sending task through an asynchronous thread, and asynchronously sending the second service message to the message middleware server. By the technical scheme of the embodiment of the invention, the asynchronous sending of the service message can be realized, the time consumption for sending the message is reduced, and the user experience is improved.

Description

Message sending method, device, equipment and storage medium
Technical Field
Embodiments of the present invention relate to computer technologies, and in particular, to a method, an apparatus, a device, and a storage medium for sending a message.
Background
With the rapid development of computer technology, the problem of strong coupling between message producers and message consumers can be solved by a message middleware server.
At present, after the service end generates the service message, the generated service message is synchronously sent to the message middleware server. The synchronous sending means that after the service end sends the service message to the message middleware server, whether the service message is sent successfully or not is detected, and after the service message is sent successfully, the subsequent service logic operation is executed.
However, in the process of implementing the present invention, the inventors found that at least the following problems exist in the prior art:
In the process of synchronously sending service messages, if network jitter is encountered or the response of a message middleware server is overtime, the message cannot be successfully sent, at this time, a service end can continuously wait and cannot execute subsequent service logic operation, so that the time consumption for sending the message is long, and the user experience is reduced.
Disclosure of Invention
The embodiment of the invention provides a message sending method, a device, equipment and a storage medium, which are used for realizing asynchronous sending of service messages, reducing message sending time consumption and improving user experience.
In a first aspect, an embodiment of the present invention provides a method for sending a message, which is applied to a service end, including:
Responding to a sending trigger instruction of a first service message, and acquiring a current message sending mode of the service end by calling a preloaded message sending component;
If the current message sending mode is an asynchronous sending mode, writing the first service message into a cache queue based on route configuration information;
Generating an asynchronous transmission task corresponding to a second service message based on the second service message to be transmitted in the cache queue, wherein the second service message comprises the first service message;
and executing the asynchronous sending task through an asynchronous thread, and asynchronously sending the second service message to a message middleware server.
In a second aspect, an embodiment of the present invention further provides a message sending device, which is integrated at a service end, including:
The current message sending mode acquisition module is used for responding to a sending trigger instruction of the first service message and acquiring the current message sending mode of the service end by calling a preloaded message sending component;
the first service message writing module is used for writing the first service message into a cache queue based on route configuration information if the current message sending mode is an asynchronous sending mode;
The asynchronous sending task generating module is used for generating an asynchronous sending task corresponding to a second service message based on the second service message to be sent in the cache queue, wherein the second service message comprises the first service message;
and the asynchronous sending module is used for executing the asynchronous sending task through an asynchronous thread and asynchronously sending the second service message to the message middleware server.
In a third aspect, an embodiment of the present invention further provides a message sending system, where the system includes a service end and a message middleware server: wherein,
The service end is used for realizing the message sending method provided by any embodiment of the invention.
In a fourth aspect, an embodiment of the present invention further provides an electronic device, including:
One or more processors;
a memory for storing one or more programs;
the one or more programs, when executed by the one or more processors, cause the one or more processors to implement the messaging method as provided by any embodiment of the present invention.
In a fifth aspect, embodiments of the present invention further provide a computer readable storage medium having stored thereon a computer program which, when executed by a processor, implements a messaging method as provided by any of the embodiments of the present invention.
One embodiment of the above invention has the following advantages or benefits:
The service end responds to a sending trigger instruction of the first service message, a current message sending mode of the service end is obtained by calling a preloaded message sending component, if the current message sending mode is an asynchronous sending mode, the first service message is written into a cache queue based on route configuration information, and an asynchronous sending task corresponding to the second service message is generated based on the second service message to be sent in the cache queue, the second service message comprises the first service message, the asynchronous sending task is executed through an asynchronous thread, the second service message is asynchronously sent to a message middleware server, and therefore the service end only needs to store the service message to be sent into the cache queue, and realizes asynchronous sending of the service message by using the cache queue without executing subsequent service logic operation after the service message is successfully sent. And the service end can pre-load the message sending component so as to carry out asynchronous sending of the service message through the message sending component, thereby realizing componentization and improving the multiplexing rate of different service ends.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, a brief description will be given below of the drawings required for the embodiments or the prior art descriptions, and it is obvious that the drawings in the following description are some embodiments of the present invention, and other drawings may be obtained according to these drawings without inventive effort for a person skilled in the art.
FIG. 1 is a flow chart of a method of messaging provided in one embodiment of the present invention;
FIG. 2 is an example of a messaging process according to an embodiment of the present invention;
FIG. 3 is a flow chart of another messaging method provided by one embodiment of the present invention;
Fig. 4 is a schematic structural diagram of a message sending device according to an embodiment of the present invention;
FIG. 5 is a schematic diagram of a messaging system according to one embodiment of the present invention;
Fig. 6 is a schematic structural diagram of an electronic device according to an embodiment of the present invention.
Detailed Description
The invention is described in further detail below with reference to the drawings and examples. It is to be understood that the specific embodiments described herein are merely illustrative of the invention and are not limiting thereof. It should be further noted that, for convenience of description, only some, but not all of the structures related to the present invention are shown in the drawings.
Fig. 1 is a flowchart of a message sending method according to an embodiment of the present invention, where the embodiment is applicable to a case of asynchronously sending a service message generated by a service end. The method can be executed by a message sending device, and the device can be realized by a software and/or hardware mode and integrated on a service end. The service end can be any message production end for producing service messages. For example, the service end may refer to an internet of things device. As shown in fig. 1, the method specifically includes the following steps:
s110, responding to a sending trigger instruction of the first service message, and acquiring a current message sending mode of the service end by calling a preloaded message sending component.
The first service message may refer to a service message that is currently generated by the service end and needs to be sent. The transmission trigger instruction may be an instruction for indicating that a service message is currently required to be transmitted. The messaging component may be a component obtained by encapsulating pre-written messaging logic code. For example, the messaging component may refer to a jar packet that is loadable by the service side. The current message sending mode may refer to a message sending mode in which the service end is located at the current moment. The message transmission mode may include an asynchronous transmission mode or a synchronous transmission mode. The asynchronous transmission mode is to asynchronously transmit the service message. The synchronous transmission mode is to synchronously transmit the service message.
Specifically, each service end that needs to send a message may pre-load a message sending component, such as an installation component jar packet, so as to use the loaded message sending component to perform a message asynchronous sending operation, that is, the operations of steps S110-S140, so that the modularization can be achieved, and the multiplexing rate of different service ends can be improved. The service end can generate a first service message based on the currently acquired service data, and generate a sending trigger instruction of the first service message after generating the first service message so as to trigger the sending operation of the first service message. If a sending trigger instruction of the first service message is detected, a current message sending mode of the service end can be obtained by calling a preloaded message sending component.
And S120, if the current message sending mode is an asynchronous sending mode, writing the first service message into a cache queue based on the route configuration information.
The routing configuration information may be configured in the message sending component, and is used for indicating the designated cache queue written by each service message, so that the service end may route each service message to the corresponding cache queue for writing. The cache queue may be a pre-set queue for caching messages. The cache queue may be implemented using a distributed cache. For example, dual R2M and JIMDB caches may be employed, while the R2M primary caches may be distributed among pre-configured rooms, such as three different rooms, so that high availability of caches may be guaranteed. Wherein, R2M and JIMDB are high-performance distributed cache systems constructed based on open source Redis cluster.
Specifically, fig. 2 gives an example of a message transmission procedure. As shown in fig. 2, after the service side loads the message sending component, a multi-machine-room cluster for implementing the cache queue and routing information for writing into the cache queue can be configured in the spring configuration file so as to meet the personalized requirement. After configuration is completed, when the service end calls the message sending component to send the generated first service message, the service end can detect whether the current message sending mode of the service end is an asynchronous sending mode, if yes, a cache queue corresponding to the first service message is determined based on a mode taking mode in the route configuration information, the first service message is written into the corresponding cache queue, subsequent service logic operation can be continued after the first service message is written successfully, and the subsequent service logic operation is not required to be executed after the service message is successfully sent, so that the message sending efficiency is improved, the message sending time consumption is reduced, and the user experience is improved.
S130, generating an asynchronous sending task corresponding to the second service message based on the second service message to be sent in the buffer queue, wherein the second service message comprises the first service message.
The second service message may be a service message to be sent, which is cached in the cache queue. The first service message is written into the cache queue, and the second service message fetched from the cache queue may be the first service message written currently or the service message written previously. Each second service message corresponds to an asynchronous transmission task, so that the corresponding second service message is transmitted by using the asynchronous transmission task.
Specifically, the embodiment may generate an asynchronous sending task corresponding to each second service message based on each second service message to be sent in the buffer queue, and may sequentially execute each asynchronous sending task according to the sequence of writing the messages.
And S140, executing an asynchronous sending task through an asynchronous thread, and asynchronously sending the second service message to the message middleware server.
The message middleware server may be a message middleware platform for providing reliable delivery of messages and data. For example, the message middleware server may be, but is not limited to, JMQ message middleware platform.
Specifically, the asynchronous transmission task that is successfully generated may be added to the task queue so that each asynchronous transmission task is sequentially executed based on the task queue. The present embodiment may create an asynchronous thread to sequentially execute asynchronous send tasks in the task queue using the asynchronous thread. An asynchronous thread pool can be created, and a plurality of asynchronous threads in the asynchronous thread pool are utilized to concurrently execute asynchronous sending tasks, so that the message sending efficiency is further improved. By executing the asynchronous sending task through the asynchronous thread, the second service message in the asynchronous sending task can be sent to the message middleware server asynchronously, so that the asynchronous sending of the service message is realized.
Illustratively, "send second service message asynchronously to message middleware server" in S140 may include: and if the failure of sending the second service message is detected, the second service message is asynchronously sent to the message compensation server, and the message compensation server resends the second service message to the message middleware server until the second service message is successfully sent.
The message compensation server may refer to a platform for performing exception compensation on the message middleware. For example, the message compensation server may refer to MQSender platforms.
Specifically, in the process of executing the asynchronous sending task of the second service message, if it is detected that the message sending success information returned by the message middleware server is not received within the preset timeout time, that is, network jitter is encountered or the response of the message middleware server is overtime, it can be determined that the sending of the second service message fails, at this time, the second service message can be automatically degraded, sent to the message compensation server asynchronously, and the message compensation server continuously resends the second service message until the second service message is successfully sent to the message middleware server, so that the condition of message loss can be avoided, and the successful sending of the service message is ensured.
For example, after the second service message is successfully sent, the second service message may be removed from the buffer queue, or the corresponding asynchronous sending task may be removed from the task queue, so as to avoid multiple sending of the same service message.
According to the technical scheme, the service end responds to the sending trigger instruction of the first service message, the preloaded message sending component is called to obtain the current message sending mode of the service end, if the current message sending mode is an asynchronous sending mode, the first service message is written into the cache queue based on the route configuration information, and the asynchronous sending task corresponding to the second service message is generated based on the second service message to be sent in the cache queue, the second service message comprises the first service message, the asynchronous sending task is executed through the asynchronous thread, the second service message is asynchronously sent to the message middleware server, therefore, the service end only needs to store the service message to be sent into the cache queue, asynchronous sending of the service message is achieved through the cache queue, and subsequent service logic operation is not required to be executed after the service message is successfully sent, so that the message sending efficiency is improved, the message sending time consumption is reduced, and the user experience is improved. And the service end can pre-load the message sending component so as to carry out asynchronous sending of the service message through the message sending component, thereby realizing componentization and improving the multiplexing rate of different service ends.
Based on the technical scheme, the method can further comprise the following steps: if the current message sending mode is detected to be a synchronous sending mode or the first service message fails to be written into the cache queue, synchronously sending the first service message to the message middleware server through the main thread; if the first service message is detected to be sent to fail, the first service message is synchronously sent to the message compensation server, and the message compensation server resends the first service message to the message middleware server until the first service message is sent successfully.
Specifically, as shown in fig. 2, when the current message sending mode is detected to be the synchronous sending mode, it indicates that synchronous sending of the message is currently required, and at this time, a sending instruction may be executed in the main thread to synchronously send the first service message to the message middleware server. The method can detect whether the message sending success information returned by the message middleware server is received within the preset timeout time, namely detect whether network jitter is encountered or the response of the message middleware server is overtime, if the message sending success information is not received, the first service message sending failure can be determined, the first service message can be automatically degraded at the moment, the first service message is synchronously sent to the message compensation server, and the message compensation server continuously resends the first service message until the first service message is successfully sent to the message middleware server, so that the condition of message loss can be avoided, and the successful sending of the service message is ensured.
As shown in fig. 2, when it is detected that the first service message fails to be written into the cache queue (i.e., the writing success information is not received within the preset timeout period), it indicates that the asynchronous sending operation of the message cannot be continued currently, and at this time, a sending instruction may be executed in the main thread, and the first service message is synchronously sent to the message middleware server. The method can detect whether the message sending success information returned by the message middleware server is received within the preset timeout time, namely detect whether network jitter is encountered or the response of the message middleware server is overtime, if the message sending success information is not received, the first service message sending failure can be determined, the first service message can be automatically degraded at the moment, the first service message is synchronously sent to the message compensation server, and the message compensation server continuously resends the first service message until the first service message is successfully sent to the message middleware server, so that the condition of message loss can be avoided, and the successful sending of the service message is ensured.
Based on the technical scheme, the method can further comprise the following steps: if the generation failure of the asynchronous sending task corresponding to the second service message is detected, or the execution failure of the asynchronous sending task is detected, the second service message is sent to a message middleware server through a main thread; and if the failure of sending the second service message is detected, sending the second service message to the message compensation server, and retransmitting the first service message to the message middleware server by the message compensation server until the first service message is successfully sent.
Specifically, as shown in fig. 2, when it is detected that the generation of the asynchronous sending task corresponding to the second service message fails, it indicates that the second service message cannot be sent asynchronously and needs to be sent synchronously, and at this time, a sending instruction may be executed in the main thread to send the second service message to the message middleware server synchronously. The message sending success information returned by the message middleware server can be detected whether to receive the message sending success information within the preset timeout time, namely whether to encounter network jitter or response timeout of the message middleware server is detected, if the message sending success information is not received, the failure of sending the second service message can be determined, the message can be automatically degraded at the moment, the second service message is synchronously sent to the message compensation server, and the message compensation server continuously resends the second service message until the second service message is successfully sent to the message middleware server, so that the condition of losing the message can be avoided, and the successful sending of the service message is ensured.
As shown in fig. 2, when the failure of executing the asynchronous sending task is detected, it indicates that the second service message cannot be sent asynchronously and needs to be sent synchronously, and at this time, a sending instruction may be executed in the main thread to send the second service message to the message middleware server synchronously. The message sending success information returned by the message middleware server can be detected whether to receive the message sending success information within the preset timeout time, namely whether to encounter network jitter or response timeout of the message middleware server is detected, if the message sending success information is not received, the failure of sending the second service message can be determined, the message can be automatically degraded at the moment, the second service message is synchronously sent to the message compensation server, and the message compensation server continuously resends the second service message until the second service message is successfully sent to the message middleware server, so that the condition of losing the message can be avoided, and the successful sending of the service message is ensured.
Based on the technical scheme, the method can further comprise the following steps: determining a current message sending success rate and/or a current buffer queue length in a current message sending mode; and if the current meeting of the preset mode switching condition is determined based on the current message sending success rate and/or the current buffer queue length, performing mode switching on the current message sending mode.
Specifically, after each service message is sent, whether the sending result of each service message in the current message sending mode is successful or failed can be monitored through a daemon thread (i.e. a service thread for serving other threads), and the message sending result is stored and counted to determine the current message sending success rate in the current message sending mode. The current buffer queue length can also be monitored in real time by the daemon thread. The daemon thread can indicate that the current message sending mode cannot meet the message sending requirement when detecting that the current message sending success rate is smaller than or equal to the preset success rate, can determine that the current message sending mode meets the preset mode switching condition at the moment, and then switches the current message sending mode to another message sending mode so as to send the message in the other message sending mode, thereby realizing high-availability sending of the message. The daemon thread can also indicate that the asynchronous sending pressure is larger when detecting that the length of the current buffer queue in the asynchronous sending mode is larger than the preset queue length and/or the sending success rate of the current message is smaller than or equal to the preset success rate, and can automatically switch the asynchronous sending mode into the synchronous sending mode at the moment so as to synchronously send the subsequent message and ensure the successful sending of the subsequent message. Or when the current buffer queue length in the synchronous transmission mode is detected to be smaller than the preset queue length, the asynchronous transmission pressure is not shown, and the synchronous transmission mode can be automatically switched to the asynchronous transmission mode at the moment, so that subsequent messages can be asynchronously transmitted, and the message transmission efficiency is improved. Asynchronous high availability messaging JMQ may be achieved by automatic switching of messaging modes.
Fig. 3 is a flowchart of another message sending method according to an embodiment of the present invention, where the execution process of at least one asynchronous sending task is described in detail by using an asynchronous thread pool based on the above embodiments. Wherein the explanation of the same or corresponding terms as those of the above embodiments is not repeated herein.
Referring to fig. 3, another message sending method provided in this embodiment specifically includes the following steps:
s310, responding to a sending trigger instruction of the first service message, and acquiring a current message sending mode of the service end by calling a preloaded message sending component.
And S320, if the current message sending mode is an asynchronous sending mode, writing the first service message into a cache queue based on the routing configuration information.
S330, generating an asynchronous sending task corresponding to the second service message based on the second service message to be sent in the buffer queue, wherein the second service message comprises the first service message.
And S340, adding the generated at least one asynchronous sending task into an asynchronous thread pool, and distributing a corresponding asynchronous thread to each asynchronous sending task.
Wherein the asynchronous thread pool may be a way of multi-threaded processing. The asynchronous thread pool may include a plurality of asynchronous threads.
Specifically, all the generated asynchronous sending tasks are added to an asynchronous thread pool, and one asynchronous thread in the asynchronous thread pool is allocated for each asynchronous sending task. The daemon thread can detect whether each cache queue has an asynchronous transmission task which is not processed for a long time, if so, the asynchronous thread can be preferentially allocated to the tasks which are not executed for a long time so as to preferentially execute the tasks, and after the execution is successful, the tasks can be automatically removed.
S350, executing corresponding asynchronous sending tasks through each asynchronous thread, and sending second service messages in the corresponding asynchronous sending tasks to the message middleware server asynchronously.
Specifically, each asynchronous thread in the asynchronous thread pool can concurrently execute the assigned asynchronous sending task, so that a plurality of second service messages are concurrently sent to the message middleware server, and the message sending efficiency can be further improved.
Illustratively, S350 may include: each asynchronous thread detects whether the task state of an asynchronous sending task to be executed currently is an unlocked state; if the asynchronous sending task is in the unlocked state, a distributed lock is added to the asynchronous sending task to be executed currently so as to update the task state to be in the locked state, and a second service message in the asynchronous sending task to be executed currently is asynchronously sent to the message middleware server.
Specifically, when each asynchronous thread detects that the task state of the asynchronous sending task to be currently executed is an unlocked state, it indicates that no other asynchronous thread executes the asynchronous sending task, at this time, a distributed lock can be added to the asynchronous sending task, and the task state is updated from the unlocked state to the locked state, so that other asynchronous threads are prevented from executing the asynchronous sending task, further, the situation that the same service message is repeatedly sent for a plurality of times is avoided, and further, the accuracy of message sending is ensured.
According to the technical scheme of the embodiment, the plurality of asynchronous threads in the asynchronous thread pool are utilized to execute the asynchronous sending task in parallel, so that the plurality of second service messages are sent to the message middleware server in parallel, and the message sending efficiency can be further improved.
The following is an embodiment of a message sending device provided by an embodiment of the present invention, which belongs to the same inventive concept as the message sending method of the above embodiments, and reference may be made to the embodiment of the message sending method for details that are not described in detail in the embodiment of the message sending device.
Fig. 4 is a schematic structural diagram of a message sending device according to an embodiment of the present invention, where the embodiment is applicable to a case of asynchronously sending a service message generated by a service end. As shown in fig. 4, the device is integrated at a service end, and specifically includes: the current messaging mode acquisition module 410, the first service message writing module 420, the asynchronous transfer task generation module 430, and the asynchronous transfer module 440.
The current message sending mode obtaining module 410 is configured to obtain a current message sending mode of the service end by calling a preloaded message sending component in response to a sending trigger instruction of the first service message; a first service message writing module 420, configured to write, if the current message sending mode is an asynchronous sending mode, the first service message into a buffer queue based on route configuration information; an asynchronous sending task generating module 430, configured to generate an asynchronous sending task corresponding to a second service message based on the second service message to be sent in the buffer queue, where the second service message includes the first service message; and the asynchronous sending module 440 is configured to perform the asynchronous sending task through an asynchronous thread, and asynchronously send the second service message to the message middleware server.
According to the technical scheme, the service end responds to the sending trigger instruction of the first service message, the preloaded message sending component is called to obtain the current message sending mode of the service end, if the current message sending mode is an asynchronous sending mode, the first service message is written into the cache queue based on the route configuration information, and the asynchronous sending task corresponding to the second service message is generated based on the second service message to be sent in the cache queue, the second service message comprises the first service message, the asynchronous sending task is executed through the asynchronous thread, the second service message is asynchronously sent to the message middleware server, therefore, the service end only needs to store the service message to be sent into the cache queue, asynchronous sending of the service message is achieved through the cache queue, and subsequent service logic operation is not required to be executed after the service message is successfully sent, so that the message sending efficiency is improved, the message sending time consumption is reduced, and the user experience is improved. And the service end can pre-load the message sending component so as to carry out asynchronous sending of the service message through the message sending component, thereby realizing componentization and improving the multiplexing rate of different service ends.
Optionally, the asynchronous sending module 440 is specifically configured to: and if the failure of sending the second service message is detected, the second service message is asynchronously sent to a message compensation server, and the message compensation server resends the second service message to the message middleware server until the second service message is successfully sent.
Optionally, the apparatus further comprises:
The parameter determining module is used for determining the current message sending success rate and/or the current buffer queue length in the current message sending mode;
And the mode switching module is used for carrying out mode switching on the current message sending mode if the current meeting the preset mode switching condition is determined based on the current message sending success rate and/or the current buffer queue length.
Optionally, the asynchronous transmitting module 440 includes:
An asynchronous thread allocation unit, configured to add at least one generated asynchronous sending task to an asynchronous thread pool, and allocate a corresponding asynchronous thread to each asynchronous sending task;
And the asynchronous sending unit is used for executing the corresponding asynchronous sending tasks through each asynchronous thread, and asynchronously sending the second service messages in the corresponding asynchronous sending tasks to the message middleware server.
Optionally, the asynchronous sending unit is specifically configured to:
Each asynchronous thread detects whether the task state of the asynchronous sending task to be executed currently is an unlocked state or not; and if the asynchronous sending task is in the unlocked state, adding a distributed lock to the asynchronous sending task to be currently executed to update the task state to be in the locked state, and asynchronously sending a second service message in the asynchronous sending task to be currently executed to a message middleware server.
Optionally, the apparatus further comprises:
the first message sending module is used for synchronously sending the first service message to the message middleware server through a main thread if the current message sending mode is detected to be a synchronous sending mode or the first service message fails to be written into the cache queue; and if the failure of the first service message sending is detected, synchronously sending the first service message to a message compensation server, and retransmitting the first service message to the message middleware server by the message compensation server until the first service message is successfully sent.
Optionally, the apparatus further comprises:
The second message sending module is used for sending the second service message to the message middleware server through the main thread if the generation failure of the asynchronous sending task corresponding to the second service message is detected or the execution failure of the asynchronous sending task is detected; and if the failure of sending the second service message is detected, sending the second service message to a message compensation server, and retransmitting the second service message to the message middleware server by the message compensation server until the second service message is sent successfully.
The message sending device provided by the embodiment of the invention can execute the message sending method provided by any embodiment of the invention, and has the corresponding functional modules and beneficial effects of executing the message sending method.
It should be noted that, in the embodiment of the message sending apparatus, each unit and module included are only divided according to the functional logic, but not limited to the above-mentioned division, so long as the corresponding functions can be implemented; in addition, the specific names of the functional units are also only for distinguishing from each other, and are not used to limit the protection scope of the present invention.
Fig. 5 is a schematic structural diagram of a message sending system according to an embodiment of the present invention, where the embodiment is applicable to a case of asynchronously sending a service message generated by a service end. As shown in fig. 5, the system specifically includes: a service end 510 and a message middleware server 520.
The service end 510 is configured to implement a message sending method according to any embodiment of the present invention.
In the message sending system in the embodiment of the present disclosure, the service end 510 responds to a sending trigger instruction of a first service message, and obtains a current message sending mode of the service end by calling a preloaded message sending component, if the current message sending mode is an asynchronous sending mode, the first service message is written into a buffer queue based on route configuration information, and an asynchronous sending task corresponding to a second service message is generated based on the second service message to be sent in the buffer queue, the second service message includes the first service message, the asynchronous sending task is executed through an asynchronous thread, and the second service message is asynchronously sent to the message middleware server 520, so that the service end 510 only needs to store the service message to be sent into the buffer queue, and implements asynchronous sending of the service message by using the buffer queue without waiting for executing subsequent service logic operations after the service message is sent successfully, thereby improving message sending efficiency, reducing message sending time consumption, and further improving user experience. And the service end 510 can pre-load the message sending component so as to send the service message asynchronously through the message sending component, thereby realizing the componentization and improving the multiplexing rate of different service ends.
Fig. 6 is a schematic structural diagram of an electronic device according to an embodiment of the present invention. Fig. 6 illustrates a block diagram of an exemplary electronic device 12 suitable for use in implementing embodiments of the present invention. The electronic device 12 shown in fig. 6 is merely an example and should not be construed as limiting the functionality and scope of use of embodiments of the present invention.
As shown in fig. 6, the electronic device 12 is in the form of a general purpose computing device. Components of the electronic device 12 may include, but are not limited to: one or more processors or processing units 16, a system memory 28, a bus 18 that connects the various system components, including the system memory 28 and the processing units 16.
Bus 18 represents one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, a processor, and a local bus using any of a variety of bus architectures. By way of example, and not limitation, such architectures include Industry Standard Architecture (ISA) bus, micro channel architecture (MAC) bus, enhanced ISA bus, video Electronics Standards Association (VESA) local bus, and Peripheral Component Interconnect (PCI) bus.
Electronic device 12 typically includes a variety of computer system readable media. Such media can be any available media that is accessible by electronic device 12 and includes both volatile and nonvolatile media, removable and non-removable media.
The system memory 28 may include computer system readable media in the form of volatile memory, such as Random Access Memory (RAM) 30 and/or cache memory 32. The electronic device 12 may further include other removable/non-removable, volatile/nonvolatile computer system storage media. By way of example only, storage system 34 may be used to read from or write to non-removable, nonvolatile magnetic media (not shown in FIG. 6, commonly referred to as a "hard disk drive"). Although not shown in fig. 6, a magnetic disk drive for reading from and writing to a removable non-volatile magnetic disk (e.g., a "floppy disk"), and an optical disk drive for reading from or writing to a removable non-volatile optical disk (e.g., a CD-ROM, DVD-ROM, or other optical media) may be provided. In such cases, each drive may be coupled to bus 18 through one or more data medium interfaces. The system memory 28 may include at least one program product having a set (e.g., at least one) of program modules configured to carry out the functions of the embodiments of the invention.
A program/utility 40 having a set (at least one) of program modules 42 may be stored in, for example, system memory 28, such program modules 42 including, but not limited to, an operating system, one or more application programs, other program modules, and program data, each or some combination of which may include an implementation of a network environment. Program modules 42 generally perform the functions and/or methods of the embodiments described herein.
The electronic device 12 may also communicate with one or more external devices 14 (e.g., keyboard, pointing device, display 24, etc.), one or more devices that enable a user to interact with the electronic device 12, and/or any devices (e.g., network card, modem, etc.) that enable the electronic device 12 to communicate with one or more other computing devices. Such communication may occur through an input/output (I/O) interface 22. Also, the electronic device 12 may communicate with one or more networks such as a Local Area Network (LAN), a Wide Area Network (WAN) and/or a public network, such as the Internet, through a network adapter 20. As shown, the network adapter 20 communicates with other modules of the electronic device 12 over the bus 18. It should be appreciated that although not shown, other hardware and/or software modules may be used in connection with electronic device 12, including, but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, data backup storage systems, and the like.
The processing unit 16 executes various functional applications and data processing by running programs stored in the system memory 28, for example, implementing a messaging method step provided by the present embodiment, the method comprising:
Responding to a sending trigger instruction of a first service message, and acquiring a current message sending mode of the service end by calling a preloaded message sending component;
If the current message sending mode is an asynchronous sending mode, writing the first service message into a cache queue based on route configuration information;
Generating an asynchronous transmission task corresponding to a second service message based on the second service message to be transmitted in the cache queue, wherein the second service message comprises the first service message;
and executing the asynchronous sending task through an asynchronous thread, and asynchronously sending the second service message to a message middleware server.
Of course, those skilled in the art will understand that the processor may also implement the technical solution of the message sending method provided in any embodiment of the present invention.
The present embodiment provides a computer-readable storage medium having stored thereon a computer program which, when executed by a processor, implements the message sending method steps as provided by any of the embodiments of the present invention, the method comprising:
Responding to a sending trigger instruction of a first service message, and acquiring a current message sending mode of the service end by calling a preloaded message sending component;
If the current message sending mode is an asynchronous sending mode, writing the first service message into a cache queue based on route configuration information;
Generating an asynchronous transmission task corresponding to a second service message based on the second service message to be transmitted in the cache queue, wherein the second service message comprises the first service message;
and executing the asynchronous sending task through an asynchronous thread, and asynchronously sending the second service message to a message middleware server.
The computer storage media of embodiments of the invention may take the form of any combination of one or more computer-readable media. The computer readable medium may be a computer readable signal medium or a computer readable storage medium. The computer readable storage medium may be, for example, but not limited to: an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or a combination of any of the foregoing. More specific examples (a non-exhaustive list) of the computer-readable storage medium would include the following: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In this document, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device.
The computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, either in baseband or as part of a carrier wave. Such a propagated data signal may take any of a variety of forms, including, but not limited to, electro-magnetic, optical, or any suitable combination of the foregoing. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device.
Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, fiber optic cable, RF, etc., or any suitable combination of the foregoing.
Computer program code for carrying out operations of the present invention may be written in one or more programming languages, including an object oriented programming language such as Java, smalltalk, C ++ and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any kind of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or may be connected to an external computer (for example, through the Internet using an Internet service provider).
It will be appreciated by those of ordinary skill in the art that the modules or steps of the invention described above may be implemented in a general purpose computing device, they may be centralized on a single computing device, or distributed over a network of computing devices, or they may alternatively be implemented in program code executable by a computer device, such that they are stored in a memory device and executed by the computing device, or they may be separately fabricated as individual integrated circuit modules, or multiple modules or steps within them may be fabricated as a single integrated circuit module. Thus, the present invention is not limited to any specific combination of hardware and software.
Note that the above is only a preferred embodiment of the present invention and the technical principle applied. It will be understood by those skilled in the art that the present invention is not limited to the particular embodiments described herein, but is capable of various obvious changes, rearrangements and substitutions as will now become apparent to those skilled in the art without departing from the scope of the invention. Therefore, while the invention has been described in connection with the above embodiments, the invention is not limited to the embodiments, but may be embodied in many other equivalent forms without departing from the spirit or scope of the invention, which is set forth in the following claims.

Claims (11)

1. A message sending method, applied to a service end, comprising:
Responding to a sending trigger instruction of a first service message, and acquiring a current message sending mode of the service end by calling a preloaded message sending component;
If the current message sending mode is an asynchronous sending mode, writing the first service message into a cache queue based on route configuration information;
Generating an asynchronous transmission task corresponding to a second service message based on the second service message to be transmitted in the cache queue, wherein the second service message comprises the first service message;
and executing the asynchronous sending task through an asynchronous thread, and asynchronously sending the second service message to a message middleware server.
2. The method of claim 1, wherein said asynchronously sending the second service message to a message middleware server comprises:
And if the failure of sending the second service message is detected, the second service message is asynchronously sent to a message compensation server, and the message compensation server resends the second service message to the message middleware server until the second service message is successfully sent.
3. The method according to claim 1, wherein the method further comprises:
determining a current message sending success rate and/or a current buffer queue length in the current message sending mode;
and if the current meeting of the preset mode switching condition is determined based on the current message sending success rate and/or the current buffer queue length, performing mode switching on the current message sending mode.
4. The method of claim 1, wherein the asynchronously sending the second service message to the message middleware server by executing the asynchronously sending task via an asynchronous thread comprises:
adding the generated at least one asynchronous sending task into an asynchronous thread pool, and distributing corresponding asynchronous threads to each asynchronous sending task;
And executing the corresponding asynchronous sending task through each asynchronous thread, and asynchronously sending the second business message in the corresponding asynchronous sending task to a message middleware server.
5. The method of claim 4, wherein said concurrently executing the respective asynchronous send task by each of the asynchronous threads asynchronously sends a second traffic message in the respective asynchronous send task to a message middleware server, comprising:
Each asynchronous thread detects whether the task state of the asynchronous sending task to be executed currently is an unlocked state or not;
And if the asynchronous sending task is in the unlocked state, adding a distributed lock to the asynchronous sending task to be currently executed to update the task state to be in the locked state, and asynchronously sending a second service message in the asynchronous sending task to be currently executed to a message middleware server.
6. The method according to claim 1, wherein the method further comprises:
if the current message sending mode is detected to be a synchronous sending mode or the first service message fails to be written into the cache queue, synchronously sending the first service message to a message middleware server through a main thread;
And if the failure of the first service message sending is detected, synchronously sending the first service message to a message compensation server, and retransmitting the first service message to the message middleware server by the message compensation server until the first service message is successfully sent.
7. The method according to any one of claims 1-6, further comprising:
If the generation failure of the asynchronous sending task corresponding to the second service message is detected, or the execution failure of the asynchronous sending task is detected, the second service message is sent to a message middleware server through a main thread;
and if the failure of sending the second service message is detected, sending the second service message to a message compensation server, and retransmitting the second service message to the message middleware server by the message compensation server until the second service message is sent successfully.
8. A messaging device integrated at a service end, comprising:
The current message sending mode acquisition module is used for responding to a sending trigger instruction of the first service message and acquiring the current message sending mode of the service end by calling a preloaded message sending component;
the first service message writing module is used for writing the first service message into a cache queue based on route configuration information if the current message sending mode is an asynchronous sending mode;
The asynchronous sending task generating module is used for generating an asynchronous sending task corresponding to a second service message based on the second service message to be sent in the cache queue, wherein the second service message comprises the first service message;
and the asynchronous sending module is used for executing the asynchronous sending task through an asynchronous thread and asynchronously sending the second service message to the message middleware server.
9. A messaging system, the system comprising a service side and a message middleware server: wherein,
The service side is configured to implement the message sending method according to any one of claims 1 to 7.
10. An electronic device, the electronic device comprising:
One or more processors;
a memory for storing one or more programs;
The one or more programs, when executed by the one or more processors, cause the one or more processors to implement the messaging method of any of claims 1-7.
11. A computer readable storage medium, on which a computer program is stored, characterized in that the program, when being executed by a processor, implements a messaging method as claimed in any of claims 1-7.
CN202211564511.7A 2022-12-07 2022-12-07 Message sending method, device, equipment and storage medium Active CN115767448B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211564511.7A CN115767448B (en) 2022-12-07 2022-12-07 Message sending method, device, equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211564511.7A CN115767448B (en) 2022-12-07 2022-12-07 Message sending method, device, equipment and storage medium

Publications (2)

Publication Number Publication Date
CN115767448A CN115767448A (en) 2023-03-07
CN115767448B true CN115767448B (en) 2024-06-18

Family

ID=85344078

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211564511.7A Active CN115767448B (en) 2022-12-07 2022-12-07 Message sending method, device, equipment and storage medium

Country Status (1)

Country Link
CN (1) CN115767448B (en)

Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110069353A (en) * 2019-03-18 2019-07-30 中科恒运股份有限公司 Business asynchronous processing method and device

Family Cites Families (13)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8149850B2 (en) * 2008-02-22 2012-04-03 Qualcomm Incorporated Method and apparatus for asynchronous mediated communicaton
US9083614B2 (en) * 2012-10-15 2015-07-14 Oracle International Corporation System and method for supporting out-of-order message processing in a distributed data grid
US9092338B1 (en) * 2013-03-20 2015-07-28 Google Inc. Multi-level caching event lookup
US9942203B2 (en) * 2015-03-30 2018-04-10 International Business Machines Corporation Enhanced security when sending asynchronous messages
CN108834086B (en) * 2018-06-25 2021-05-11 平安科技(深圳)有限公司 Method and device for sending short message, computer equipment and storage medium
CN109271265B (en) * 2018-09-29 2023-09-15 平安科技(深圳)有限公司 Request processing method, device, equipment and storage medium based on message queue
CN110337075A (en) * 2019-06-28 2019-10-15 北京奇才天下科技有限公司 A kind of short message sending method, device and electronic equipment based on APP type of service
CN111104235B (en) * 2019-12-06 2022-09-09 江苏苏宁物流有限公司 Queue-based asynchronous processing method and device for service requests
CN112068973A (en) * 2020-09-09 2020-12-11 深圳乐信软件技术有限公司 Asynchronous information processing method and device of policy mode, server and storage medium
CN114253748B (en) * 2021-12-27 2023-01-31 北京宇信科技集团股份有限公司 Message processing system and message processing method
CN114338781A (en) * 2021-12-29 2022-04-12 神州数码系统集成服务有限公司 Artificial intelligence microservice control method, system, equipment, storage medium and application
CN114428692B (en) * 2022-01-25 2024-10-15 腾讯科技(深圳)有限公司 Data transmission method, data receiving method, data transmission device, data receiving device, computer equipment and storage medium
CN114675983A (en) * 2022-02-21 2022-06-28 青岛海尔科技有限公司 Business data processing method and device, storage medium and electronic equipment

Patent Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110069353A (en) * 2019-03-18 2019-07-30 中科恒运股份有限公司 Business asynchronous processing method and device

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
基于消息队列的独立通信层的设计与应用;王松磊;陈永生;;计算机应用;20101231(S2);全文 *

Also Published As

Publication number Publication date
CN115767448A (en) 2023-03-07

Similar Documents

Publication Publication Date Title
US10491560B2 (en) Message delivery in messaging networks
CN108647104B (en) Request processing method, server and computer readable storage medium
US9253287B2 (en) Speculation based approach for reliable message communications
CN110795503A (en) Multi-cluster data synchronization method and related device of distributed storage system
CN107341062B (en) Data pushing method, device, equipment and storage medium
CN110740145B (en) Message consumption method and device, storage medium and electronic equipment
CN109150662B (en) Message transmission method, distributed system, device, medium, and unmanned vehicle
CN111510480A (en) Request sending method and device and first server
CN112395097A (en) Message processing method, device, equipment and storage medium
CN111679892A (en) Distributed transaction processing method, device, equipment and medium
US20120191772A1 (en) Processing a unit of work
CN115767448B (en) Message sending method, device, equipment and storage medium
CN119003204A (en) Message queue processing method and device, electronic equipment and storage medium
CN110515749B (en) Method, device, server and storage medium for queue scheduling of information transmission
CN114095907B (en) Bluetooth connection control method, device and equipment
CN110134628B (en) Message transmission method, device, equipment and storage medium
CN114785861A (en) Service request forwarding system, method, computer equipment and storage medium
CN110798398A (en) Group message management method, device, equipment and medium
CN113296982A (en) Interface calling method and device
CN114513547B (en) Module node scheduling method and device, electronic equipment and storage medium
CN111865675B (en) Container receiving and dispatching speed limiting method, device and system
CN111008074B (en) File processing method, device, equipment and medium
CN113783830B (en) Method and apparatus for data communication
CN116939022A (en) Message pushing method, device, system, equipment and storage medium
CN117857490A (en) Message transmission method, device, equipment and 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