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

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

Info

Publication number
CN115767448A
CN115767448A CN202211564511.7A CN202211564511A CN115767448A CN 115767448 A CN115767448 A CN 115767448A CN 202211564511 A CN202211564511 A CN 202211564511A CN 115767448 A CN115767448 A CN 115767448A
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.)
Pending
Application number
CN202211564511.7A
Other languages
Chinese (zh)
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/CN115767448A/en
Publication of CN115767448A publication Critical patent/CN115767448A/en
Pending legal-status Critical Current

Links

Images

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 a service end and comprises the following steps: responding to a sending trigger instruction of the first service message, and acquiring a current message sending mode of a service end by calling a pre-loaded 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 routing configuration information; generating an asynchronous sending task corresponding to a second service message to be sent in a cache queue based on the second service message, wherein the second service message comprises a first service message; and executing the asynchronous sending task through the 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 message sending method, apparatus, device, and storage medium.
Background
With the rapid development of computer technology, the problem of strong coupling between a message producer and a message consumer can be solved through a message middleware server.
At present, after a service end generates a service message, the generated service message is synchronously sent to a message middleware server. The synchronous sending refers to that after the service end sends the service message to the message middleware server, whether the service message is sent successfully is detected, and subsequent service logic operation is executed after the service message is sent successfully.
However, in the process of implementing the present invention, the inventor finds that at least the following problems exist in the prior art:
in the process of synchronously sending the service message, if network jitter occurs or the response of the message middleware server is overtime, the message cannot be successfully sent, at the moment, the service end continuously waits 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 message sending device, equipment and a storage medium, which are used for realizing asynchronous sending of service messages, reducing the time consumption of message sending and improving the user experience.
In a first aspect, an embodiment of the present invention provides a message sending method, 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 pre-loaded 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 routing configuration information;
generating an asynchronous sending task corresponding to a second service message to be sent 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 apparatus, integrated at a service end, including:
a current message sending mode obtaining module, 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, configured to write the first service message into a cache queue based on the routing configuration information if the current message sending mode is an asynchronous sending mode;
an asynchronous sending task generating module, configured to generate an asynchronous sending task corresponding to a second service message to be sent in the cache queue, where the second service message includes 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 content of the first and second substances,
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, where the electronic device includes:
one or more processors;
a memory for storing one or more programs;
when executed by the one or more processors, cause the one or more processors to implement a messaging method as provided by any of the embodiments of the invention.
In a fifth aspect, the embodiments of the present invention further provide a computer-readable storage medium, on which a computer program is stored, where the computer program, when executed by a processor, implements the message sending method according to any embodiment of the present invention.
One embodiment of the above invention has the following advantages or benefits:
the method comprises the steps that a service end responds to a sending trigger instruction of a first service message, a pre-loaded message sending component is called to obtain a 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 a cache queue based on routing configuration information, an asynchronous sending task corresponding to a 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, therefore, the service end only needs to store the service message to be sent to the cache queue, the asynchronous sending of the service message is achieved through the cache queue, subsequent service logic operation does not need to be executed after the service message is successfully sent, the message sending efficiency is improved, the message sending time consumption is reduced, and user experience is improved. And the service end can pre-load the message sending component so as to asynchronously send the service message through the message sending component, thereby realizing modularization 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 technical solutions in the prior art, and it is obvious that the drawings in the following description are some embodiments of the present invention, and for those skilled in the art, other drawings can be obtained according to these drawings without creative efforts.
Fig. 1 is a flowchart of a message sending method according to an 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 flowchart of another message sending method according to an embodiment of the present invention;
fig. 4 is a schematic structural diagram of a message sending apparatus according to an embodiment of the present invention;
fig. 5 is a schematic structural diagram of a message transmission system according to an 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 present invention will be described in further detail with reference to the accompanying drawings and examples. It is to be understood that the specific embodiments described herein are merely illustrative of the invention and are not limiting of the invention. It should be further noted that, for the convenience of description, only some of the structures related to the present invention are shown in the drawings, not all of the structures.
Fig. 1 is a flowchart of a message sending method according to an embodiment of the present invention, which 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, which can be implemented by software and/or hardware, and is integrated on a service side. The service end can be any message production end which produces 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 calling a pre-loaded message sending component to obtain a current message sending mode of the service end.
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 triggering instruction may be an instruction for indicating that a service message needs to be transmitted currently. 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 package that the service end may load. The current message sending mode may refer to a message sending mode in which the service end is located at the current time. The message transmission mode may include an asynchronous transmission mode or a synchronous transmission mode. The asynchronous transmission mode is to transmit the service message asynchronously. The synchronous transmission mode is to transmit the service message synchronously.
Specifically, each service end that needs to send a message may preload a message sending component, such as installing a component jar package, so as to perform an asynchronous message sending operation by using the loaded message sending component, that is, the operations in steps S110 to S140, thereby implementing componentization and improving the reuse rate of different service ends. The service end may 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 a sending operation of the first service message. If the sending triggering instruction of the first service message is detected, the current message sending mode of the service end can be obtained by calling the pre-loaded message sending component.
And S120, if the current message sending mode is the asynchronous sending mode, writing the first service message into a cache queue based on the routing configuration information.
The routing configuration information may be configured in the message sending component, and is used to indicate a specified buffer queue to which each service message is written, so that the service end may route each service message to the corresponding buffer queue for writing. The buffer queue may be a preset queue for buffering messages. The buffer queue may be implemented using distributed buffers. For example, R2M and JIMDB dual caches may be employed, while the R2M main cache may be distributed in a pre-configured room, such as three different rooms, so that high availability of the cache may be guaranteed. Wherein, R2M and JIMDB are high-performance distributed cache systems constructed based on an open-source Redis cluster.
In particular, fig. 2 gives an example of a message sending procedure. As shown in fig. 2, after the service end loads the message sending component, a multi-chassis cluster for implementing a cache queue and routing information for writing into the cache queue may be configured in a spring configuration file, so as to meet personalized requirements. After configuration is completed, when the service end calls the message sending component to send the generated first service message, whether the current message sending mode of the service end is an asynchronous sending mode can be detected, if yes, the cache queue corresponding to the first service message is determined based on the mode taking mode in the routing configuration information, the first service message is written into the corresponding cache queue, after writing is successful, subsequent service logic operation can be continued, the subsequent service logic operation is not required to be executed after the service message is successfully sent, therefore, the message sending efficiency is improved, the message sending time is reduced, and further, the user experience is improved.
S130, based on a second service message to be sent in the cache queue, generating an asynchronous sending task corresponding to the second service message, wherein the second service message comprises the first service message.
The second service message may be a service message to be sent, which is buffered in the buffer queue. And writing the first service message into a buffer queue, wherein the second service message taken out of the buffer queue can be the first service message written currently or the service message written before. Each second service message corresponds to an asynchronous sending task, so that the corresponding second service message is sent by using the asynchronous sending task.
Specifically, in this embodiment, an asynchronous sending task corresponding to each second service message may be generated based on each second service message to be sent in the cache queue, and each asynchronous sending task may be sequentially executed according to the sequence of message writing.
And S140, executing the asynchronous sending task through the 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, a JMQ message middleware platform.
Specifically, the asynchronous sending task which is successfully generated may be added to the task queue, so that each asynchronous sending task is executed in sequence based on the task queue. The embodiment can create an asynchronous thread so that asynchronous sending tasks in the task queue can be executed in sequence by the asynchronous thread. And an asynchronous thread pool can be created, and a plurality of asynchronous threads in the asynchronous thread pool are utilized to concurrently execute the asynchronous sending task, so that the message sending efficiency is further improved. The asynchronous sending task is executed through the asynchronous thread, and the second service message in the asynchronous sending task can be asynchronously sent to the message middleware server, so that the asynchronous sending of the service message is realized.
Exemplarily, "asynchronously sending the second service message to the message middleware server" in S140 may include: and if the second service message is detected to be unsuccessfully sent, 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 message middleware. For example, the message compensation server may refer to the mq composer platform.
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 period, that is, network jitter or response timeout of the message middleware server occurs, it may be determined that the second service message is failed to be sent, at this time, the second service message may be automatically degraded, the second service message is asynchronously sent to the message compensation server, and the message compensation server continuously retransmits the second service message until the second service message is successfully sent to the message middleware server, so that the condition of message loss may 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, and the corresponding asynchronous sending task may also be removed from the task queue, so as to avoid multiple sending of the same service message.
According to the technical scheme of the embodiment, the service end responds to a sending trigger instruction of a first service message, a pre-loaded message sending component is called to obtain a current message sending mode of the service end, if the current message sending mode is an asynchronous sending mode, a first service message is written into a cache queue based on routing configuration information, an asynchronous sending task corresponding to a 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 to the cache queue, the cache queue is used for realizing asynchronous sending of the service message, subsequent service logic operation is not needed to be executed after the service message is successfully sent, message sending efficiency is improved, message sending time consumption is reduced, and 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 modularization and improving the multiplexing rate of different service ends.
On the basis of the above technical solution, the method may further include: if the current message sending mode is detected to be a synchronous sending mode or the first service message is failed to be written into the cache queue, the first service message is synchronously sent to the message middleware server through the main thread; if the first service message is detected to be unsuccessfully sent, 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 successfully sent.
Specifically, as shown in fig. 2, when it is detected that the current message sending mode is the synchronous sending mode, it indicates that synchronous sending of the message is currently required, and at this time, the sending instruction may be executed in the main thread to synchronously send the first service message to the message middleware server. Whether message sending success information returned by the message middleware server is received or not can be detected within preset overtime time, namely whether network jitter is met or the response of the message middleware server is overtime is detected, if the message sending success information is not received, the first service message can be determined to be failed to be sent, automatic degradation can be realized at the moment, the first service message is synchronously sent to the message compensation server, the message compensation server continuously retransmits the first service message until the first service message is successfully sent to the message middleware server, and therefore the condition of message loss can be avoided, and the successful sending of the service message is guaranteed.
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 write success information is not received within the preset timeout), it indicates that the asynchronous sending operation of the message cannot be continued currently, and at this time, the sending instruction may be executed in the main thread, and the first service message is synchronously sent to the message middleware server. Whether message sending success information returned by the message middleware server is received or not can be detected within preset overtime time, namely whether network jitter is met or the response of the message middleware server is overtime is detected, if the message sending success information is not received, the first service message can be determined to be failed to be sent, automatic degradation can be realized at the moment, the first service message is synchronously sent to the message compensation server, the message compensation server continuously retransmits the first service message until the first service message is successfully sent to the message middleware server, and therefore the condition of message loss can be avoided, and the successful sending of the service message is guaranteed.
On the basis of the above technical solution, the method may further include: if the asynchronous sending task corresponding to the second service message is detected to fail to generate or the asynchronous sending task fails to execute, the second service message is sent to the message middleware server through the main thread; and if the second service message is detected to be failed to be sent, sending the second service message to the message compensation server, and resending 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 asynchronous sending task corresponding to the second service message is failed to be generated, it indicates that the second service message cannot be sent asynchronously, and needs to be sent synchronously, at this time, the sending instruction may be executed in the main thread, and the second service message is sent synchronously to the message middleware server. Whether message sending success information returned by the message middleware server is received or not can be detected within preset overtime time, namely whether network jitter is met or the response of the message middleware server is overtime is detected, if the message sending success information is not received, the second service message can be determined to be failed to be sent, automatic degradation can be realized at the moment, the second service message is synchronously sent to the message compensation server, the message compensation server continuously retransmits the second service message until the second service message is successfully sent to the message middleware server, and therefore the condition of message loss can be avoided, and the successful sending of the service message is guaranteed.
As shown in fig. 2, when it is detected that the asynchronous sending task fails to be executed, it indicates that the second service message cannot be asynchronously sent and needs to be synchronously sent, and at this time, the sending instruction may be executed in the main thread to synchronously send the second service message to the message middleware server. Whether message sending success information returned by the message middleware server is received or not can be detected within preset overtime, namely whether network jitter occurs or the response of the message middleware server is overtime or not is detected, if the message sending success information is not received, the second service message can be determined to be failed to send, at the moment, the automatic degradation can be realized, the second service message is synchronously sent to the message compensation server, the message compensation server continuously retransmits the second service message until the second service message is successfully sent to the message middleware server, and therefore the condition of message loss can be avoided, and the successful sending of the service message is ensured.
On the basis of the above technical solution, the method may further include: determining the current message sending success rate and/or the current buffer queue length in the current message sending mode; and if the current message sending success rate and/or the current cache queue length are determined to meet the preset mode switching condition, carrying out 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 may 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 through 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, and at the moment, the daemon thread can determine that the current message sending mode meets the preset mode switching condition, and further switch the current message sending mode to another message sending mode so as to send messages in the other message sending mode, and therefore high-availability message sending can be achieved. The daemon thread can also indicate that the asynchronous sending pressure is higher when detecting that the length of the current cache queue in the asynchronous sending mode is larger than the length of the preset queue and/or the success rate of the current message sending is smaller than or equal to the preset success rate, and at the moment, the daemon thread can automatically switch the asynchronous sending mode into the synchronous sending mode so as to synchronously send the subsequent message and ensure the successful sending of the subsequent message. Or when the length of the current buffer queue in the synchronous sending mode is detected to be smaller than the length of the preset queue, the asynchronous sending pressure does not exist, and at the moment, the synchronous sending mode can be automatically switched to the asynchronous sending mode, so that the subsequent messages can be asynchronously sent, and the message sending efficiency is improved. Asynchronous high availability of sending JMQ messages can 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, and this embodiment describes in detail an execution process of at least one asynchronous sending task by using an asynchronous thread pool based on the foregoing embodiments. Wherein explanations of the same or corresponding terms as those of the above embodiments are omitted.
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 calling a pre-loaded message sending component to obtain a current message sending mode of a service end.
And S320, if the current message sending mode is the 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 a second service message to be sent in the cache queue, wherein the second service message comprises the first service message.
S340, adding the generated at least one asynchronous sending task into an asynchronous thread pool, and distributing corresponding asynchronous threads to each asynchronous sending task.
The asynchronous thread pool may be a multi-thread processing manner. The asynchronous thread pool may include a plurality of asynchronous threads.
Specifically, all the generated asynchronous sending tasks are added into 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 a long-time unprocessed asynchronous sending task, if yes, the daemon thread can preferentially distribute the asynchronous threads to the tasks which are not executed for a long time, so that the tasks are preferentially executed, and after the tasks are successfully executed, the tasks can be automatically removed.
S350, the corresponding asynchronous sending task is executed through each asynchronous thread, and the second service message in the corresponding asynchronous sending task is sent to the message middleware server asynchronously.
Specifically, each asynchronous thread in the asynchronous thread pool may concurrently execute the assigned asynchronous sending task, so as to concurrently send a plurality of second service messages to the message middleware server, thereby further improving the message sending efficiency.
Illustratively, S350 may include: each asynchronous thread detects whether the task state of the asynchronous sending task to be executed currently is a non-locking state; and if the state is the non-locking state, adding a distributed lock to the asynchronous sending task to be executed currently to update the task state to be the locking state, and asynchronously sending the second service message in the asynchronous sending task to be executed currently to the message middleware server.
Specifically, when detecting that the task state of the currently to-be-executed asynchronous sending task is in a non-locked state, each asynchronous thread indicates that no other asynchronous thread executes the asynchronous sending task, at this time, a distributed lock may be added to the asynchronous sending task, and the task state is updated from the non-locked state to a locked state, so that the asynchronous sending task is prevented from being executed by other asynchronous threads, and further, the situation that the same service message is repeatedly sent for multiple 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 used for executing the asynchronous sending task concurrently, so that the plurality of second service messages are sent to the message middleware server concurrently, and the message sending efficiency can be further improved.
The following is an embodiment of a message sending apparatus according to an embodiment of the present invention, which belongs to the same inventive concept as the message sending method according to the foregoing embodiments, and reference may be made to the above message sending method for details that are not described in detail in the embodiment of the message sending apparatus.
Fig. 4 is a schematic structural diagram of a message sending apparatus according to an embodiment of the present invention, which is applicable to a case of asynchronously sending a service message generated by a service end. As shown in fig. 4, the apparatus is integrated at a service end, and specifically includes: a current message sending mode acquiring module 410, a first service message writing module 420, an asynchronous sending task generating module 430 and an asynchronous sending module 440.
The current message sending mode acquiring module 410 is configured to acquire, in response to a sending trigger instruction of a first service message, a current message sending mode of the service end by invoking a preloaded message sending component; a first service message writing module 420, configured to write the first service message into a cache queue based on routing configuration information if the current message sending mode is an asynchronous sending mode; an asynchronous sending task generating module 430, configured to generate an asynchronous sending task corresponding to a second service message to be sent in the cache queue, where the second service message includes the first service message; the asynchronous sending module 440 is configured to execute 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 of the embodiment, the service end responds to a sending trigger instruction of a first service message, a pre-loaded message sending component is called to obtain a current message sending mode of the service end, if the current message sending mode is an asynchronous sending mode, a first service message is written into a cache queue based on routing configuration information, an asynchronous sending task corresponding to a 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, and the second service message is asynchronously sent to a message middleware server, so that the service end only needs to store the service message to be sent to the cache queue, the asynchronous sending of the service message is realized through the cache queue, subsequent service logic operation is not needed to be executed after the service message is successfully sent, 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 asynchronously send the service message through the message sending component, thereby realizing modularization and improving the multiplexing rate of different service ends.
Optionally, the asynchronous sending module 440 is specifically configured to: and if the second service message is detected to be failed to be sent, the second service message is asynchronously sent to a message compensation server, and the message compensation server is used for resending the second service message to the message middleware server until the second service message is successfully sent.
Optionally, the apparatus further comprises:
a parameter determining module, configured to determine a current message sending success rate and/or a current buffer queue length in the current message sending mode;
and the mode switching module is used for switching the mode of the current message sending mode if the current message sending success rate and/or the current cache queue length determine that the preset mode switching condition is met currently.
Optionally, the asynchronous sending module 440 includes:
the asynchronous thread distribution unit is used for 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;
and the asynchronous sending unit is used for executing the corresponding asynchronous sending task through each asynchronous thread concurrently and asynchronously sending the second service message in the corresponding asynchronous sending task 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 a non-locking state; and if the state is the non-locking state, adding a distributed lock to the asynchronous sending task to be executed currently to update the task state to be the locking state, and asynchronously sending a second service message in the asynchronous sending task to be executed currently 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 a 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 is failed to be written into the cache queue; if the first service message is detected to be failed to be sent, the first service message is synchronously sent to a message compensation server, and the message compensation server sends the first service message to the message middleware server again 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 a message middleware server through a main thread if the asynchronous sending task corresponding to the second service message is detected to fail to generate or the asynchronous sending task fails to execute; and if the second service message is detected to be unsuccessfully sent, sending the second service message to a message compensation server, and resending the second service message to the message middleware server by the message compensation server until the second service message is successfully sent.
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 module and beneficial effect of executing the message sending method.
It should be noted that, in the embodiment of the message sending apparatus, the included units and modules are merely divided according to functional logic, but are not limited to the above division as long as the corresponding functions can be implemented; in addition, specific names of the functional units are only for convenience of distinguishing from each other, and are not used for limiting 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 the message sending method according to any embodiment of the present invention.
In the message sending system in the embodiment of the disclosure, the service end 510, in response to a sending trigger instruction of a first service message, acquires a current message sending mode of the service end by calling a preloaded message sending component, and if the current message sending mode is an asynchronous sending mode, writes a first service message into the cache queue based on the routing configuration information, and generates an asynchronous sending task corresponding to a second service message based on a second service message to be sent in the cache queue, where the second service message includes the first service message, executes the asynchronous sending task through an asynchronous thread, and asynchronously sends the second service message to the message middleware server 520, so that the service end 510 only needs to store the service message to be sent to the cache queue, and uses the cache queue to implement asynchronous sending of the service message, and does not need to execute subsequent service logic operation after the service message is successfully sent, thereby improving message sending efficiency, reducing message sending time consumption, and further improving user experience. And the service end 510 may pre-load the message sending component, so as to perform asynchronous sending of the service message through the message sending component, thereby implementing 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 only an example and should not bring any limitation to the function and the scope of use of the embodiment of the present invention.
As shown in fig. 6, electronic device 12 is in the form of a general purpose computing device. The 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, and a bus 18 that couples various system components including the system memory 28 and the processing unit 16.
Bus 18 represents one or more of any of several types of bus structures, including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, a processor, or a local bus using any of a variety of bus architectures. By way of example, such architectures include, but are not limited to, 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 may 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 and write to non-removable, nonvolatile magnetic media (not shown in FIG. 6, and commonly referred to as a "hard drive"). Although not shown in FIG. 6, a magnetic disk drive for reading from and writing to a removable, nonvolatile magnetic disk (e.g., a "floppy disk") and an optical disk drive for reading from or writing to a removable, nonvolatile optical disk (e.g., a CD-ROM, DVD-ROM, or other optical media) may be provided. In these cases, each drive may be connected to bus 18 by one or more data media interfaces. System memory 28 may include at least one program product having a set (e.g., at least one) of program modules that are configured to carry out the functions of embodiments of the invention.
A program/utility 40 having a set (at least one) of program modules 42 may be stored, for example, in 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 of which examples or some combination thereof may comprise an implementation of a network environment. Program modules 42 generally carry out the functions and/or methodologies of the described embodiments of the invention.
Electronic device 12 may also communicate with one or more external devices 14 (e.g., keyboard, pointing device, display 24, etc.), with one or more devices that enable a user to interact with electronic device 12, and/or with any devices (e.g., network card, modem, etc.) that enable electronic device 12 to communicate with one or more other computing devices. Such communication may be through an input/output (I/O) interface 22. Also, the electronic device 12 may communicate with one or more networks (e.g., a Local Area Network (LAN), a Wide Area Network (WAN), and/or a public network such as the Internet) via the network adapter 20. As shown, the network adapter 20 communicates with other modules of the electronic device 12 via the bus 18. It should be understood that although not shown in the figures, other hardware and/or software modules may be used in conjunction with electronic device 12, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems, to name a few.
The processing unit 16 executes various functional applications and data processing by executing programs stored in the system memory 28, for example, to implement a message sending method provided by the embodiment of the present invention, the method includes:
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 pre-loaded 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 routing configuration information;
generating an asynchronous sending task corresponding to a second service message to be sent in the cache queue based on the second service message, 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 can understand that the processor may also implement the technical solution of the message sending method provided by any embodiment of the present invention.
The present embodiment provides a computer-readable storage medium, on which a computer program is stored, which program, when executed by a processor, implements the steps of a message sending method as provided by any embodiment of the 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 pre-loaded 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 routing configuration information;
generating an asynchronous sending task corresponding to a second service message to be sent in the cache queue based on the second service message, 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.
Computer storage media for embodiments of the invention may employ 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 any combination thereof. 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 the context of 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.
A computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, 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 thereof. 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 for aspects of the present invention may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, smalltalk, C + + or the like 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 type of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or the connection may be made to an external computer (for example, through the Internet using an Internet service provider).
It will be understood by those skilled in the art that the modules or steps of the invention described above may be implemented by a general purpose computing device, they may be centralized on a single computing device or distributed across a network of computing devices, and optionally they may be implemented by program code executable by a computing device, such that it may be stored in a memory device and executed by a computing device, or it may be separately fabricated into various integrated circuit modules, or it may be fabricated by fabricating a plurality of modules or steps thereof into a single integrated circuit module. Thus, the present invention is not limited to any specific combination of hardware and software.
It is to be noted that the foregoing description is only exemplary of the invention and that the principles of the technology may be employed. Those skilled in the art will appreciate that the present invention is not limited to the particular embodiments described herein, and that various obvious changes, rearrangements and substitutions will now be apparent to those skilled in the art without departing from the scope of the invention. Therefore, although the present invention has been described in some detail by the above embodiments, the invention is not limited to the above embodiments, and may include other equivalent embodiments without departing from the spirit of the invention, and the scope of the invention is determined by the scope of the appended claims.

Claims (11)

1. A message sending method is characterized in that, applied to a service end, the message sending method comprises the following steps:
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 pre-loaded 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 routing configuration information;
generating an asynchronous sending task corresponding to a second service message to be sent in the cache queue based on the second service message, 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 the asynchronously sending the second traffic message to a message middleware server comprises:
and if the second service message is detected to be failed to be sent, the second service message is asynchronously sent to a message compensation server, and the message compensation server is used for resending the second service message to the message middleware server until the second service message is successfully sent.
3. The method of claim 1, further comprising:
determining the current message sending success rate and/or the current buffer queue length in the current message sending mode;
and if the current message sending success rate and/or the current cache queue length are/is determined to meet the preset mode switching condition, carrying out mode switching on the current message sending mode.
4. The method of claim 1, wherein the asynchronously sending the second business message to a message middleware server by executing the asynchronously sending task via an asynchronous thread comprises:
adding at least one generated asynchronous sending task into an asynchronous thread pool, and distributing a corresponding asynchronous thread to each asynchronous sending task;
and synchronously executing the corresponding asynchronous sending task through each asynchronous thread, and asynchronously sending the second service message in the corresponding asynchronous sending task to a message middleware server.
5. The method of claim 4, wherein the asynchronously sending a second service message in the corresponding asynchronous sending task to a message middleware server by concurrently executing the corresponding asynchronous sending task by each asynchronous thread comprises:
each asynchronous thread detects whether the task state of the asynchronous sending task to be executed currently is a non-locking state;
and if the state is the non-locking state, adding a distributed lock to the asynchronous sending task to be executed currently to update the task state to be the locking state, and asynchronously sending a second service message in the asynchronous sending task to be executed currently to a message middleware server.
6. The method of claim 1, further comprising:
if the current message sending mode is detected to be a synchronous sending mode, or the first service message is failed to be written into the cache queue, the first service message is synchronously sent to a message middleware server through a main thread;
if the first service message is detected to be unsuccessfully sent, the first service message is synchronously sent to a message compensation server, and the message compensation server resends the first service message to the message middleware server until the first service message is successfully sent.
7. The method according to any one of claims 1-6, further comprising:
if the asynchronous sending task corresponding to the second service message is detected to fail to generate or the asynchronous sending task fails to execute, the second service message is sent to a message middleware server through a main thread;
if the second service message is detected to be failed to be sent, the second service message is sent to a message compensation server, and the message compensation server sends the second service message to the message middleware server again until the second service message is successfully sent.
8. A message sending apparatus, integrated in a service end, comprising:
a current message sending mode obtaining module, 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, configured to write the first service message into a cache queue based on routing configuration information if the current message sending mode is an asynchronous sending mode;
an asynchronous sending task generating module, configured to generate an asynchronous sending task corresponding to a second service message to be sent in the cache queue, where the second service message includes 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 message transmission system, characterized in that the system comprises a service end and a message middleware server: wherein the content of the first and second substances,
the service end is configured to implement the message sending method according to any one of claims 1 to 7.
10. An electronic device, characterized in that the electronic device comprises:
one or more processors;
a memory for storing one or more programs;
when executed by the one or more processors, cause the one or more processors to implement a messaging method as recited in any of claims 1-7.
11. A computer-readable storage medium, on which a computer program is stored which, when being executed by a processor, carries out the message sending method according to any one of claims 1-7.
CN202211564511.7A 2022-12-07 2022-12-07 Message sending method, device, equipment and storage medium Pending CN115767448A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211564511.7A CN115767448A (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 CN115767448A (en) 2022-12-07 2022-12-07 Message sending method, device, equipment and storage medium

Publications (1)

Publication Number Publication Date
CN115767448A true CN115767448A (en) 2023-03-07

Family

ID=85344078

Family Applications (1)

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

Country Status (1)

Country Link
CN (1) CN115767448A (en)

Citations (14)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20090213852A1 (en) * 2008-02-22 2009-08-27 Govindarajan Krishnamurthi Method and apparatus for asynchronous mediated communicaton
US20140108450A1 (en) * 2012-10-15 2014-04-17 Oracle International Corporation System and method for supporting named operations in a distributed data grid
US9092338B1 (en) * 2013-03-20 2015-07-28 Google Inc. Multi-level caching event lookup
US20160294782A1 (en) * 2015-03-30 2016-10-06 International Business Machines Corporation Enhanced security when sending asynchronous messages
CN110069353A (en) * 2019-03-18 2019-07-30 中科恒运股份有限公司 Business asynchronous processing method and device
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
WO2020000663A1 (en) * 2018-06-25 2020-01-02 平安科技(深圳)有限公司 Short message sending method and apparatus, computer device, and storage medium
WO2020062793A1 (en) * 2018-09-29 2020-04-02 平安科技(深圳)有限公司 Message queue-based request processing method, apparatus and device, and storage medium
CN111104235A (en) * 2019-12-06 2020-05-05 江苏苏宁物流有限公司 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
CN114253748A (en) * 2021-12-27 2022-03-29 北京宇信科技集团股份有限公司 Message processing system and message processing method
CN114338781A (en) * 2021-12-29 2022-04-12 神州数码系统集成服务有限公司 Artificial intelligence micro-service control method, system, equipment, storage medium and application
CN114428692A (en) * 2022-01-25 2022-05-03 腾讯科技(深圳)有限公司 Data transmitting method, data receiving method, data transmitting 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 (14)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20090213852A1 (en) * 2008-02-22 2009-08-27 Govindarajan Krishnamurthi Method and apparatus for asynchronous mediated communicaton
US20140108450A1 (en) * 2012-10-15 2014-04-17 Oracle International Corporation System and method for supporting named operations in a distributed data grid
US9092338B1 (en) * 2013-03-20 2015-07-28 Google Inc. Multi-level caching event lookup
US20160294782A1 (en) * 2015-03-30 2016-10-06 International Business Machines Corporation Enhanced security when sending asynchronous messages
WO2020000663A1 (en) * 2018-06-25 2020-01-02 平安科技(深圳)有限公司 Short message sending method and apparatus, computer device, and storage medium
WO2020062793A1 (en) * 2018-09-29 2020-04-02 平安科技(深圳)有限公司 Message queue-based request processing method, apparatus and device, and storage medium
CN110069353A (en) * 2019-03-18 2019-07-30 中科恒运股份有限公司 Business asynchronous processing method and device
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
CN111104235A (en) * 2019-12-06 2020-05-05 江苏苏宁物流有限公司 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
CN114253748A (en) * 2021-12-27 2022-03-29 北京宇信科技集团股份有限公司 Message processing system and message processing method
CN114338781A (en) * 2021-12-29 2022-04-12 神州数码系统集成服务有限公司 Artificial intelligence micro-service control method, system, equipment, storage medium and application
CN114428692A (en) * 2022-01-25 2022-05-03 腾讯科技(深圳)有限公司 Data transmitting method, data receiving method, data transmitting 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

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
王松磊;陈永生;: "基于消息队列的独立通信层的设计与应用", 计算机应用, no. 2, 31 December 2010 (2010-12-31) *

Similar Documents

Publication Publication Date Title
US10491560B2 (en) Message delivery in messaging networks
US8799906B2 (en) Processing a batched unit of work
US10592317B2 (en) Timeout processing for messages
CN110717132A (en) Data collection method and pushing method for full-link monitoring system and related equipment
CN111858007A (en) Task scheduling method and device based on message middleware
KR20210040866A (en) File resource processing method and apparatus, device and medium
CN115904761A (en) System on chip, vehicle and video processing unit virtualization method
CN110881224B (en) Network long connection method, device, equipment and storage medium
CN112395097A (en) Message processing method, device, equipment and storage medium
US7197533B2 (en) Non-persistent service support in transactional application support environments
CN111679892A (en) Distributed transaction processing method, device, equipment and medium
CN109445966B (en) Event processing method, device, medium and computing equipment
CN115767448A (en) Message sending method, device, equipment and storage medium
CN111510480A (en) Request sending method and device and first server
CN113946376A (en) Load adjustment method and device, electronic equipment and storage medium
CN110798398A (en) Group message management method, device, equipment and medium
CN112217718A (en) Service processing method, device, equipment and storage medium
CN112817788A (en) Task abnormity warning method, device, server and storage medium
CN112463514A (en) Monitoring method and device for distributed cache cluster
CN114513547B (en) Module node scheduling method and device, electronic equipment and storage medium
CN117573380B (en) Virtual address allocation method and device
CN117544512A (en) Data transmission method, device, system, equipment and storage medium
CN116939022A (en) Message pushing method, device, system, equipment and storage medium
CN114356603A (en) Message processing method and device, electronic equipment and storage medium
CN117097784A (en) Message theme processing method, device, system, server 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