Business processing method and device
By simultaneously performing business operations and message sending in database transactions, the problem of inconsistent message sending and service processing logic in upstream business systems is solved, and the final consistency of transactions and the reliability of message sending is achieved.
Patent Information
- Application Number
- CN202311132766.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-09-04
- Publication Date
- 2025-08-26
- Estimated Expiration
- 2043-09-04
AI Technical Summary
Under the distributed system architecture, when the upstream business system performs business operations, the message sending and business processing logic are inconsistent, resulting in transaction errors.
The message sending and business processing logic are placed in the same database transaction. By starting the database transaction when receiving the target transaction request, performing business operations and generating messages, it is sent to the message middleware only after both the message and business data are successfully inserted into the database, ensuring the consistency between message sending and business processing.
It realizes success or failure while sending messages and handling messages, reducing the probability of transaction errors, ensuring the final consistency of transactions, and improving the success of message sending through message retransmission mechanism.
Smart Images

Figure CN117290125B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of Internet technology, and in particular to a service processing method and device. Background Art
[0002] In a distributed system architecture, it's common to encounter situations where, after the upstream business system (i.e., the production-side business system) completes business data processing, it asynchronously notifies the downstream business system (i.e., the consumption-side business system) through message-based middleware to perform the next step of business processing. In other words, the execution of a core business logic requires not only the upstream business system to perform business processing, but also calls into the downstream business system for further processing.
[0003] As the amount of data continues to increase, the processing pressure on upstream business systems continues to increase. The following phenomenon may occur: when the upstream business system performs business operations, it has updated the database, but the message has not been sent to the message middleware. Or, the upstream business system first sends the message to the message middleware, and then updates the database based on the message, but the update fails. In this case, the message sending will be inconsistent with the business processing logic, resulting in transaction errors. Summary of the Invention
[0004] The present disclosure aims to solve one of the technical problems in the related art at least to a certain extent.
[0005] One aspect of the present disclosure proposes a business processing method and apparatus to implement a business operation and a message sending operation performed simultaneously on a production side, placing the message sending and business processing logic in the same database transaction, thereby achieving consistency between message sending and business processing, that is, achieving simultaneous success or failure of the business operation and the message sending operation, thereby reducing the probability of transaction errors and ensuring the ultimate consistency of the transaction.
[0006] The first embodiment of the present disclosure provides a business processing method, which is applied to a production end and includes:
[0007] In response to receiving the target transaction request, opening a database transaction and executing a first business operation associated with the target transaction request to obtain target business data;
[0008] generating a first message according to the target service data, and inserting the first message and the target service data into a target database;
[0009] In response to the successful insertion of the first message and the target business data, the first message in the target database is sent to the message middleware, so that the consumer end pulls the first message from the message middleware and executes the second business operation associated with the target transaction request according to the first message.
[0010] A second embodiment of the present disclosure provides a business processing device, which is applied to a production end and includes:
[0011] An opening module, configured to open a database transaction in response to receiving a target transaction request;
[0012] an execution module, configured to execute a first business operation associated with the target transaction request to obtain target business data;
[0013] a processing module, configured to generate a first message according to the target business data, and insert the first message and the target business data into a target database;
[0014] A sending module is used to send the first message in the target database to the message middleware in response to the successful insertion of the first message and the target business data, so that the consumer end pulls the first message from the message middleware and performs a second business operation associated with the target transaction request according to the first message.
[0015] The third embodiment of the present disclosure proposes an electronic device, comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the program, it implements the business processing method proposed in the first embodiment of the present disclosure.
[0016] The fourth embodiment of the present disclosure proposes a non-temporary computer-readable storage medium on which a computer program is stored. When the program is executed by a processor, it implements the business processing method proposed in the first embodiment of the present disclosure.
[0017] The fifth embodiment of the present disclosure proposes a computer program product. When the instructions in the computer program product are executed by a processor, the business processing method proposed in the first embodiment of the present disclosure is executed.
[0018] The technical solutions provided by the above embodiments of the present disclosure bring at least the following beneficial effects:
[0019] 1. When the first business operation executed on the production side and the message sending operation are performed simultaneously, the message sending and business processing logic can be placed in the same database transaction, thereby achieving consistency between message sending and business processing. That is, the business operation and the message sending operation can succeed or fail at the same time, thereby reducing the probability of transaction errors and ensuring the ultimate consistency of transactions.
[0020] 2. According to the second business operation to be executed by the downstream business system, determine the target topic to which the first message belongs, and publish the first message to the target topic of the message middleware. This can enable the consumer end that subscribes to the target topic to pull the first message from the target topic of the message middleware in a timely and effective manner, and execute the second business operation associated with the target topic based on the first message, so as to improve the effectiveness and timeliness of business processing.
[0021] 3. If the first message fails to be sent, the message resend mechanism can be used to resend the first message to the target topic in the messaging middleware, thereby improving the success rate of sending or publishing the first message. Furthermore, if a business operation and / or message sending operation fails, the first message and target business data can be deleted to ensure transaction consistency in upstream and downstream business systems.
[0022] Additional aspects and advantages of the present disclosure will be given in part in the following description and in part will be obvious from the following description, or will be learned through practice of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] The above and / or additional aspects and advantages of the present disclosure will become apparent and readily understood from the following description of the embodiments in conjunction with the accompanying drawings, in which:
[0024] Figure 1 A flowchart of a business processing method provided by an embodiment of the present disclosure;
[0025] Figure 2 A flowchart of another business processing method provided by an embodiment of the present disclosure;
[0026] Figure 3 A flowchart of another business processing method provided by an embodiment of the present disclosure;
[0027] Figure 4 A flowchart of another business processing method provided by an embodiment of the present disclosure;
[0028] Figure 5 A flowchart of another business processing method provided by an embodiment of the present disclosure;
[0029] Figure 6 A schematic diagram of the process of publishing a message on the production side provided in an embodiment of the present disclosure;
[0030] Figure 7 A schematic diagram of the structure of a service processing device provided by an embodiment of the present disclosure;
[0031] Figure 8 It is a schematic structural diagram of an electronic device shown in an exemplary embodiment of the present disclosure. DETAILED DESCRIPTION
[0032] The following describes in detail embodiments of the present disclosure, examples of which are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are intended to be used to explain the present disclosure, and should not be construed as limiting the present disclosure.
[0033] As the amount of data continues to increase, the processing pressure on upstream business systems continues to increase. The following phenomenon may occur: when the upstream business system performs business operations, it has updated the database, but the message has not been sent to the message middleware. Or, the upstream business system first sends the message to the message middleware, and then updates the database based on the message, but the update fails. In this case, the message sending will be inconsistent with the business processing logic, resulting in transaction errors.
[0034] The above is the consistency issue between database transactions and MQ (Message Queue) messages. Simply put, database transactions and ordinary MQ message sending cannot be directly bound together, and the consistency of messages cannot be guaranteed. Therefore, to solve the problem of reliable message consistency, one aspect of this disclosure proposes a business processing method and device.
[0035] The following describes the service processing method and apparatus of the embodiments of the present disclosure with reference to the accompanying drawings. Before describing the embodiments of the present disclosure in detail, for ease of understanding, the following common technical terms are first introduced:
[0036] ID is the abbreviation of Identity.
[0037] MQTT, short for Message Queuing Telemetry Transport, is a lightweight communication protocol based on the publish / subscribe model.
[0038] Kafka is a high-throughput distributed publish-subscribe messaging system that can process all action stream data of consumers (or consumer ends) on the website.
[0039] RocketMQ is an open source distributed messaging middleware.
[0040] ZeroMQ is a lightweight message communication library and a special message middleware formed by extending the traditional standard socket interface.
[0041] JSON (JavaScript Object Notation) is a lightweight data exchange format. JSON data has a concise and clear hierarchical structure, making it easy for users to read and write, as well as for machines to parse and generate data, effectively improving network transmission efficiency.
[0042] Figure 1 A flowchart of a business processing method provided by an embodiment of the present disclosure.
[0043] The business processing method provided by the embodiment of the present disclosure can be applied to the production end, wherein the production end (or called the message production end, the message sending end) can be a client that produces, sends or publishes messages.
[0044] The client can be a software program running on a device to provide services to users, or a program or device that uses MQTT. Devices can be, for example, personal computers, mobile terminals, servers, etc. Mobile terminals can be, for example, mobile phones, tablet computers, personal digital assistants, wearable devices, intelligent robots, and other hardware devices with various operating systems, touch screens, and / or displays.
[0045] like Figure 1 As shown, the business processing method may include the following steps:
[0046] Step S101 : in response to receiving a target transaction request, opening a database transaction and executing a first business operation associated with the target transaction request to obtain target business data.
[0047] In the embodiment of the present disclosure, the target transaction request includes but is not limited to: a transfer request, a deposit request, a withdrawal request, etc.
[0048] In the embodiments of the present disclosure, the target transaction request may be sent by an application client (such as mobile banking, Alipay, Taobao, etc.) through different channels to the production end in the upstream business system of a financial institution (such as a bank), or the target transaction request may be sent by a clearing platform or a settlement platform to the production end, and the embodiments of the present disclosure do not impose any restrictions on this.
[0049] In the embodiments of the present disclosure, the target business data may include business messages and business assembly data. Taking the target transaction request as an example of a transfer request, the target business data may include the transfer message, transfer-in account information, transfer account information, transfer amount, information about the teller handling the transfer request, etc. For another example, taking the target transaction request as an example of a deposit request, the target business data may include the deposit message, deposit account information, deposit amount, information about the teller handling the deposit request, etc.
[0050] In an embodiment of the present disclosure, upon receiving a target transaction request, the production end may start a database transaction and execute a first business operation associated with the target transaction request to obtain target business data.
[0051] As an example, taking the target transaction request as a transfer request, the first business operation may be a transfer operation.
[0052] Step S102: Generate a first message according to the target business data, and insert the first message and the target business data into a target database.
[0053] In the embodiment of the present disclosure, the first message may include target business data. For example, the target business data may be assembled or encapsulated to obtain a structured (eg, JSON format) first message.
[0054] In an embodiment of the present disclosure, the production end may generate a first message based on the target business data, and insert the first message and the target business data into the target database.
[0055] Step S103, in response to the successful insertion of the first message and the target business data, the first message in the target database is sent to the message middleware, so that the consumer end pulls the first message from the message middleware and executes the second business operation associated with the target transaction request according to the first message.
[0056] In the embodiment of the present disclosure, the message middleware may be Kafka, RocketMQ, ZeroMQ or other message middleware.
[0057] In the embodiment of the present disclosure, the target database can be a database shared by all production terminals. That is, for any production terminal, after receiving a transaction request and executing the business operation associated with the transaction request and obtaining the business data, the production terminal can generate a message based on the business data and insert the message and business data into the target database.
[0058] In an embodiment of the present disclosure, when the first message and the target business data are successfully inserted into the target database, the production end can send or publish the first message in the target database to the message middleware, so that the consumer end in the downstream business system of the financial institution (such as a bank) pulls the first message from the message middleware and executes the second business operation associated with the target transaction request based on the first message.
[0059] Among them, the consumer end (or called the message consumer end, the message receiving end) can be a client end that consumes messages.
[0060] As an example, taking the target transaction request as a transfer request, the second business operation may be a bookkeeping operation.
[0061] The business processing method of the embodiment of the present disclosure is as follows: in response to receiving a target transaction request, a database transaction is opened, and a first business operation associated with the target transaction request is executed to obtain target business data; a first message is generated according to the target business data, and the first message and the target business data are inserted into the target database; in response to the successful insertion of the first message and the target business data, the first message in the target database is sent to the message middleware, so that the consumer end pulls the first message from the message middleware and executes the second business operation associated with the target transaction request according to the first message. In this way, when the first business operation executed on the production end and the message sending operation are carried out at the same time, the message sending and business processing logic are placed in the same database transaction, thereby achieving consistency between message sending and business processing, that is, achieving the simultaneous success or failure of the business operation and the message sending operation, so as to reduce the probability of transaction errors and ensure the ultimate consistency of the transaction.
[0062] For example, taking the target transaction request as a transfer request, if the target business data and / or the first message fail to be inserted into the target database, it indicates that the transfer has failed. At this time, if the first message is sent to the message middleware, the consumer end will pull the first message from the message middleware and the consumer end will record the account normally. At this time, the transfer will not be successful, but the account has been recorded. The balance of the transfer account will decrease, but the balance of the transfer account will not increase, resulting in a transaction error.
[0063] In this application, the first message is sent to the message middleware only when the target business data and the first message are successfully inserted into the target database. This ensures that only when the transfer is successful can the consumer end pull the first message from the message middleware and record the account normally, to ensure that when the balance of the transfer account decreases, the balance of the transfer account can increase, thereby improving the accuracy of the transaction.
[0064] In the event that the target business data and / or the first message fails to be inserted into the target database, there is no need to send the first message to the message middleware to avoid the consumer consuming the first message and causing a transaction error.
[0065] In order to clearly illustrate the above embodiments, the present disclosure further proposes a service processing method.
[0066] Figure 2 A flowchart of another business processing method provided by an embodiment of the present disclosure.
[0067] like Figure 2 As shown, the business processing method is applied to the production side and may include the following steps:
[0068] Step S201 : in response to receiving a target transaction request, start a database transaction and execute a first business operation associated with the target transaction request to obtain target business data.
[0069] Step S202: Generate a first message according to the target business data, and insert the first message and the target business data into a target database.
[0070] For explanations of steps S201 to S202 , reference may be made to the relevant descriptions in any embodiment of the present disclosure, and no further details will be given here.
[0071] Step S203, determining whether the first message and the target business data are both successfully inserted into the target database, if so, executing step S205, if not, executing step S204.
[0072] It should be noted that step S204 and step S205 are two parallel implementation methods. In actual application, only one needs to be executed.
[0073] Step S204: roll back the database transaction to delete the first message and target business data.
[0074] In an embodiment of the present disclosure, if the first message is not successfully inserted into the target database (i.e., the insertion fails), and / or the target business data is not successfully inserted into the target database (i.e., the insertion fails), the production end can roll back the database transaction to delete the first message and the target business data.
[0075] Step S205: Send the first message in the target database to the message middleware.
[0076] In an embodiment of the present disclosure, when both the first message and the target business data are successfully inserted into the target database (i.e., the insertion is successful), the production end can send the first message in the target database to the message middleware, so that the consumer end pulls the first message from the message middleware and executes the second business operation associated with the target transaction request based on the first message.
[0077] In any embodiment of the present disclosure, when the first message and the target business data are both inserted successfully, the production end may further set the state of the first message in the target database to a waiting-to-send state.
[0078] The business processing method of the embodiment of the present disclosure can delete the first message and target business data when the business operation and / or message sending operation fails, so as to ensure the consistency of transactions in upstream and downstream business systems.
[0079] In order to clearly illustrate the above embodiments, the present disclosure further proposes a service processing method.
[0080] Figure 3A flowchart of another business processing method provided by an embodiment of the present disclosure.
[0081] like Figure 3 As shown, the business processing method can be applied to the production side, including the following steps:
[0082] Step S301 : in response to receiving a target transaction request, start a database transaction and execute a first business operation associated with the target transaction request to obtain target business data.
[0083] Step S302: Generate a first message according to target business data.
[0084] For explanations of steps S301 to S302 , reference may be made to the relevant descriptions in any embodiment of the present disclosure, and no further details will be given here.
[0085] Step S303: Acquire configuration information, wherein the configuration information includes first identification information of the target database, second identification information of the message table, and third identification information of the business table.
[0086] In an embodiment of the present disclosure, the production end can obtain pre-configured configuration information, wherein the configuration information may include first identification information of the target database (such as name), second identification information of the message table (such as table name), and third identification information of the business table (such as table name).
[0087] Step S304: Determine, based on the first identification information, a target database that matches the first identification information from at least one database.
[0088] In the embodiment of the present disclosure, the production end may determine, based on the first identification information, from at least one database, a target database that matches the first identification information.
[0089] Step S305 : Determine, from at least one data table in the target database, a message table that matches the second identification information, and a service table that matches the third identification information.
[0090] In an embodiment of the present disclosure, the production end can determine a message table that matches the second identification information (such as a table name) from at least one data table in the target database based on the second identification information, and determine a business table that matches the third identification information (such as a table name) from at least one data table in the target database based on the third identification information.
[0091] Step S306: insert the first message into the message table, and insert the target service data into the service table.
[0092] In an embodiment of the present disclosure, the production end may insert the first message into a message table in the target database, and insert the target business data into a business table in the target database.
[0093] Step S307 , determining whether the first message is successfully inserted into the message table and whether the target business data is successfully inserted into the business table, if yes, executing step S308 , if no, executing step S309 .
[0094] It should be noted that step S308 and step S309 are two parallel implementation methods. In actual application, only one needs to be executed.
[0095] Step S308: Send the first message in the message table to the message middleware.
[0096] In an embodiment of the present disclosure, when the first message is successfully inserted into the message table and the target business data is successfully inserted into the business table, the production end can send the first message in the message table that is in a pending state to the message middleware, so that the consumer end pulls the first message from the message middleware and executes the second business operation associated with the target transaction request according to the first message.
[0097] In any embodiment of the present disclosure, after the production end sends the first message in the target database to the message middleware, the production end may also send an asynchronous message to the message middleware, wherein the asynchronous message is used to remind the production end to delete the first message in the message table after a set period of time to reduce the occupancy of storage resources.
[0098] Specifically, first, the production end can send a second message to the message middleware, wherein the second message carries the message identifier of the first message (such as the unique ID of the first message, the retrieval index of the first message in the message table, etc.) and the first target time, wherein the first target time is determined based on the sending time of the first message. For example, the first target time can be the sending time of the first message + the set duration.
[0099] Afterwards, the production end may obtain the second message sent by the message middleware in response to reaching the first target moment, and delete the first message matching the message identifier from the message table in the target database according to the message identifier in the second message.
[0100] As an example, taking the setting time as 24 hours for exemplary explanation, the production end can dynamically delete the messages that have been stored in the message table for 24 hours by sending asynchronous messages to the message middleware, so as to reduce the storage resource usage in the target database.
[0101] Step S309: roll back the database transaction to delete the first message and target business data.
[0102] In an embodiment of the present disclosure, if the first message is not successfully inserted into the message table and / or the target business data is not successfully inserted into the business table, the consumer end may roll back the database transaction to delete the first message and the target business data.
[0103] In any embodiment of the present disclosure, in order to reduce the occupancy of storage resources in the target database, the production end can also determine whether the set conditions are met at the current moment. If so, delete the messages in the message table that have been stored for more than the set time. If not, continue to determine whether the conditions are set at the next moment or subsequent moment. If so, delete the messages in the message table that have been stored for more than the set time.
[0104] The setting conditions may include any of the following:
[0105] The first item is when the set period is reached, that is, the messages stored in the message table can be updated regularly.
[0106] For example, the messages stored in the message table may be updated at 00:00:00 every day. When the current time is 00:00:00, it may be determined that the current time meets the set condition. However, when the current time is not 00:00:00, it may be determined that the current time does not meet the set condition.
[0107] The second item is reaching the second target time, wherein the number of transaction requests received during the time period of the second target time is less than the first set threshold, or the number of messages or business data inserted into the target database during the time period of the second target time is less than the second set threshold.
[0108] The first set threshold and the second set threshold are both pre-set quantity thresholds. It should be noted that the embodiments of the present disclosure do not limit the magnitude relationship between the first set threshold and the second set threshold. For example, the first set threshold may be equal to the second set threshold, or the first set threshold may be greater than the second set threshold, or the first set threshold may be less than the second set threshold.
[0109] That is, in the present disclosure, the time period in which the second target moment is located can be a low-peak period for message production, or the time period in which the second target moment is located can be a low-peak period for business processing, or the time period in which the second target moment is located can be a non-transaction peak period or a transaction low-peak period.
[0110] This allows for dynamic maintenance of the message table in the target database, such as deleting messages that have been stored for a long time to reduce storage overhead.
[0111] The business processing method of the embodiment of the present disclosure can accurately insert messages and business data into a specified or required data table in a target database according to configuration information.
[0112] In order to clearly illustrate the above embodiments, the present disclosure further proposes a service processing method.
[0113] Figure 4 A flowchart of another business processing method provided by an embodiment of the present disclosure.
[0114] like Figure 4 As shown, the business processing method can be applied to the production side, including the following steps:
[0115] Step S401 : in response to receiving a target transaction request, start a database transaction and execute a first business operation associated with the target transaction request to obtain target business data.
[0116] Step S402: Generate a first message according to the target business data, and insert the first message and the target business data into the target database.
[0117] Step S403 , determining whether the first message and the target business data are both successfully inserted into the target database, if so, executing step S405 , if not, executing step S404 .
[0118] It should be noted that step S404 and step S405 are two parallel implementation methods. In actual application, only one needs to be executed.
[0119] Step S404: roll back the database transaction to delete the first message and target business data.
[0120] In an embodiment of the present disclosure, when the first message fails to be inserted and / or the target business data fails to be inserted, the database transaction may be rolled back to delete the first message and the target business data.
[0121] For explanations of steps S401 to S404 , reference may be made to the relevant descriptions in any embodiment of the present disclosure, and no further details will be given here.
[0122] Step S405 : Determine the target topic to which the first message belongs according to the second business operation associated with the target transaction request.
[0123] A topic refers to the classification of different business subscriptions in the message-based middleware, such as accounting, accounting notification, and SMS notification. It should be noted that messages generated by different production terminals can have different topics. For example, message 1 generated by production terminal 1 in the upstream business system may have the topic of accounting notification, while message 2 generated by production terminal 2 may have the topic of SMS notification.
[0124] In the embodiment of the present disclosure, the production end can determine the target topic to which the first message belongs based on the second business operation associated with the target transaction request, that is, the production end can determine the first business operation to be executed by the upstream business system and the second business operation to be executed by the downstream business system based on the transaction type of the target transaction request (such as transfer, deposit, withdrawal, etc.), and after executing the first business operation, determine the target topic to which the first message belongs based on the second business operation.
[0125] As an example, taking the transaction type of transfer as an example, the first business operation may be a transfer operation, the second business operation may be an accounting operation, and the target topic of the first message may be "transfer" or "transfer notification".
[0126] Step S406: publish the first message in the target database in a waiting-to-send state to the target topic of the message middleware.
[0127] The first message under the target topic is used for a consumer that subscribes to the target topic to pull the first message from the target topic and to perform a second business operation associated with the target topic according to the first message.
[0128] In an embodiment of the present disclosure, the production end can publish the first message in the target database that is in a waiting-to-send state to the target topic of the message middleware, so that the consumer end that subscribes to the target topic can pull the first message from the target topic of the message middleware and execute the second business operation associated with the target topic based on the first message.
[0129] The business processing method of the embodiment of the present disclosure determines the target topic to which the first message belongs based on the second business operation to be executed by the downstream business system, and publishes the first message to the target topic of the message middleware. This allows the consumer end that subscribes to the target topic to promptly and effectively pull the first message from the target topic of the message middleware, and execute the second business operation associated with the target topic based on the first message, thereby improving the effectiveness and timeliness of business processing.
[0130] In any embodiment of the present disclosure, after the production end publishes the first message to the message middleware, it can also be determined whether the first message is published successfully. If so, the database transaction is submitted. If not, the first message is republished to the message middleware based on the message resending mechanism to improve the success rate of the first message publishing. Figure 5 , the above process is explained in detail.
[0131] Figure 5 A flowchart of another business processing method provided by an embodiment of the present disclosure.
[0132] like Figure 5As shown, based on any of the above embodiments, after the production end sends the first message in the target database to the message middleware, the business processing method may further include the following steps:
[0133] Step S501: determine whether first feedback information sent by the message middleware is received within a set period after the third target time. If so, execute step S502; if not, execute step S503.
[0134] The first feedback information is used to indicate that the message middleware has received the first message, and the third target time is the publishing time or sending time of the first message.
[0135] In the embodiment of the present disclosure, after sending the first message, the producer can store the sending time of the first message (referred to as the third target time in this application) and determine whether the first feedback information sent by the message middleware is received within a set period after the third target time. If so, step S502 is executed; if not, step S503 is executed. The first feedback information is used to indicate that the message middleware has received the first message sent by the producer.
[0136] It should be noted that step S502 and step S503 are two parallel implementation methods. In actual application, only one needs to be executed.
[0137] Step S502: Change the state of the first message in the target database from a waiting-to-send state to a successfully sent state, and commit the database transaction.
[0138] In an embodiment of the present disclosure, when the production end receives the first feedback message, the production end can determine that the first message is sent successfully. At this time, the production end can change the status of the first message in the target database from the pending state to the successfully sent state, and commit the database transaction.
[0139] Step S503: Change the state of the first message in the target database from a waiting-to-send state to a failed-to-send state.
[0140] In an embodiment of the present disclosure, if the production end does not receive the first feedback message, the production end can determine that the first message has failed to be sent. At this time, the production end can change the state of the first message in the target database from the waiting state to the failed sending state.
[0141] Step S504: resend the first message in the target database that is in a failed sending state to the target topic of the message middleware.
[0142] In an embodiment of the present disclosure, when the first message fails to be sent and the production end updates the status of the first message to a failed sending status, the production end may also resend the first message in the failed sending status in the target database to the target topic of the message middleware, so that the consumer end that subscribes to the target topic pulls the first message from the target topic of the message middleware and executes the second business operation associated with the target topic based on the first message.
[0143] Step S505 , determining whether the second feedback information sent by the message middleware is received within a set period after the fourth target time, if so, executing step S506 , if not, executing step S507 .
[0144] The second feedback information is used to indicate that the message middleware has received the resent first message, and the fourth target time is the time when the first message is resent.
[0145] In an embodiment of the present disclosure, after the producer resends the first message, the resending time of the first message (referred to as the fourth target time in the present disclosure) may be stored, and a determination may be made as to whether the second feedback information sent by the message middleware is received within a set period after the fourth target time. If so, step S506 is executed; if not, step S507 is executed. The second feedback information indicates that the message middleware has received the first message resent by the producer.
[0146] It should be noted that step S506 and step S507 are two parallel implementation methods. In actual application, only one needs to be executed.
[0147] Step S506: Update the status of the first message in the target database from a failed sending status to a successful sending status, and commit the database transaction.
[0148] In an embodiment of the present disclosure, when the production end receives the second feedback message, the production end can determine that the first message is resent successfully. At this time, the production end can change the status of the first message in the target database from a failed sending state to a successful sending state, and commit the database transaction.
[0149] Step S507: Send the first message in the target database that is in the failed sending state to the target topic of the message middleware again until the target feedback information sent by the message middleware is received, update the state of the first message in the target database from the failed sending state to the successful sending state, and commit the database transaction.
[0150] In an embodiment of the present disclosure, if the production end does not receive the second feedback message, the production end may determine that the first message has failed to be sent again. At this time, the production end may resend the first message in the target database that is in a failed sending state to the target topic of the message middleware. Only when the production end receives the target feedback message sent by the message middleware will the production end update the state of the first message in the target database from a failed sending state to a successful sending state and commit the database transaction. The target feedback information is used to indicate that the message middleware has received the first message sent by the production end.
[0151] The business processing method of the embodiment of the present disclosure can achieve, when the first message fails to be sent, resending the first message to the target topic in the message middleware based on the message resending mechanism, which can improve the success rate of sending or publishing the first message.
[0152] In any embodiment of the present disclosure, the reliability of the message on the production side depends on the database transaction. The message sending persistence and the business processing logic can be placed in the same database transaction to achieve simultaneous success or failure. Moreover, when the message fails to be sent, the production side can automatically resend the message until the message is successfully sent. The specific implementation principle can be as follows Figure 6 As shown, it mainly includes the following steps:
[0153] 1.1. When a transaction request is received, a database transaction is started. The production end in the upstream business system executes the business operations associated with the transaction request and processes the business data.
[0154] For example, taking the transaction request as a transfer request, the production end can perform the transfer operation in response to the transaction request.
[0155] 1.2. The production end sends messages and persists them in the message table in the database, and persists the business data in the business table in the database.
[0156] 1.3. If the business data and messages are successfully inserted into the database, proceed to step 1.5.
[0157] 1.4 If the business data and / or message is not successfully inserted into the database, roll back the database transaction to delete the message and business data.
[0158] 1.5. Send the message to the target topic in the message middleware. For example, the target topic can be "accounting".
[0159] 1.6. After the message is sent successfully, modify the record status of the message in the message table, for example, change the record status of the message from the pending state to the successfully sent state, and commit the database transaction.
[0160] 1.7. If the message fails to be sent, or if the record status changes to failed sending, execute step 1.8.
[0161] 1.8. Execute the message resending mechanism to automatically resend messages.
[0162] In summary, database transactions can be used to combine messages and business data within the same database transaction. This allows business operations and message sending to succeed or fail simultaneously. The message resend mechanism ensures that messages are resent after a message sending failure, thus ensuring eventual transaction consistency. In other words, when business operations and message sending are performed simultaneously, the insertion of processed business data into the database and the sending of the message can succeed or fail simultaneously, ensuring eventual transaction consistency.
[0163] With the above Figure 1-Figure 5 Corresponding to the service processing method provided in the embodiment, the present disclosure also provides a service processing device. Figure 1-Figure 5 The business processing method provided in the embodiment corresponds to the embodiment, so the implementation of the business processing method is also applicable to the business processing device provided in the embodiment of the present disclosure, and will not be described in detail in the embodiment of the present disclosure.
[0164] Figure 7 A schematic diagram of the structure of a service processing device provided by an embodiment of the present disclosure.
[0165] like Figure 7 As shown, the business processing device 700 can be applied to the production end, including: an opening module 710, an execution module 720, a processing module 730 and a sending module 740.
[0166] The start module 710 is configured to start a database transaction in response to receiving a target transaction request.
[0167] The execution module 720 is configured to execute a first business operation associated with the target transaction request to obtain target business data.
[0168] The processing module 730 is configured to generate a first message according to the target business data, and insert the first message and the target business data into a target database.
[0169] The sending module 740 is used to send the first message in the target database to the message middleware in response to the successful insertion of the first message and the target business data, so that the consumer end pulls the first message from the message middleware and executes the second business operation associated with the target transaction request according to the first message.
[0170] In a possible implementation of the embodiment of the present disclosure, the processing module 730 is specifically used to: obtain configuration information, wherein the configuration information includes first identification information of the target database, second identification information of the message table, and third identification information of the business table; based on the first identification information, determine the target database that matches the first identification information from at least one database; determine the message table that matches the second identification information and the business table that matches the third identification information from at least one data table in the target database; insert the first message into the message table, and insert the target business data into the business table.
[0171] In a possible implementation of the embodiment of the present disclosure, the sending module 740 is further used to: send a second message to the message middleware; wherein the second message carries the message identifier and the first target time of the first message, and the first target time is determined according to the sending time of the first message.
[0172] The service processing device 700 may further include:
[0173] An acquisition module, configured to acquire a second message sent by the message middleware in response to reaching the first target time;
[0174] The first deleting module is configured to delete the first message matching the message identifier from the message table in the target database according to the message identifier in the second message.
[0175] In a possible implementation of the embodiment of the present disclosure, the service processing apparatus 700 may further include:
[0176] The first judgment module is used to judge whether the current moment meets the set conditions.
[0177] The second deletion module is used to delete messages that have been stored in the message table for longer than a set time period when a set condition is met at the current moment; the set condition includes any one of the following: reaching a set period; reaching a second target moment; wherein the number of transaction requests received during the time period of the second target moment is less than a first set threshold, or the number of messages or business data inserted into the target database during the time period of the second target moment is less than a second set threshold.
[0178] In a possible implementation of the embodiment of the present disclosure, when both the first message and the target service data are successfully inserted, the service processing apparatus 700 may further include:
[0179] The setting module is configured to set the state of the first message in the target database to a waiting-to-send state.
[0180] In a possible implementation of the embodiment of the present disclosure, the service processing apparatus 700 may further include:
[0181] The rollback module is configured to roll back the database transaction in response to a failure in inserting the first message and / or a failure in inserting the target business data, so as to delete the first message and the target business data.
[0182] In a possible implementation of the embodiment of the present disclosure, the sending module 740 is specifically used to: determine the target topic to which the first message belongs based on the second business operation associated with the target transaction request; publish the first message in the target database that is in a pending-sending state to the target topic of the message middleware; wherein the first message under the target topic is used for a consumer end that subscribes to the target topic to pull the first message from the target topic, and execute the second business operation associated with the target topic based on the first message.
[0183] In a possible implementation of the embodiment of the present disclosure, the service processing apparatus 700 may further include:
[0184] A second determination module is configured to determine whether a first feedback message sent by the message middleware is received within a set period after the third target time; wherein the first feedback message is used to indicate that the message middleware has received the first message, and the third target time is the time when the first message is published;
[0185] a modification module, configured to modify the state of the first message in the target database from a waiting-to-send state to a successfully sent state upon receiving the first feedback message;
[0186] Submit module, used to submit database transactions;
[0187] The modification module is further configured to: if the first feedback information is not received, modify the state of the first message in the target database from a waiting-to-send state to a failed-to-send state;
[0188] The sending module 740 is further configured to resend the first message in the target database that is in a sending failure state to the target topic of the message middleware.
[0189] In a possible implementation of the embodiment of the present disclosure, the service processing apparatus 700 may further include:
[0190] a third determination module, configured to determine whether second feedback information sent by the message middleware is received within a set period after the fourth target time; wherein the second feedback information is used to indicate that the message middleware has received the resent first message, and the fourth target time is the time when the first message is resent;
[0191] an updating module, configured to update the state of the first message in the target database from a failed sending state to a successfully sent state upon receiving the second feedback information;
[0192] The commit module is also used to: commit database transactions;
[0193] The sending module 740 is also used to: if the second feedback information is not received, then send the first message in the target database that is in the failed sending state to the target topic of the message middleware again, until the target feedback information sent by the message middleware is received, update the state of the first message in the target database from the failed sending state to the successful sending state, and commit the database transaction; wherein the target feedback information is used to indicate that the message middleware has received the first message.
[0194] The business processing device of the embodiment of the present disclosure, in response to receiving a target transaction request, opens a database transaction and executes a first business operation associated with the target transaction request to obtain target business data; generates a first message based on the target business data, and inserts the first message and the target business data into the target database; in response to the successful insertion of the first message and the target business data, sends the first message in the target database to the message middleware, so that the consumer end pulls the first message from the message middleware and executes the second business operation associated with the target transaction request based on the first message. In this way, when the business operation and the message sending operation are carried out at the same time, the message sending and the business processing logic are placed in the same database transaction, thereby achieving consistency between the message sending and the business processing, that is, achieving the simultaneous success or failure of the business operation and the message sending operation, thereby reducing the probability of transaction errors and ensuring the ultimate consistency of the transaction.
[0195] In order to implement the above embodiments, the present disclosure also proposes an electronic device, wherein the electronic device can be any device with computing capabilities, and the electronic device includes: a memory, a processor, and a computer program stored in the memory and runnable on the processor. When the processor executes the program, it implements the business processing method proposed in any of the above embodiments of the present disclosure.
[0196] As an example, Figure 8 is a structural diagram of an electronic device 800 shown in an exemplary embodiment of the present disclosure, such as Figure 8 As shown, the electronic device 800 may further include:
[0197] The memory 810 and the processor 820, and the bus 830 connecting different components (including the memory 810 and the processor 820), the memory 810 stores a computer program, and when the processor 820 executes the program, the business processing method described in the embodiment of the present disclosure is implemented.
[0198] Bus 830 represents one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, a processor, or a local bus using any of a variety of bus architectures. Examples of these architectures include, but are not limited to, an Industry Standard Architecture (ISA) bus, a Micro Channel Architecture (MAC) bus, an Enhanced ISA bus, a Video Electronics Standards Association (VESA) local bus, and a Peripheral Component Interconnect (PCI) bus.
[0199] The electronic device 800 typically includes a variety of electronic device-readable media. These media can be any available media that can be accessed by the electronic device 800, including volatile and non-volatile media, removable and non-removable media.
[0200] The memory 810 may also include computer system readable media in the form of volatile memory, such as random access memory (RAM) 840 and / or cache memory 850. The server 800 may further include other removable / non-removable, volatile / non-volatile computer system storage media. By way of example only, the storage system 860 may be used to read and write non-removable, non-volatile magnetic media ( Figure 8 Not shown, often called a "hard drive"). Although Figure 8 Not shown, a disk drive for reading and writing to a removable non-volatile disk (e.g., a "floppy disk"), and an optical drive for reading and writing to a removable non-volatile 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 830 via one or more data medium interfaces. Memory 810 may include at least one program product having a set (e.g., at least one) of program modules configured to perform the functions of various embodiments of the present disclosure.
[0201] A program / utility 880 having a set (at least one) of program modules 870 may be stored, for example, in memory 810. Such program modules 870 include, but are not limited to, an operating system, one or more application programs, other program modules, and program data, each of which, or some combination thereof, may include an implementation of a network environment. Program modules 870 generally implement the functions and / or methods of the embodiments described herein.
[0202] The electronic device 800 can also communicate with one or more external devices 890 (e.g., a keyboard, a pointing device, a display 891, etc.), one or more devices that enable a user to interact with the electronic device 800, and / or any device that enables the electronic device 800 to communicate with one or more other computing devices (e.g., a network card, a modem, etc.). Such communication can occur via an input / output (I / O) interface 892. Furthermore, the electronic device 800 can 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 a network adapter 893. As shown, the network adapter 893 communicates with other modules of the electronic device 800 via a bus 830. It should be understood that, although not shown in the figure, other hardware and / or software modules can be used in conjunction with the electronic device 800, including but not limited to microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.
[0203] The processor 820 executes various functional applications and data processing by running programs stored in the memory 810 .
[0204] It should be noted that the implementation process and technical principles of the electronic device of this embodiment can be found in the aforementioned explanation of the business processing method of the embodiment of the present disclosure, and will not be repeated here.
[0205] In order to implement the above embodiments, the present disclosure further proposes a non-transitory computer-readable storage medium on which a computer program is stored. When the program is executed by a processor, it implements the business processing method proposed in any of the above embodiments of the present disclosure.
[0206] In order to implement the above embodiments, the present disclosure further proposes a computer program product. When instructions in the computer program product are executed by a processor, the service processing method proposed in any of the above embodiments of the present disclosure is executed.
[0207] In the description of this specification, the description with reference to the terms "one embodiment", "some embodiments", "example", "specific example", or "some examples" means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present disclosure. In this specification, the schematic representations of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner. In addition, those skilled in the art may combine and combine different embodiments or examples described in this specification and features of different embodiments or examples, unless they are mutually inconsistent.
[0208] Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features being referred to. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one such feature. Throughout the present disclosure, "plurality" means at least two, such as two, three, etc., unless otherwise specifically defined.
[0209] Any process or method description in a flowchart or otherwise described herein may be understood to represent a module, segment or portion of code comprising one or more executable instructions for implementing the steps of a custom logical function or process, and the scope of the preferred embodiments of the present disclosure includes additional implementations in which functions may be performed out of the order shown or discussed, including performing functions in a substantially simultaneous manner or in the reverse order depending on the functions involved, which should be understood by those skilled in the art to which the embodiments of the present disclosure belong.
[0210] The logic and / or steps represented in the flowcharts or otherwise described herein, for example, can be considered as a sequenced list of executable instructions for implementing the logical functions, and can be embodied in any computer-readable medium for use by, or in conjunction with, an instruction execution system, apparatus, or device (e.g., a computer-based system, a system including a processor, or other system that can fetch and execute instructions from an instruction execution system, apparatus, or device). For purposes of this specification, a "computer-readable medium" can be any device that can contain, store, communicate, propagate, or transport a program for use by, or in conjunction with, an instruction execution system, apparatus, or device. More specific examples (a non-exhaustive list) of computer-readable media include the following: an electrical connection with one or more wires (electronic devices), a portable computer disk cartridge (magnetic device), random access memory (RAM), read-only memory (ROM), erasable and programmable read-only memory (EPROM or flash memory), fiber optic devices, and a portable compact disc read-only memory (CDROM). Furthermore, the computer-readable medium may even be paper or other suitable medium on which the program is printed, since the program may be obtained electronically, for example, by optically scanning the paper or other medium and then editing, interpreting or processing it in another suitable manner if necessary, and then storing it in a computer memory.
[0211] It should be understood that various parts of the present disclosure can be implemented using hardware, software, firmware, or a combination thereof. In the above embodiments, multiple steps or methods can be implemented using software or firmware stored in a memory and executed by a suitable instruction execution system. For example, if implemented using hardware, as in another embodiment, any one of the following technologies known in the art or a combination thereof can be used to implement: a discrete logic circuit having a logic gate circuit for implementing a logic function on a data signal, an application-specific integrated circuit having a suitable combination of logic gate circuits, a programmable gate array (PGA), a field programmable gate array (FPGA), etc.
[0212] Those skilled in the art will understand that all or part of the steps in the method of the above embodiment can be completed by instructing related hardware through a program, and the program can be stored in a computer-readable storage medium. When the program is executed, it includes one or a combination of the steps of the method embodiment.
[0213] In addition, the functional units in the various embodiments of the present disclosure may be integrated into a single processing module, or each unit may exist physically separately, or two or more units may be integrated into a single module. The aforementioned integrated modules may be implemented in the form of hardware or in the form of software functional modules. If the integrated modules are implemented in the form of software functional modules and sold or used as independent products, they may also be stored in a computer-readable storage medium.
[0214] The storage medium mentioned above may be a read-only memory, a magnetic disk, or an optical disk, etc. Although the embodiments of the present disclosure have been shown and described above, it is understood that the above embodiments are exemplary and should not be construed as limiting the present disclosure. A person of ordinary skill in the art may make changes, modifications, substitutions, and variations to the above embodiments within the scope of the present disclosure.
Claims
1. A business processing method, characterized in that: Applied to the production side, including: In response to receiving the target transaction request, opening a database transaction and executing a first business operation associated with the target transaction request to obtain target business data; Assembling or encapsulating the target service data to obtain a structured first message; Acquire configuration information, wherein the configuration information includes first identification information of the target database, second identification information of the message table, and third identification information of the business table; determining, according to the first identification information, a target database matching the first identification information from at least one database; determining, from at least one data table in the target database, a message table that matches the second identification information, and determining a service table that matches the third identification information; Inserting the first message into the message table, and inserting the target service data into the service table; In response to the successful insertion of the first message and the target business data, the first message in the target database is sent to the message middleware, so that the consumer end pulls the first message from the message middleware and executes the second business operation associated with the target transaction request according to the first message.
2. The method according to claim 1, characterized in that In response to the first message and the target business data being successfully inserted, after sending the first message in the target database to the message middleware, the method further includes: Sending a second message to the message middleware; wherein the second message carries a message identifier and a first target time of the first message, and the first target time is determined according to the sending time of the first message; Obtaining the second message sent by the message middleware in response to reaching the first target time; According to the message identifier in the second message, the first message matching the message identifier is deleted from the message table in the target database.
3. The method according to claim 1, characterized in that The method further comprises: Determine whether the current moment meets the set conditions; When the current moment satisfies the set condition, deleting messages in the message table that have been stored for longer than the set time period; The set condition includes any one of the following: reaching the set period; reaching the second target time; The number of transaction requests received during the time period of the second target moment is less than a first set threshold, or the number of messages or business data inserted into the target database during the time period of the second target moment is less than a second set threshold.
4. The method according to claim 1, wherein When both the first message and the target service data are successfully inserted, the method further includes: The state of the first message in the target database is set to a waiting-to-send state.
5. The method according to any one of claims 1 to 4, characterized in that After inserting the first message and the target service data into the target database, the method further includes: In response to a failure in inserting the first message and / or a failure in inserting the target business data, the database transaction is rolled back to delete the first message and the target business data.
6. The method according to any one of claims 1 to 4, characterized in that The sending the first message in the target database to the message middleware includes: determining a target topic to which the first message belongs according to a second business operation associated with the target transaction request; Publishing the first message in the target database in a waiting-to-send state to the target topic of the message middleware; The first message under the target topic is used for a consumer that subscribes to the target topic to pull the first message from the target topic and perform a second business operation associated with the target topic according to the first message.
7. The method according to claim 6, characterized in that After publishing the first message in the target database in a waiting-to-send state to the target topic of the message middleware, the method further includes: Determining whether first feedback information sent by the message middleware is received within a set period after a third target time; wherein the first feedback information is used to indicate that the message middleware has received the first message, and the third target time is the time when the first message is published; If the first feedback message is received, changing the state of the first message in the target database from a pending state to a successfully sent state, and committing the database transaction; If the first feedback information is not received, changing the state of the first message in the target database from a waiting-to-send state to a failed-to-send state; The first message in the target database that is in a failed sending state is resent to the target topic of the message middleware.
8. The method according to claim 7, characterized in that After resending the first message in the target database that is in a failed sending state to the target topic of the message middleware, the method further includes: Determining whether second feedback information sent by the message middleware is received within a set period after a fourth target time; wherein the second feedback information is used to indicate that the message middleware has received the resent first message, and the fourth target time is the resending time of the first message; If the second feedback information is received, updating the state of the first message in the target database from a failed sending state to a successful sending state, and committing the database transaction; If the second feedback information is not received, the first message in the target database that is in a failed sending state is sent again to the target topic of the message middleware until the target feedback information sent by the message middleware is received, the state of the first message in the target database is updated from a failed sending state to a successful sending state, and the database transaction is committed; The target feedback information is used to indicate that the message middleware has received the first message.
9. A service processing device, characterized in that: Applied to the production side, including: An opening module, configured to open a database transaction in response to receiving a target transaction request; an execution module, configured to execute a first business operation associated with the target transaction request to obtain target business data; a processing module configured to assemble or encapsulate the target business data to obtain a structured first message; obtain configuration information, wherein the configuration information includes first identification information of a target database, second identification information of a message table, and third identification information of a business table; determine, based on the first identification information, a target database that matches the first identification information from at least one database; determine, from at least one data table in the target database, a message table that matches the second identification information, and a business table that matches the third identification information; insert the first message into the message table, and insert the target business data into the business table; A sending module is used to send the first message in the target database to the message middleware in response to the successful insertion of the first message and the target business data, so that the consumer end pulls the first message from the message middleware and performs a second business operation associated with the target transaction request according to the first message.
Citation Information
Patent Citations
Method and device for sending message corresponding to transaction
CN114281603A
Message queue proxy method and device
CN115334155A