Message idempotent processing method and device based on distributed system
By configuring unique constraints and indexes in the message record file, the problems introduced by middleware in the message idempotence processing in the prior art are solved, and efficient and independent idempotence processing is realized, reducing the cost and node exception rate.
Patent Information
- Application Number
- CN202411275932.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-12
- Publication Date
- 2024-12-31
AI Technical Summary
In the prior art, in order to ensure message idempotence, additional middleware Redis is needed, resulting in increased costs and high node abnormality rates, and the idempotent function is coupled with business data, affecting system stability.
By configuring unique constraints and indexes in the message record file, we can determine whether the consumption message is inserted for the first time. If the insertion is successful, the business logic will be executed and the status will be updated. If it fails, the record will be deleted to avoid directly interacting with the business table and use the message record file to record the file As an intermediate layer stripping idempotence check function.
It realizes the efficiency and simplicity of message idempotence processing, avoids the introduction of additional middleware, reduces costs, and reduces node exception rates, maintains the stability of the system and the independence of idempotence functions.
Smart Images

Figure CN119232695A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of smart home technology, and in particular to a message idempotent processing method and device based on a distributed system. Background Art
[0002] In computer science, idempotence means that after one or more operations, the results are the same and the existing state will not be changed again. Idempotence is a very important concept and is widely used in distributed systems, concurrency control, database operations and other fields.
[0003] At present, in order to ensure the idempotence of messages, a globally unique identity document (ID) is added to each message when the producer sends the message. When consuming, the corresponding ID is saved to the remote dictionary server (Remote Dictionary Server, Redis for short). Before each consumption, the corresponding message is searched in Redis, and consumption is performed only after ensuring that there is no corresponding message.
[0004] However, the above-mentioned solution of adding middleware Redis requires increasing costs and introducing additional middleware. Moreover, after adding the middleware, the process link is longer and the node abnormality rate is higher. Summary of the invention
[0005] The present application provides a message idempotent processing method and device based on a distributed system, which is used to solve the defect in the prior art that duplicate data appears in the business due to repeated message requests. It does not introduce additional middleware, avoids more nodes, and avoids direct interaction with the business table so that the idempotent function is coupled with the business data.
[0006] The present application provides a message idempotent processing method based on a distributed system, comprising: receiving a request sent by a message queue, the request containing a consumption message; based on the request, determining whether the consumption message can be inserted into a previously configured message log file; wherein the message log file is previously configured with a uniqueness constraint; based on the fact that the consumption message can be inserted into the message log file, inserting the consumption message into the message log file, and based on the consumption message, executing a corresponding business logic program, and determining whether the business logic program is successfully executed; based on the successful execution of the business logic program, updating the corresponding message consumption status in the message log file.
[0007] According to a message idempotent processing method based on a distributed system provided by the present application, before judging whether the consumption message can be inserted into a previously configured message record file based on the request, it includes: creating a message record table, the message record table includes a message identity, a message body, message fields and a message consumption status; adding unique constraints and indexes to the message fields to obtain a message record file.
[0008] According to a message idempotent processing method based on a distributed system provided by the present application, after determining whether the business logic program is executed successfully, it includes: based on the failure of the execution of the business logic program, deleting the record of the corresponding consumption message in the message record file.
[0009] According to a message idempotent processing method based on a distributed system provided by the present application, after deleting the record of the corresponding consumption message in the message log file based on the failure of the execution of the business logic program, it includes: storing the deleted consumption message in the message queue.
[0010] According to a message idempotent processing method based on a distributed system provided by the present application, after judging whether the consumption message can be inserted into a previously configured message log file based on the request, the method includes: based on the fact that the consumption message cannot be inserted into the message log file, searching the message log file according to the consumption message to obtain the corresponding message consumption status in the message log file; judging whether the corresponding message consumption status in the message log file obtained by searching is a successful consumption, and if so, ending; otherwise, re-storing it in the message queue.
[0011] According to a message idempotent processing method based on a distributed system provided by the present application, the request sent by the message queue is initiated after the consumption message generated by consumption is stored in the message queue.
[0012] The present application also provides a message idempotent processing device based on a distributed system, including: a request receiving module, receiving a request sent by a message queue, the request containing a consumption message; an insertion status judgment module, based on the request, judging whether the consumption message can be inserted into a previously configured message record file; wherein the message record file is previously configured with a uniqueness constraint; an execution status judgment module, based on the fact that the consumption message can be inserted into the message record file, inserting the consumption message into the message record file, and based on the consumption message, executing a corresponding business logic program, and judging whether the business logic program is executed successfully; a message update module, based on the successful execution of the business logic program, updating the corresponding message consumption status in the message record file.
[0013] The present application also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the message idempotent processing method based on a distributed system as described above is implemented.
[0014] The present application also provides a non-transitory computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the message idempotent processing method based on a distributed system as described in any one of the above is implemented.
[0015] The present application also provides a computer program product, including a computer program, which, when executed by a processor, implements any of the above-mentioned message idempotent processing methods based on a distributed system.
[0016] The message idempotence processing method and device based on a distributed system provided by the present application determines whether the consumption message carried in the request can be inserted into a message record file previously configured with a unique constraint based on a request sent by a received message queue, thereby determining that the consumption message is the first consumption when it is determined that it can be inserted, inserting the consumption message into the message record file, and executing the corresponding business logic program based on the consumption message to update the message consumption status of the corresponding consumption message in the message record file when the execution is successful. The idempotence verification function is separated by using the message record file as an intermediate layer so as not to be confused with the business, and is implemented through the unique index of the message record file without additional processing. While avoiding more nodes, it avoids direct interaction with the business table so as to couple the idempotence function with the business data. In addition, no additional middleware is required, which saves costs, and the business library can be directly reused, which is simple and efficient, and has a wide range of applications. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0018] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0019] Figure 1 It is a hardware environment diagram of a message idempotent processing method based on a distributed system according to an embodiment of the present application; Figure 2 This is one of the flow charts of the message idempotent processing method based on the distributed system provided by this application; Figure 3This is the second flow chart of the message idempotent processing method based on a distributed system provided by this application; Figure 4 It is a structural diagram of a message idempotent processing device based on a distributed system provided by the present application; Figure 5 It is a structural schematic diagram of the electronic device provided by this application. DETAILED DESCRIPTION
[0020] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only 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 should fall within the scope of protection of the present application.
[0021] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0022] According to one aspect of an embodiment of the present application, a message idempotence processing method based on a distributed system is provided. The message idempotence processing method based on a distributed system is widely used in smart home (Smart Home), smart home, smart home device ecology, smart residential (Intelligence House) ecology and other whole-house intelligent digital control application scenarios. Optionally, in this embodiment, the above-mentioned message idempotence processing method based on a distributed system can be applied to Figure 1 In the hardware environment composed of the terminal device 102 and the server 104 shown in FIG. Figure 1 As shown, the server 104 is connected to the terminal device 102 via a network, and can be used to provide services (such as application services, etc.) for the terminal or a client installed on the terminal. A database can be set on the server or independently of the server to provide data storage services for the server 104. Cloud computing and / or edge computing services can be configured on the server or independently of the server to provide data computing services for the server 104.
[0023] The network may include but is not limited to at least one of the following: wired network, wireless network. The wired network may include but is not limited to at least one of the following: wide area network, metropolitan area network, local area network, and the wireless network may include but is not limited to at least one of the following: WIFI (Wireless Fidelity), Bluetooth. The terminal device 102 may be but is not limited to a PC, a mobile phone, a tablet computer, a smart air conditioner, a smart range hood, a smart refrigerator, a smart oven, a smart stove, a smart washing machine, a smart water heater, a smart washing equipment, a smart dishwasher, a smart projection equipment, a smart TV, a smart clothes drying rack, a smart curtain, a smart audio and video, a smart socket, a smart speaker, a smart speaker, a smart fresh air equipment, a smart kitchen and bathroom equipment, a smart bathroom equipment, a smart sweeping robot, a smart window cleaning robot, a smart mopping robot, a smart air purification equipment, a smart steamer, a smart microwave oven, a smart kitchen treasure, a smart purifier, a smart water dispenser, a smart door lock, etc.
[0024] Figure 2 This is one of the flow charts of the message idempotent processing method based on the distributed system provided by the present invention, such as Figure 2 As shown, the method includes: S21, receiving a request sent by a message queue, wherein the request includes a consumption message; S22, based on the request, determining whether the consumption message can be inserted into a previously configured message record file; wherein the message record file is previously configured with a uniqueness constraint; S23, based on the fact that the consumption message can be inserted into the message record file, inserting the consumption message into the message record file, and executing the corresponding business logic program based on the consumption message, and determining whether the business logic program is executed successfully; S24, based on the successful execution of the business logic program, updating the corresponding message consumption status in the message record file.
[0025] It should be noted that the step numbers "S1N" in this specification do not represent the order of the message idempotent processing method based on the distributed system. Figure 3 The present invention describes the message idempotent processing method based on a distributed system.
[0026] Step S21, receiving a request sent by a message queue, wherein the request includes a consumption message.
[0027] In this embodiment, the request sent by the message queue is initiated after the consumption message generated based on consumption is stored in the message queue.
[0028] Furthermore, the consumption information contained in the request is generated after the newly generated consumption information is stored in the message queue and based on the consumption message that is first stored in the time window of the message queue. The request is initiated after the consumption message is received through the message queue. This can not only send the first stored message in chronological order to ensure the message order, but also limit the number of messages sent each time by controlling the time window to avoid being overwhelmed by receiving too many messages in a short period of time, thereby ensuring the stability and reliability of the system, and helping to maintain the consistency of related data processing and reduce data inconsistency problems caused by disorder.
[0029] It should be noted that the execution subject of this method is the server. When consumption information is generated, the consumption information is sent to the message queue (MQ) for storage; after the message queue receives the consumption information, it generates a request based on its time window and the first stored consumption information, and sends the generated request to the server; the server receives the request.
[0030] In an optional embodiment, before determining whether the consumption message can be inserted into a previously configured message record file based on the request, it includes: creating a message record table, the message record table including a message identity, a message body, message fields and a message consumption status; adding a unique constraint and an index to the message field to obtain a message record file.
[0031] It should be noted that by adding a unique constraint to the message field, the idempotence verification function can be separated through the message log file as an intermediate layer, so as not to be confused with the business, and implemented through the unique index of the message log file without additional processing. While avoiding more nodes, it avoids direct interaction with the business table so that the idempotence function is coupled with the business data. In addition, no additional middleware is required, which saves costs and can directly reuse the business library, which is simple and efficient and has a wide range of applications.
[0032] Specifically, adding a unique constraint and an index to the message field includes: adding a unique constraint to the message field of the message record table to ensure that the value of the field is unique; adding an index to the message field of the message record table to speed up query and sort operations on the field.
[0033] Specifically, adding a unique constraint to the message field of the message record table includes: using the CONSTRAINT keyword to set a unique constraint for the message field of the message record table, and specifying a name for the set unique constraint.
[0034] It should be noted that after creating the message record table, a unique constraint is added to the message field of the message record table to ensure that the value of the message field is unique in the message record table, thereby avoiding duplicate messages to ensure data consistency and accuracy, and preventing multiple insertions of the same message, reducing unnecessary data storage, saving storage space, and ensuring data quality and accuracy through unique constraints, reducing the possibility of errors; in addition, by creating an index for the message field of the message record table, it helps to speed up the query and connection operations on the field, so that it can quickly locate when looking for consumer messages, improve the speed of data retrieval, and improve the operation performance of the corresponding fields.
[0035] In another optional embodiment, before determining whether the consumption message can be inserted into a previously configured message record file based on the request, it includes: creating a message record table, and setting a unique constraint and index when creating the message record table; wherein the message record table includes a message identity, a message body, message fields, and a message consumption status.
[0036] It should be added that when creating the message record table, the uniqueness constraint and index can be set by referring to the above description of adding uniqueness constraints and indexes to the message fields, which will not be repeated here. In addition, by setting uniqueness constraints and indexes for the created message record table when creating the message record table, it is ensured that the value of the message field is unique in the message record table, thereby avoiding the duplication of messages to ensure the consistency and accuracy of the data, and preventing multiple insertions of the same message, reducing unnecessary data storage, saving storage space, and ensuring the quality and accuracy of the data through uniqueness constraints, and reducing the possibility of errors; in addition, by creating an index for the message field of the message record table, it helps to speed up the query and connection operations on the field, so that it can quickly locate when searching for consumer messages, improve the speed of data retrieval, and improve the operation performance of the corresponding fields.
[0037] Step S22: Based on the request, determine whether the consumption message can be inserted into a previously configured message record file; wherein the message record file is previously configured with a uniqueness constraint.
[0038] In this embodiment, based on the request, it is determined whether the consumption message can be inserted into the previously configured message record file, including: based on the request, obtaining the consumption message; according to the consumption message, using the index of the message record file to find out whether there is a corresponding consumption message in the message record file; if there is no corresponding consumption message in the message record file, it is determined that the consumption message can be inserted into the message record file; otherwise, it is determined that the consumption message cannot be inserted into the message record file.
[0039] It should be added that when searching for a corresponding consumption message in the message record file using an index of the message record file according to the consumption message, the message record file may be queried based on the message identity identifier.
[0040] In addition, if it is determined that the consumption message can be inserted into the message record file, it indicates that the consumption message is consumed for the first time and the subsequent business logic program can be executed; otherwise, it proves that the consumption message has been consumed or is being consumed.
[0041] In an optional embodiment, after determining whether the consumption message can be inserted into the previously configured message record file based on the request, the following steps are performed: based on the fact that the consumption message cannot be inserted into the message record file, searching the message record file according to the consumption message to obtain the corresponding message consumption status in the message record file; determining whether the corresponding message consumption status in the message record file obtained is a successful consumption, and if so, ending the process; otherwise, re-storing the message in the message queue.
[0042] It should be noted that when the consumption message cannot be inserted into the message record file, the message consumption status in the corresponding message record table is determined to determine whether the consumption message has been consumed or is being consumed. If the consumption message has been consumed, the process ends; otherwise, the process is re-stored in the message queue to wait for the time window based on the message queue and re-execute the steps of this method.
[0043] Step S23, based on the fact that the consumption message can be inserted into the message record file, the consumption message is inserted into the message record file, and based on the consumption message, the corresponding business logic program is executed, the consumption message is inserted into the message record file, and it is determined whether the business logic program is executed successfully.
[0044] It should be noted that the business logic program is determined according to the usage requirements of the consumption message, and no further limitation is made here. For example, if the consumption message needs to be further analyzed, the business logic program is data processing and analysis, that is, the consumption message is extracted, converted and loaded to integrate the consumption message into the database for data analysis and report generation; for another example, it is necessary to give users discounts or upgrade membership levels based on consumption messages, then the business logic program is rule judgment and decision-making, that is, judgment is made based on the content of the consumption message and the preset rules, so as to make corresponding decisions. For another example, it is necessary to notify and remind relevant personnel based on the consumption message, then the business logic program is notification and reminder, that is, the complaint information submitted by the consumer is consumed, and a reminder notification is sent to the customer service staff.
[0045] Step S24: based on the successful execution of the business logic program, update the corresponding message consumption status in the message record file.
[0046] In an optional embodiment, after determining whether the business logic program is executed successfully, the method further includes: based on the failure of the business logic program to execute, deleting the record corresponding to the consumption message in the message record file.
[0047] Specifically, after deleting the record of the corresponding consumption message in the message record file based on the failure of the execution of the business logic program, the method further includes: storing the deleted consumption message in the message queue.
[0048] To summarize, the embodiment of the present invention determines whether the consumption message carried in the request can be inserted into the message record file previously configured with a unique constraint based on the request sent by the received message queue, and thus determines that the consumption message is the first consumption when it is determined that it can be inserted, inserts the consumption message into the message record file, and executes the corresponding business logic program based on the consumption message to update the message consumption status of the corresponding consumption message in the message record file when the execution is successful. The idempotence verification function is separated by using the message record file as an intermediate layer so as not to be confused with the business, and is implemented through the unique index of the message record file without additional processing. While avoiding more nodes, it avoids direct interaction with the business table so as to couple the idempotence function with the business data. In addition, no additional middleware is required, which saves costs, and the business library can be directly reused, which is simple and efficient, and has a wide range of applications.
[0049] The message idempotence processing device based on a distributed system provided by the present invention is described below. The message idempotence processing device based on a distributed system described below and the message idempotence processing method based on a distributed system described above can be referred to each other.
[0050] Figure 4 A schematic diagram of the structure of a message idempotent processing device based on a distributed system is shown, and the device includes: A request receiving module 41 receives a request sent by a message queue, wherein the request includes a consumption message; The insertion state judgment module 42 judges whether the consumption message can be inserted into a previously configured message record file based on the request; wherein the message record file is previously configured with a uniqueness constraint; An execution status judgment module 43 inserts the consumption message into the message record file based on the fact that the consumption message can be inserted into the message record file, executes a corresponding business logic program based on the consumption message, and judges whether the business logic program is executed successfully; The message updating module 44 updates the corresponding message consumption status in the message record file based on the successful execution of the business logic program.
[0051] It should be noted that the business logic program is determined according to the usage requirements of the consumption message, and no further limitation is made here. For example, if the consumption message needs to be further analyzed, the business logic program is data processing and analysis, that is, the consumption message is extracted, converted and loaded to integrate the consumption message into the database for data analysis and report generation; for another example, it is necessary to give users discounts or upgrade membership levels based on consumption messages, then the business logic program is rule judgment and decision-making, that is, judgment is made based on the content of the consumption message and the preset rules, so as to make corresponding decisions. For another example, it is necessary to notify and remind relevant personnel based on the consumption message, then the business logic program is notification and reminder, that is, the complaint information submitted by the consumer is consumed, and a reminder notification is sent to the customer service staff.
[0052] In this embodiment, the request sent by the message queue is initiated after the consumption message generated based on consumption is stored in the message queue.
[0053] Furthermore, the consumption information contained in the request is generated after the newly generated consumption information is stored in the message queue and based on the consumption message that is first stored in the time window of the message queue. The request is initiated after the consumption message is received through the message queue. This can not only send the first stored message in chronological order to ensure the message order, but also limit the number of messages sent each time by controlling the time window to avoid being overwhelmed by receiving too many messages in a short period of time, thereby ensuring the stability and reliability of the system, and helping to maintain the consistency of related data processing and reduce data inconsistency problems caused by disorder.
[0054] It should be noted that the execution subject of this method is the server. When consumption information is generated, the consumption information is sent to the message queue (MQ) for storage; after the message queue receives the consumption information, it generates a request based on its time window and the first stored consumption information, and sends the generated request to the server; the server receives the request.
[0055] In an optional embodiment, the device also includes: a table creation module, which creates a message record table before determining whether the consumption message can be inserted into a previously configured message record file based on the request, wherein the message record table includes a message identity, a message body, message fields, and a message consumption status; and a table configuration module, which adds unique constraints and indexes to the message fields to obtain a message record file.
[0056] It should be noted that by adding a unique constraint to the message field, the idempotence verification function can be separated through the message log file as an intermediate layer, so as not to be confused with the business, and implemented through the unique index of the message log file without additional processing. While avoiding more nodes, it avoids direct interaction with the business table so that the idempotence function is coupled with the business data. In addition, no additional middleware is required, which saves costs and can directly reuse the business library, which is simple and efficient and has a wide range of applications.
[0057] Specifically, the table configuration module includes: a constraint setting unit, which adds a unique constraint to the message field of the message record table to ensure that the value of the field is unique; an index creation unit, which adds an index to the message field of the message record table to speed up query and sort operations on the field.
[0058] Specifically, the constraint setting unit is used to: use the CONSTRAINT keyword to set a uniqueness constraint for the message field of the message record table, and specify a name for the set uniqueness constraint.
[0059] It should be noted that after creating the message record table, a unique constraint is added to the message field of the message record table to ensure that the value of the message field is unique in the message record table, thereby avoiding duplicate messages to ensure data consistency and accuracy, and preventing multiple insertions of the same message, reducing unnecessary data storage, saving storage space, and ensuring data quality and accuracy through unique constraints, reducing the possibility of errors; in addition, by creating an index for the message field of the message record table, it helps to speed up the query and connection operations on the field, so that it can quickly locate when looking for consumer messages, improve the speed of data retrieval, and improve the operation performance of the corresponding fields.
[0060] In another optional embodiment, the device further includes: a table creation module, which creates a message record table before determining whether the consumption message can be inserted into a previously configured message record file based on the request, and sets a unique constraint and index when creating the message record table; wherein the message record table includes a message identity, a message body, a message field, and a message consumption status.
[0061] It should be added that when creating the message record table, the uniqueness constraint and index can be set by referring to the above description of adding uniqueness constraints and indexes to the message fields, which will not be repeated here. In addition, by setting uniqueness constraints and indexes for the created message record table when creating the message record table, it is ensured that the value of the message field is unique in the message record table, thereby avoiding the duplication of messages to ensure the consistency and accuracy of the data, and preventing multiple insertions of the same message, reducing unnecessary data storage, saving storage space, and ensuring the quality and accuracy of the data through uniqueness constraints, and reducing the possibility of errors; in addition, by creating an index for the message field of the message record table, it helps to speed up the query and connection operations on the field, so that it can quickly locate when searching for consumer messages, improve the speed of data retrieval, and improve the operation performance of the corresponding fields.
[0062] In this embodiment, the insertion status judgment module 42 includes: a message acquisition unit, which acquires the consumption message based on the request; a query unit, which uses the index of the message record file to find out whether there is a corresponding consumption message in the message record file according to the consumption message; a result determination unit, which determines that the consumption message can be inserted into the message record file if there is no corresponding consumption message in the message record file; otherwise, determines that the consumption message cannot be inserted into the message record file.
[0063] It should be added that when searching for a corresponding consumption message in the message record file using an index of the message record file according to the consumption message, the message record file may be queried based on the message identity identifier.
[0064] In addition, if it is determined that the consumption message can be inserted into the message record file, it indicates that the consumption message is consumed for the first time and the subsequent business logic program can be executed; otherwise, it proves that the consumption message has been consumed or is being consumed.
[0065] In an optional embodiment, the device further includes: a status search module, which determines whether the consumption message can be inserted into the previously configured message record file based on the request, and searches the message record file according to the consumption message based on the fact that the consumption message cannot be inserted into the message record file to obtain the corresponding message consumption status in the message record file; a status judgment module, which determines whether the corresponding message consumption status in the message record file obtained by the search is a successful consumption, and if so, ends the process; otherwise, re-stores the message in the message queue.
[0066] It should be noted that when the consumption message cannot be inserted into the message record file, the message consumption status in the corresponding message record table is determined to determine whether the consumption message has been consumed or is being consumed. If the consumption message has been consumed, the process ends; otherwise, the process is re-stored in the message queue to wait for the time window based on the message queue and re-execute the steps of this method.
[0067] In an optional embodiment, the device further includes: a message deletion module, after determining whether the business logic program is executed successfully, based on the failure of the business logic program to execute, deletes the record corresponding to the consumption message in the message record file.
[0068] Furthermore, the device also includes: a message storage module, which stores the deleted consumption message in the message queue after deleting the record of the corresponding consumption message in the message record file based on the failure of the execution of the business logic program.
[0069] To summarize, the embodiment of the present invention determines whether the consumption message carried in the request can be inserted into the message record file previously configured with a unique constraint based on the request sent by the message queue received by the request receiving module through the insertion status judgment module, so that when it is determined that the insertion can be performed, the consumption message is determined to be the first consumption, the consumption message is inserted into the message record file, and based on the consumption message, the corresponding business logic program is executed, so that when the execution is successful, the message consumption status of the corresponding consumption message in the message record file is updated through the message update module, and the idempotence verification function is separated by using the message record file as the intermediate layer, so as not to be confused with the business, and is implemented through the unique index of the message record file without additional processing. While avoiding more nodes, it avoids direct interaction with the business table so that the idempotence function is coupled with the business data; in addition, no additional middleware is required, which saves costs, and the business library can be directly reused, which is simple and efficient, and has a wide range of applications.
[0070] Figure 5 An example of a physical structure diagram of an electronic device is shown in FIG. Figure 5As shown, the electronic device may include: a processor 510, a communication interface 520, a memory 530 and a communication bus 540, wherein the processor 510, the communication interface 520 and the memory 530 communicate with each other through the communication bus 540. The processor 510 may call the logic instructions in the memory 530 to execute a message idempotent processing method based on a distributed system, the method comprising: receiving a request sent by a message queue, the request including a consumption message; based on the request, determining whether the consumption message can be inserted into a previously configured message log file; based on the consumption message being able to be inserted into the message log file, inserting the consumption message into the message log file, and based on the consumption message, executing a corresponding business logic program, and determining whether the business logic program is executed successfully; based on the success of the execution of the business logic program, updating the corresponding message consumption status in the message log file.
[0071] In addition, the logic instructions in the above-mentioned memory 530 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on this understanding, the technical solution of the present application can be essentially or partly embodied in the form of a software product that contributes to the prior art. The computer software product is stored in a storage medium, including several instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, etc. Various media that can store program codes.
[0072] On the other hand, the present application also provides a computer program product, which includes a computer program. The computer program can be stored on a computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the message idempotent processing method based on a distributed system provided by the above-mentioned methods, and the method includes: receiving a request sent by a message queue, and the request includes a consumption message; based on the request, determining whether the consumption message can be inserted into a previously configured message record file; based on the fact that the consumption message can be inserted into the message record file, inserting the consumption message into the message record file, and based on the consumption message, executing the corresponding business logic program, and determining whether the business logic program is executed successfully; based on the successful execution of the business logic program, updating the corresponding message consumption status in the message record file.
[0073] On the other hand, the present application also provides a computer-readable storage medium, which includes a stored program, wherein when the program is running, the message idempotent processing method based on a distributed system provided by the above-mentioned methods is executed, and the method includes: receiving a request sent by a message queue, and the request includes a consumption message; based on the request, determining whether the consumption message can be inserted into a previously configured message record file; based on the fact that the consumption message can be inserted into the message record file, inserting the consumption message into the message record file, and based on the consumption message, executing the corresponding business logic program, and determining whether the business logic program is executed successfully; based on the successful execution of the business logic program, updating the corresponding message consumption status in the message record file.
[0074] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.
[0075] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0076] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application.
Claims
1. A message idempotent processing method based on a distributed system, characterized in that: include: Receive a request sent by a message queue, wherein the request includes a consumption message; Based on the request, determining whether the consumption message can be inserted into a previously configured message record file; wherein the message record file is previously configured with a uniqueness constraint; Based on the fact that the consumption message can be inserted into the message record file, inserting the consumption message into the message record file, and executing the corresponding business logic program based on the consumption message, and determining whether the business logic program is executed successfully; Based on the successful execution of the business logic program, the corresponding message consumption status in the message record file is updated.
2. The message idempotent processing method based on a distributed system according to claim 1 is characterized in that: Before determining whether the consumption message can be inserted into a previously configured message log file based on the request, the method includes: Create a message record table, the message record table includes a message identity, a message body, a message field and a message consumption status; A unique constraint and an index are added to the message field to obtain a message record file.
3. The message idempotent processing method based on a distributed system according to claim 1 is characterized in that: After determining whether the business logic program is executed successfully, the following steps are included: Based on the failure of the execution of the business logic program, the record of the corresponding consumption message in the message record file is deleted.
4. The message idempotent processing method based on a distributed system according to claim 3 is characterized in that: After deleting the record of the corresponding consumption message in the message record file based on the failure of the execution of the business logic program, the method includes: The deleted consumption message is stored in the message queue.
5. The message idempotent processing method based on a distributed system according to claim 1 is characterized in that: After determining whether the consumption message can be inserted into a previously configured message log file based on the request, the method further comprises: Based on the fact that the consumption message cannot be inserted into the message record file, searching the message record file according to the consumption message to obtain the corresponding message consumption status in the message record file; Determine whether the corresponding message consumption status in the searched message record file is consumption success, if so, end; otherwise, store it again in the message queue.
6. The message idempotent processing method based on a distributed system according to claim 1 is characterized in that: The request sent by the message queue is initiated after the consumption message generated based on consumption is stored in the message queue.
7. A message idempotent processing device based on a distributed system, characterized in that: include: A request receiving module receives a request sent by a message queue, wherein the request includes a consumption message; An insertion status judgment module, based on the request, judges whether the consumption message can be inserted into a previously configured message record file; wherein the message record file is previously configured with a uniqueness constraint; An execution status judgment module, based on the fact that the consumption message can be inserted into the message record file, inserts the consumption message into the message record file, executes the corresponding business logic program based on the consumption message, and judges whether the business logic program is executed successfully; The message update module updates the corresponding message consumption status in the message record file based on the successful execution of the business logic program.
8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the message idempotent processing method based on a distributed system as described in any one of claims 1 to 6 is implemented.
9. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the message idempotent processing method based on a distributed system as claimed in any one of claims 1 to 6 is implemented.
10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the message idempotent processing method based on a distributed system as claimed in any one of claims 1 to 6 is implemented.
