Message transmission method, device, electronic device and storage medium
After the business execution is successful, two threads are used to process message storage and state storage respectively, the problem of affecting business execution during message transmission is solved, and the stability of business execution and the independence of message transmission is achieved.
Patent Information
- Application Number
- CN202211149648.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-09-21
- Publication Date
- 2025-02-11
- Estimated Expiration
- 2042-09-21
AI Technical Summary
In the prior art, if the message queue fails or takes too long during message transmission, it will cause the main service execution of the service initiator to fail or the performance will be degraded.
After the first thread successfully executes the service, the message corresponding to the service is obtained, and the message is stored through the first thread to the first repository, and the message is sent to the message middleware through the second thread. After receiving feedback from the message middleware, the message status is determined based on the feedback, and the status is stored to the second repository through the second thread. If the message middleware successfully stores the message, the message is sent to the message receiving end through the message middleware.
Relative independence between service execution and message transmission is realized. Even if there are problems in the message transmission process, it will not affect the stability of service execution, and avoid service execution failure or performance degradation caused by message transmission exceptions.
Smart Images

Figure CN115562884B_ABST
Abstract
Description
Technical Field
[0001] The present application belongs to the field of business services, and specifically relates to a message transmission method, device, electronic device and storage medium. Background Art
[0002] In the existing business service message transmission process, in order to achieve message consistency between the business initiator (message sender) and the business participant (message receiver), the execution of the main business and the message queue sending are usually placed in one transaction. That is, when executing the transaction, it is necessary not only to execute the main business but also to send messages related to the main business to the message middleware, and then send the messages related to the main business to the business participants through the message middleware. In this way, the messages between the business initiator and the message receiver are consistent, and the transaction participants can also execute the main business after receiving the messages related to the main business.
[0003] However, during the above message transmission process, if the sending message queue (sending the main business related message to the message middleware) fails or the sending time is too long, the main business execution of the business initiator will fail or the performance will be reduced. Summary of the invention
[0004] The embodiments of the present application provide a message transmission method, device, electronic device and storage medium, which can solve the problem that the message transmission process affects the main business execution process.
[0005] In a first aspect, an embodiment of the present application provides a message transmission method, the method comprising: when a first business is successfully executed through a first thread, obtaining a first message corresponding to the first business; storing the first message in a first storage repository through the first thread; sending the first message to a message middleware through a second thread; if message feedback sent by the message middleware is received, determining status information corresponding to the first message based on the message feedback, and storing the status information in a second storage repository through the second thread, wherein the message feedback is used to indicate whether the message middleware has successfully stored the first message; if the message feedback indicates that the message middleware has successfully stored the first message, sending the first message to a message receiving end through the message middleware, so that the message receiving end executes the first business according to the first message.
[0006] In a second aspect, an embodiment of the present application provides a message transmission device, which includes: an execution module, which is used to obtain a first message corresponding to a first business when a first business is successfully executed through a first thread; a first storage module, which is used to store the first message in a first repository through the first thread; a first sending module, which is used to send the first message to a message middleware through a second thread; a second storage module, which is used to determine status information corresponding to the first message based on the message feedback if a message feedback sent by the message middleware is received, and store the status information in a second repository through the second thread, wherein the message feedback is used to indicate whether the message middleware has successfully stored the first message; and a second sending module, which is used to send the first message to a message receiving end through the message middleware if the message feedback indicates that the message middleware has successfully stored the first message, so that the message receiving end executes the first business according to the first message.
[0007] In a third aspect, an embodiment of the present application provides an electronic device, which includes a processor, a memory, and a program or instruction stored in the memory and executable on the processor, wherein the program or instruction, when executed by the processor, implements the steps of the method described in the first aspect.
[0008] In a fourth aspect, an embodiment of the present application provides a readable storage medium, on which a program or instruction is stored, and when the program or instruction is executed by a processor, the steps of the method described in the first aspect are implemented.
[0009] In an embodiment of the present application, when the first business is successfully executed through the first thread, a first message corresponding to the first business is obtained; the first message is stored in the first repository through the first thread; the first message is sent to the message middleware for storage through the second thread; if a message feedback sent by the message middleware is received, the status information corresponding to the first message is determined according to the message feedback, and the status information is stored in the second repository through the second thread, wherein the message feedback is used to indicate whether the message middleware has successfully stored the first message; if the message feedback indicates that the message middleware has successfully stored the first message, the first message is sent to the message receiving end through the message middleware, so that the message receiving end executes the first business according to the first message, so that the first message of the execution of the first business is completed. The thread and the second thread that sends the first message are different threads. In this way, the process of executing the first business and the process of transmitting the first message are relatively independent. Even if a problem occurs during the transmission of the first message, it will not affect the execution of the first business, which can improve the execution stability of the first business and avoid the problem that the first business execution fails or affects the performance due to problems in the transmission process of the first message. The first message is stored in the first repository through the first thread, and the status information corresponding to the first message is stored in the second repository through the second thread. The two repositories are controlled by two threads, which avoids the problem of using the same thread to operate two repositories, which may easily lead to problems such as locking the repository or locking the table, thereby improving the stability of business execution and the stability of the message transmission process. BRIEF DESCRIPTION OF THE DRAWINGS
[0010] Figure 1 It is a flowchart of a message transmission method provided in an embodiment of the present application;
[0011] Figure 2 This is a schematic diagram of a message transmission process provided by an embodiment of the present application;
[0012] Figure 3 It is a structural diagram of a message transmission device provided in an embodiment of the present application;
[0013] Figure 4 It is a structural schematic diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0014] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0015] The terms "first", "second", etc. in the specification and claims of the present application are used to distinguish similar objects, and are not used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable under appropriate circumstances, so that the embodiments of the present application can be implemented in an order other than those illustrated or described here, and the objects distinguished by "first", "second", etc. are generally of one type, and the number of objects is not limited. For example, the first object can be one or more. In addition, "and / or" in the specification and claims represents at least one of the connected objects, and the character " / " generally indicates that the objects associated with each other are in an "or" relationship.
[0016] The message transmission method, device, electronic device and storage medium provided in the embodiments of the present application are described in detail below with reference to the accompanying drawings through specific embodiments and their application scenarios.
[0017] Figure 1 A message transmission method provided by an embodiment of the present invention is shown. The method can be executed by an electronic device, and the electronic device may include: a server and / or a message initiating end device, wherein the message initiating end device may be a service initiating end device or a service providing end device, etc. In other words, the method can be executed by software or hardware installed in the electronic device, and the method includes the following steps:
[0018] Step 102: When the first service is successfully executed through the first thread, a first message corresponding to the first service is obtained.
[0019] Specifically, the basic principle of the final message consistency between the electronic device and the message receiving end is that the electronic device sends a message after successfully executing the local service. After the message receiving end receives the message sent by the electronic device, it executes the same service as the local service executed by the electronic device according to the message.
[0020] In an embodiment of the present application, the electronic device can execute a first service through a preset first thread. The first service can be a scheduled service or a local service in the background of the electronic device. After the first service is successfully executed, a first message corresponding to the first service is obtained.
[0021] Step 104: Store the first message in a first storage repository through a first thread.
[0022] Specifically, in an electronic device, the execution of a first business and the storage of a first message can be executed in the same transaction, that is, after the first business is successfully executed through a first thread, the first message can be stored in a preset first repository through the first thread. The operation of storing the first message in the first repository can be an insert operation, that is, inserting the first message into the first repository for storage. The first repository can be a storage database or a data interface table. The first repository can be set according to actual needs, and the first repository is not specifically limited herein.
[0023] Step 106: Send the first message to the message middleware through the second thread.
[0024] Specifically, after obtaining the first message corresponding to the first business, the electronic device can send the first message to the message middleware through a preset message transmission network, and the first message can be stored in the message middleware. In the message transmission method provided in the embodiment of the present application, the message middleware can be RocketMQ message middleware. It should be understood that the message middleware here can also be other message middleware, that is, the message middleware can be set as needed, and no specific limitation is made here.
[0025] Step 108: If a message feedback sent by the message middleware is received, the state information corresponding to the first message is determined according to the message feedback, and the state information is stored in a second storage repository through a second thread.
[0026] Specifically, after performing a storage operation on the first message, the message middleware may issue a message feedback, and the message feedback is used to indicate whether the message middleware successfully stores the first message. The electronic device may receive the message feedback and determine the status information corresponding to the first message based on the message feedback. For example, if the feedback message indicates that the message middleware successfully stores the first message, the status information corresponding to the first message may be that it is successfully sent to the message middleware; if the feedback message indicates that the message middleware fails to store the first message, the status information corresponding to the first message may be that it fails to be sent to the message middleware, etc. Here, the status information corresponding to the first message is not specifically limited.
[0027] After obtaining the status information corresponding to the first message, the status information can be stored in the second repository through the second thread. The operation of storing the status information in the second repository can be an insert operation, that is, inserting the status information into the second repository for storage. The second repository can be a storage database or a data interface table. The second repository can be set according to actual needs, and the second repository is not specifically limited here.
[0028] Step 110: If the message feedback indicates that the message middleware successfully stores the first message, the message middleware sends the first message to a message receiving end so that the message receiving end executes the first service according to the first message.
[0029] Specifically, if the message feedback indicates that the message middleware successfully stores the first message, then the first message can be sent to the message receiving end through the message middleware to achieve message consistency between the electronic device and the message receiving end, so that the message receiving end executes the first business according to the first message. In the message receiving end, the first message can be subscribed to (received) from the message middleware through a preset message transmission network, and the reception of the first message, the execution of the first business according to the first message, and the feedback of the message reception result can be placed in the same thread or the same transaction for execution, which can ensure the consistency of receiving the first message and executing the first business. Under normal circumstances, the message receiving end will only feedback the message reception result if the first business is successfully executed. However, if the business processing flow is long, in order to ensure efficiency, the message reception result can also be fed back immediately after receiving the first message, and the subsequent asynchronous processing executes the process of the first business. It should be understood that the message receiving end needs to ensure the idempotence of the first message processing.
[0030] In an embodiment of the present application, when the first business is successfully executed through the first thread, a first message corresponding to the first business is obtained; the first message is stored in the first repository through the first thread; the first message is sent to the message middleware for storage through the second thread; if a message feedback sent by the message middleware is received, the status information corresponding to the first message is determined according to the message feedback, and the status information is stored in the second repository through the second thread, wherein the message feedback is used to indicate whether the message middleware has successfully stored the first message; if the message feedback indicates that the message middleware has successfully stored the first message, the first message is sent to the message receiving end through the message middleware, so that the message receiving end executes the first business according to the first message, so that the first message of the execution of the first business is completed. The thread and the second thread that sends the first message are different threads. In this way, the process of executing the first business and the process of transmitting the first message are relatively independent. Even if a problem occurs during the transmission of the first message, it will not affect the execution of the first business, which can improve the execution stability of the first business and avoid the problem that the first business execution fails or affects the performance due to problems in the transmission process of the first message. The first message is stored in the first repository through the first thread, and the status information corresponding to the first message is stored in the second repository through the second thread. The two repositories are controlled by two threads, which avoids the problem of using the same thread to operate two repositories, which may easily lead to problems such as locking the repository or locking the table, thereby improving the stability of business execution and the stability of the message transmission process.
[0031] In one implementation, determining the state information corresponding to the first message according to the message feedback includes:
[0032] If the message feedback indicates that the message middleware successfully stores the first message, the status information corresponding to the first message is the first status information, and the first status information indicates that the first message is sent successfully; if the message feedback indicates that the message middleware fails to store the first message, the status information corresponding to the first message is the second status information, and the second status information indicates that the first message is sent unsuccessfully.
[0033] Specifically, if the message middleware successfully stores the first message, the electronic device can receive message feedback indicating that the message middleware successfully stores the first message. At this time, it can be determined that the status information corresponding to the first message is the first status information, and the first status information indicates that the first message is successfully sent to the message middleware, that is, the electronic device sends the first message to the message middleware for storage successfully. If the message middleware fails to store the first message, the electronic device can receive message feedback indicating that the message middleware fails to store the first message. At this time, it can be determined that the status information corresponding to the first message is the second status information, and the second status information indicates that the first message is failed to be sent to the message middleware. Of course, no matter whether the status information corresponding to the first message obtained is the first status information or the second status information, the status information corresponding to the first message can be stored in the second storage repository through the second thread.
[0034] In this way, if the message feedback indicates that the message middleware successfully stores the first message, the status information corresponding to the first message is the first status information, and the first status information indicates that the first message is sent successfully; if the message feedback indicates that the message middleware fails to store the first message, the status information corresponding to the first message is the second status information, and the second status information indicates that the first message fails to be sent. It is possible to determine whether the first message is successfully sent to the message middleware for storage based on the message feedback, and determine the status information corresponding to the first message based on the feedback message, thereby enabling the recording of the status information corresponding to the first message.
[0035] In one implementation, sending the first message to a message receiving end through the message middleware includes:
[0036] The second message is sent to the message middleware through the second thread, so that the message middleware sends the first message to the message receiving end after receiving the second message, wherein the second message is used to indicate that the first state information is stored successfully.
[0037] If the message feedback indicates that the message middleware successfully stores the first message, then the state information corresponding to the first message is the first state information. At this time, the first state information corresponding to the first message can be stored in the first repository through the second thread. If the first state information is successfully stored in the first repository, the electronic device will send a second message to the message middleware. After receiving the second message, the message middleware will send the first message to the message receiving end according to the second message. The second message is used to indicate that the first state information is successfully stored. That is, after determining that the electronic device successfully stores the first state information in the first repository through the second thread, the message middleware transmits the first message to the message receiving end. If the electronic device does not send the second message, the message middleware can query from the electronic device whether the first state information corresponding to the first message is successfully stored in the first repository, and determine whether to transmit the first message to the message receiving end according to the query result. That is, if it is queried that the electronic device successfully stores the first state information in the first repository, the first message is transmitted to the message receiving end. If it is queried that the electronic device fails to store the first state information in the first repository, the first message is prohibited from being transmitted to the message receiving end.
[0038] In this way, the second message is sent to the message middleware through the second thread, so that the message middleware sends the first message to the message receiving end after receiving the second message, wherein the second message is used to represent the successful storage of the first status information, and can send the second message to the message middleware when the message middleware successfully stores the first message and the electronic device successfully stores the status information corresponding to the first message in the second storage repository, so that the message middleware can send the first message to the message receiving end, which can solve the atomicity problem of message transmission and business execution in the electronic device, and avoid the problem of inconsistency between the electronic device and the message receiving end caused by abnormal transmission of the first message, and the second storage repository is operated by the second thread, so that the operation of the first storage repository and the operation of the second storage are no longer in the same thread, avoiding problems such as locking the library and locking the table.
[0039] In one implementation, the method further includes:
[0040] If the message feedback indicates that the message middleware fails to store the first message, the reason why the message middleware fails to store the first message and the time when the first message was sent are stored in the second repository; the first message is obtained from the first repository and resent until the message middleware successfully stores the first message.
[0041] Specifically, if the message feedback indicates that the message middleware fails to store the first message, that is, the electronic device fails to send the first message to the message middleware for storage, then the process data of the electronic device sending the first message to the message middleware for storage can be obtained, and the reason for the failure of the message middleware to store the first message can be analyzed based on the process data, and the time of sending the first message can be obtained. The time of sending the first message and the reason for the failure of the message middleware to store the first message are stored in the second repository. It should be understood that in order to more accurately solve the problem of the failure of the message middleware to store the first message, other data that affects the message middleware to store the first message can also be recorded in the second repository.
[0042] If the electronic device fails to send the first message to the message middleware, the electronic device can obtain the first message from the first repository and resend it until the first message is successfully sent to the message middleware. If the first message still fails after sending the first message to the message middleware a predetermined number of times, the electronic device can send an exception of the first message to the message middleware to alert the administrator, so that the administrator can handle the message exception according to the second repository.
[0043] In this way, if the message feedback indicates that the message middleware fails to store the first message, the reason for the failure of the message middleware to store the first message and the time of sending the first message are stored in the second repository; the first message is obtained from the first repository and resent until the message middleware successfully stores the first message. This can prompt the message middleware to successfully store the first message by resending the first message, and when multiple resendings still fail, the administrator can handle the exception based on the information in the second repository, which can effectively solve the problem of failure in sending the first message to the message middleware for storage and improve the stability of the message transmission process.
[0044] In one implementation, the method further includes: if the status information corresponding to the first message is the first status information, and storing the first status information fails, issuing an alarm of failure to store the first status information; sending a third message to the message middleware through the second thread so that the message middleware deletes the first message, wherein the third message is used to characterize the failure to store the first status information.
[0045] Specifically, if the message feedback received from the message middleware indicates that the message middleware successfully stores the first message, that is, the status information corresponding to the first message is the first status information, then the first status information corresponding to the first message can be stored in the first storage repository. If the storage of the first status information fails, a third message can be sent to the message middleware through the second thread. After receiving the third message, the message middleware can delete the first message, wherein the third message is used to indicate that the electronic device fails to store the first status information. It should be understood that in the event of a failure to store the first status information, the cause of the failure to store the first status information can also be analyzed and an alarm for the failure to store the first status information can be issued, so that the management personnel can handle the exception of the failure to store the first status information corresponding to the first message.
[0046] In this way, if the status information corresponding to the first message is the first status information, and the storage of the first status information fails, an alarm of the failure to store the first status information is issued; the third message is sent to the message middleware through the second thread, so that the message middleware deletes the first message, wherein the third message is used to characterize the failure to store the first status information, so that the management personnel can handle the abnormality of storing the first status information, and, in the case that the electronic device fails to store the first status corresponding to the first message, the message middleware deletes the first message, which can prevent the first message from being stored in the message middleware, resulting in a waste of message middleware resources, thereby improving resource utilization, and sending the third message to the message middleware through the second thread prevents the transmission of the third message from affecting the business execution in the electronic device.
[0047] In one implementation, in one implementation, the method further includes:
[0048] If it is detected that the first message is inconsistent with the fourth message received by the message receiving end, a difference message between the first message and the fourth message is sent to the message receiving end through the second thread.
[0049] Specifically, a first repository may also be pre-set in the message receiving end for storing received messages. To ensure that the messages between the electronic device and the message receiving end are consistent, a third-party reconciliation system may periodically verify the first message sent by the electronic device and the fourth message received by the message receiving end according to verification rules. The verification rules may be pre-set according to requirements, that is, the third-party reconciliation system obtains the first message from the first repository of the electronic device, obtains the received fourth message from the first repository of the message receiving end, and verifies them according to preset verification rules. If the verification result is that the first message and the fourth message are inconsistent, the difference message between the first message and the fourth message may be obtained. The electronic device may obtain the verification result and the difference message between the first message and the fourth message, and send the difference message between the first message and the fourth message to the message receiving end through the second thread for message compensation. If the message compensation fails for multiple times, the verification result and the message compensation failure result may be sent to the management personnel so that the management personnel can handle the exception.
[0050] In this way, if it is detected that the first message is inconsistent with the fourth message received by the message receiving end, the difference message between the first message and the fourth message is sent to the message receiving end through the second thread, and message compensation can be performed when the first message sent by the electronic device is inconsistent with the fourth message received by the message receiving end, thereby ensuring the message consistency between the electronic device and the message receiving end, and sending the difference message to the message receiving end through the second thread prevents the transmission of the difference message from affecting the business execution in the electronic device.
[0051] Below, a message transmission method provided by an embodiment of the present application is described in detail by using an example. Figure 2 is a schematic diagram of a message transmission process provided by an embodiment of the present application, such as Figure 2 As shown, the message transmission process includes the following steps:
[0052] 1. Send the first message.
[0053] Specifically, the electronic device can execute the first service through the preset first thread, and the first service can be a scheduled service or a local service in the background of the electronic device, etc. After the first service is successfully executed, the first message corresponding to the first service is obtained, and the execution of the first service and the storage of the first message can be placed in the same transaction for execution, that is, after the first service is successfully executed through the first thread, the first message can be stored in the preset first repository through the first thread, and the operation of storing the first message in the first repository can be an insert operation, that is, inserting the first message into the first repository for storage, the first repository can be a storage database or a data interface table, the first repository can be set according to actual needs, and the first repository is not specifically limited here, the message middleware can be RocketMQ message middleware, it should be understood that the message middleware here can also be other message middleware, that is, the message middleware can be set according to needs, and is not specifically limited here. .
[0054] 2. Receive message feedback.
[0055] Specifically, after receiving the first message, the message middleware can store the first message. After storing the first message, the message middleware can issue a message feedback, which is used to indicate whether the message middleware successfully stores the first message. The electronic device can receive the message feedback and determine the status information corresponding to the first message based on the message feedback.
[0056] 3. Store the status information corresponding to the first message.
[0057] Specifically, if the message middleware successfully stores the first message, the electronic device can receive message feedback indicating that the message middleware successfully stores the first message. At this time, it can be determined that the status information corresponding to the first message is the first status information, and the first status information indicates that the first message is successfully sent to the message middleware, that is, the electronic device sends the first message to the message middleware for storage successfully. If the message middleware fails to store the first message, the electronic device can receive message feedback indicating that the message middleware fails to store the first message. At this time, it can be determined that the status information corresponding to the first message is the second status information, and the second status information indicates that the first message is unsuccessful. Of course, no matter whether the status information corresponding to the first message obtained is the first status information or the second status information, the status information corresponding to the first message can be stored in the second repository through the second thread. The operation of storing the status information in the second repository can be an insert operation, that is, inserting the status information into the second repository for storage. The second repository can be a storage database or a data interface table. The second repository can be set according to actual needs, and the second repository is not specifically limited here.
[0058] 4. Send the second message / third message.
[0059] Specifically, if the message feedback indicates that the message middleware successfully stores the first message, then the status information corresponding to the first message is the first status information. At this time, the first status information corresponding to the first message can be stored in the first repository through the second thread. If the first status information is successfully stored in the first repository, the electronic device will send a second message to the message middleware. After receiving the second message, the message middleware will send the first message to the message receiving end according to the second message. The second message is used to indicate that the storage of the first status information is successful. That is, after determining that the electronic device successfully stores the first status information in the first repository through the second thread, the message middleware transmits the first message to the message receiving end.
[0060] Specifically, if the message feedback indicates that the message middleware fails to store the first message, that is, the electronic device fails to send the first message to the message middleware for storage, then the process data of the electronic device sending the first message to the message middleware for storage can be obtained, and the reason for the failure of the message middleware to store the first message can be analyzed based on the process data, and the time of sending the first message can be obtained. The time of sending the first message and the reason for the failure of the message middleware to store the first message are stored in the second repository. It should be understood that in order to more accurately solve the problem of the failure of the message middleware to store the first message, other data that affects the message middleware to store the first message can also be recorded in the second repository.
[0061] If the electronic device fails to send the first message to the message middleware, the electronic device can obtain the first message from the first repository and resend it until the first message is successfully sent to the message middleware. If the first message still fails after sending the first message to the message middleware a predetermined number of times, the electronic device can send an exception of the first message to the message middleware to alert the administrator, so that the administrator can handle the message exception according to the second repository.
[0062] 5. Check the transaction execution status.
[0063] If the electronic device does not send the second message, the message middleware can query from the electronic device whether the first status information corresponding to the first message is successfully stored in the first repository, and determine whether to transmit the first message to the message receiving end based on the query result. That is, if the query finds that the electronic device successfully stores the first status information in the first repository, the first message is transmitted to the message receiving end; if the query finds that the electronic device fails to store the first status information in the first repository, the first message is prohibited from being transmitted to the message receiving end.
[0064] 6. Transmit the first message.
[0065] Specifically, if the first state information is successfully stored in the first storage repository, the electronic device will send a second message to the message middleware, and after receiving the second message, the message middleware will send the first message to the message receiving end according to the second message.
[0066] 7. Feedback message receiving result.
[0067] At the message receiving end, the first message can be subscribed to (received) from the message middleware through a preset message transmission network. The receiving of the first message, the execution of the first business according to the first message, and the feedback of the message receiving result can be placed in the same thread or the same transaction for execution, which can ensure the consistency of receiving the first message and executing the first business. Normally, the message receiving end will only feedback the message receiving result if the first business is executed successfully. However, if the business processing flow is long, in order to ensure efficiency, the message receiving result can be fed back immediately after receiving the first message, and the subsequent asynchronous processing executes the process of the first business. It should be understood that the message receiving end needs to ensure the idempotence of the first message processing.
[0068] 8. Perform message reconciliation.
[0069] Specifically, a first repository may also be pre-set in the message receiving end for storing received messages. To ensure that the messages between the electronic device and the message receiving end are consistent, a third-party reconciliation system may periodically verify the first message sent by the electronic device and the fourth message received by the message receiving end according to verification rules. The verification rules may be pre-set according to requirements, that is, the third-party reconciliation system obtains the first message from the first repository of the electronic device, obtains the received fourth message from the first repository of the message receiving end, and verifies them according to preset verification rules. If the verification result is that the first message and the fourth message are inconsistent, the difference message between the first message and the fourth message may be obtained. The electronic device may obtain the verification result and the difference message between the first message and the fourth message, and send the difference message between the first message and the fourth message to the message receiving end through the second thread for message compensation. If the message compensation fails for multiple times, the verification result and the message compensation failure result may be sent to the management personnel so that the management personnel can handle the exception.
[0070] Figure 3 is a schematic diagram of the structure of a message transmission device according to an embodiment of the present invention. Figure 3 As shown, the message transmission device 300 includes: an execution module 310, a first storage module 320, a first sending module 330, a second storage module 340 and a second sending module 350.
[0071] An execution module 310 is used to obtain a first message corresponding to a first business when the first business is successfully executed through a first thread; a first storage module 320 is used to store the first message in a first repository through the first thread; a first sending module 330 is used to send the first message to a message middleware through a second thread; a second storage module 340 is used to determine, if a message feedback sent by the message middleware is received, state information corresponding to the first message based on the message feedback, and store the state information in a second repository through a second thread, wherein the message feedback is used to indicate whether the message middleware has successfully stored the first message; a second sending module 350 is used to send the first message to a message receiving end through the message middleware if the message feedback indicates that the message middleware has successfully stored the first message, so that the message receiving end executes the first business according to the first message.
[0072] In one implementation, the second storage module 340 is used to, if the message feedback indicates that the message middleware successfully stores the first message, then the status information corresponding to the first message is first status information, and the first status information indicates that the first message is sent successfully; if the message feedback indicates that the message middleware fails to store the first message, then the status information corresponding to the first message is second status information, and the second status information indicates that the sending of the first message fails.
[0073] In one implementation, the second sending module 350 is used to send a second message to the message middleware through the second thread, so that the message middleware sends the first message to the message receiving end after receiving the second message, wherein the second message is used to indicate that the first status information is successfully stored.
[0074] In one implementation, the second storage module 340 is also used to store the reason why the message middleware failed to store the first message and the time when the first message was sent in the second repository if the message feedback indicates that the message middleware failed to store the first message; and obtain the first message from the first repository for resending until the message middleware successfully stores the first message.
[0075] In one implementation, the second storage module 340 is also used to issue an alarm of failure to store the first status information if the status information corresponding to the first message is the first status information and the storage of the first status information fails; and send a third message to the message middleware through the second thread so that the message middleware deletes the first message, wherein the third message is used to characterize the failure to store the first status information.
[0076] In one implementation, the second sending module 350 is further configured to send a difference message between the first message and the fourth message to the message receiving end through the second thread if it is detected that the first message is inconsistent with a fourth message received by the message receiving end.
[0077] In one implementation, the first message includes a field of the first service and data of the first service.
[0078] The transmission device of the message in the embodiment of the present application can be a device electronic device, or a component in a terminal electronic device, such as an integrated circuit or a chip. The electronic device can be a terminal, or it can be other devices other than a terminal. The device can be a mobile electronic device or a non-mobile electronic device. Exemplarily, the mobile electronic device can be a mobile phone, a tablet computer, a laptop computer, a PDA, a car electronic device, a mobile Internet device (Mobile Internet Device, MID), an augmented reality (Augmented Reality, AR) / virtual reality (Virtual Reality, VR) device, a robot, a wearable device, an ultra-mobile personal computer (Ultra-mobile Personal Computer, UMPC), a netbook or a personal digital assistant (Personal Digital Assistant, PDA), etc., and the non-mobile electronic device can also be a server, a network attached storage (Network Attached Storage, NAS), a personal computer (Personal Computer, PC), a television (Television, TV), a teller machine or a self-service machine, etc., which is not specifically limited in the embodiment of the present application.
[0079] The message transmission device in the embodiment of the present application may be a device having an operating system. The operating system may be an Android operating system, an iOS operating system, or other possible operating systems, which are not specifically limited in the embodiment of the present application.
[0080] The message transmission device provided in the embodiment of the present application can realize Figure 1 To avoid repetition, the various processes implemented by the method embodiment are not described here.
[0081] Alternatively, if Figure 4As shown, an embodiment of the present application further provides an electronic device 400, including a processor 401 and a memory 402, wherein the memory 402 stores a program or instruction that can be executed on the processor 401, and when the program or instruction is executed by the processor 401, it is implemented as follows: when a first business is successfully executed through a first thread, a first message corresponding to the first business is obtained; the first message is stored in a first repository through the first thread; the first message is sent to a message middleware through a second thread; if a message feedback sent by the message middleware is received, the status information corresponding to the first message is determined according to the message feedback, and the status information is stored in a second repository through the second thread, wherein the message feedback is used to indicate whether the message middleware has successfully stored the first message; if the message feedback indicates that the message middleware has successfully stored the first message, the first message is sent to a message receiving end through the message middleware, so that the message receiving end executes the first business according to the first message.
[0082] In one implementation, if the message feedback indicates that the message middleware successfully stores the first message, then the status information corresponding to the first message is first status information, and the first status information indicates that the first message is sent successfully; if the message feedback indicates that the message middleware fails to store the first message, then the status information corresponding to the first message is second status information, and the second status information indicates that the first message is sent unsuccessfully.
[0083] In one implementation, the second message is sent to the message middleware through the second thread, so that the message middleware sends the first message to the message receiving end after receiving the second message, wherein the second message is used to indicate that the first state information is successfully stored.
[0084] In one implementation, the method further includes: if the message feedback indicates that the message middleware fails to store the first message, storing the reason for the failure of the message middleware to store the first message and the time of sending the first message in the second repository; obtaining the first message from the first repository and resending it until the message middleware successfully stores the first message.
[0085] In one implementation, the method further includes: if the status information corresponding to the first message is the first status information, and storing the first status information fails, issuing an alarm of failure to store the first status information; sending a third message to the message middleware through the second thread so that the message middleware deletes the first message, wherein the third message is used to characterize the failure to store the first status information.
[0086] In one implementation, the method further includes: if it is detected that the first message is inconsistent with a fourth message received by the message receiving end, sending a difference message between the first message and the fourth message to the message receiving end through the second thread.
[0087] In one implementation, the first message includes a field of the first service and data of the first service.
[0088] The specific execution steps can refer to the various steps of the above-mentioned message transmission method embodiment, and can achieve the same technical effect. To avoid repetition, they will not be repeated here.
[0089] It should be noted that the electronic devices in the embodiments of the present application include: servers, terminals, or other devices except terminals.
[0090] The above electronic device structure does not constitute a limitation on the electronic device. The electronic device may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently. For example, the input unit may include a graphics processing unit (GPU) and a microphone, and the display unit may be configured with a display panel in the form of a liquid crystal display, an organic light-emitting diode, etc. The user input unit includes a touch panel and at least one of other input devices. The touch panel is also called a touch screen. Other input devices may include, but are not limited to, a physical keyboard, function keys (such as volume control buttons, switch buttons, etc.), a trackball, a mouse, and a joystick, which will not be repeated here.
[0091] The memory can be used to store software programs and various data. The memory may mainly include a first storage area for storing programs or instructions and a second storage area for storing data, wherein the first storage area may store an operating system, an application program or instructions required for at least one function (such as a sound playback function, an image playback function, etc.), etc. In addition, the memory may include a volatile memory or a non-volatile memory, or the memory may include both volatile and non-volatile memories. Among them, the non-volatile memory may be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory. Volatile memory can be random access memory (RAM), static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDRSDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link dynamic random access memory (SLDRAM) and direct memory bus random access memory (DRRAM).
[0092] The processor may include one or more processing units; optionally, the processor integrates an application processor and a modem processor, wherein the application processor mainly processes operations related to the operating system, user interface, and application programs, and the modem processor mainly processes wireless communication signals, such as a baseband processor. It is understandable that the modem processor may not be integrated into the processor.
[0093] An embodiment of the present application also provides a readable storage medium, on which a program or instruction is stored. When the program or instruction is executed by a processor, the various processes of the above-mentioned message transmission method embodiment are implemented, and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.
[0094] The processor is the processor in the electronic device described in the above embodiment. The readable storage medium includes a computer readable storage medium, such as ROM, RAM, magnetic disk or optical disk.
[0095] It should be noted that, in this article, the terms "comprise", "include" or any other variant thereof are intended to cover non-exclusive inclusion, so that the process, method, article or device including a series of elements includes not only those elements, but also includes other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise one..." do not exclude the presence of other identical elements in the process, method, article or device including the element. In addition, it should be pointed out that the scope of the methods and devices in the embodiments of the present application is not limited to performing functions in the order shown or discussed, and may also include performing functions in a substantially simultaneous manner or in reverse order according to the functions involved, for example, the described method may be performed in an order different from that described, and various steps may also be added, omitted, or combined. In addition, the features described with reference to certain examples may be combined in other examples.
[0096] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a computer software product, which is stored in a storage medium (such as ROM / RAM, a disk, or an optical disk), and includes a number of instructions for a terminal (which can be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods described in each embodiment of the present application.
[0097] The embodiments of the present application are described above in conjunction with the accompanying drawings, but the present application is not limited to the above-mentioned specific implementation methods. The above-mentioned specific implementation methods are merely illustrative and not restrictive. Under the guidance of the present application, ordinary technicians in this field can also make many forms without departing from the purpose of the present application and the scope of protection of the claims, all of which are within the protection of the present application.
Claims
1. A message transmission method, characterized in that: include: When the first service is successfully executed through the first thread, obtaining a first message corresponding to the first service; Storing the first message in a first repository through a first thread; Sending the first message to the message middleware through the second thread; If a message feedback sent by the message middleware is received, the state information corresponding to the first message is determined according to the message feedback, and the state information is stored in a second storage repository through a second thread, wherein the message feedback is used to indicate whether the message middleware has successfully stored the first message; If the message feedback indicates that the message middleware successfully stores the first message, sending the first message to the message receiving end through the message middleware, so that the message receiving end executes the first service according to the first message; If the message feedback indicates that the message middleware fails to store the first message, the reason why the message middleware fails to store the first message and the time when the first message was sent are stored in the second repository; the first message is obtained from the first repository and resent until the message middleware successfully stores the first message.
2. The transmission method according to claim 1, characterized in that: The determining, according to the message feedback, the state information corresponding to the first message includes: If the message feedback indicates that the message middleware successfully stores the first message, the state information corresponding to the first message is first state information, and the first state information indicates that the first message is successfully sent; If the message feedback indicates that the message middleware fails to store the first message, the state information corresponding to the first message is second state information, and the second state information indicates that sending the first message fails.
3. The transmission method according to claim 2, characterized in that: The sending the first message to the message receiving end through the message middleware includes: The second message is sent to the message middleware through the second thread, so that the message middleware sends the first message to the message receiving end after receiving the second message, wherein the second message is used to indicate that the first state information is stored successfully.
4. The method according to claim 2, characterized in that: The method further comprises: If the state information corresponding to the first message is the first state information and storing the first state information fails, issuing an alarm of failure to store the first state information; A third message is sent to the message middleware through the second thread, so that the message middleware deletes the first message, wherein the third message is used to indicate a failure in storing the first state information.
5. The method according to claim 1, characterized in that The method further comprises: If it is detected that the first message is inconsistent with the fourth message received by the message receiving end, a difference message between the first message and the fourth message is sent to the message receiving end through the second thread.
6. The transmission method according to claim 1, characterized in that: The first message includes a field of the first service and data of the first service.
7. A message transmission device, characterized in that: include: An execution module, configured to obtain a first message corresponding to the first service when the first service is successfully executed through the first thread; A first storage module, configured to store the first message in a first storage repository through a first thread; A first sending module, used for sending the first message to the message middleware through a second thread; A second storage module is configured to determine, if a message feedback sent by the message middleware is received, state information corresponding to the first message according to the message feedback, and store the state information in a second storage repository through a second thread, wherein the message feedback is used to indicate whether the message middleware has successfully stored the first message; A second sending module is configured to send the first message to a message receiving end through the message middleware if the message feedback indicates that the message middleware successfully stores the first message, so that the message receiving end executes the first service according to the first message; The second storage module is also used to store the reason for the failure of the message middleware to store the first message and the time of sending the first message in the second repository if the message feedback indicates that the message middleware fails to store the first message; the first sending module is also used to obtain the first message from the first repository for resending until the message middleware successfully stores the first message.
8. An electronic device, characterized in that: The method comprises a processor, a memory, and a program or instruction stored in the memory and executable on the processor, wherein the program or instruction, when executed by the processor, implements the steps of the message transmission method as described in any one of claims 1 to 6.
9. A readable storage medium, characterized in that: The readable storage medium stores a program or instruction, and when the program or instruction is executed by the processor, the steps of the message transmission method according to any one of claims 1 to 6 are implemented.
Citation Information
Patent Citations
Service demand processing method, system and related device
CN112019452A
Message sending method, device and equipment and computer readable storage medium
CN112559223A