A method and apparatus for message processing

By locking the service ID on instances in the distributed cluster, the problems of inefficient message processing and lock conflict in the distributed cluster are solved, and more efficient and accurate message processing is achieved.

CN113377795BActive Publication Date: 2025-03-18BEIJING WODONG TIANJUN INFORMATION TECH CO LTD +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202110700492.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-06-23
Publication Date
2025-03-18
Estimated Expiration
2041-06-23

AI Technical Summary

Technical Problem

In a distributed cluster, when business data changes to a certain data table in the database, each instance may receive duplicate change messages, resulting in inefficient message processing and distributed lock conflicts.

Method used

By locking instances in a distributed cluster based on data identification (service ID), and using the locked instances to process multiple pending messages, the number of retry times is reduced and distributed lock conflicts are avoided.

Benefits of technology

It effectively reduces the number of retry times, avoids distributed lock conflicts, improves message processing efficiency, and improves message processing accuracy through the attribute value setting of distributed locks.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113377795B_ABST
    Figure CN113377795B_ABST
Patent Text Reader

Abstract

The present invention discloses a method and device for message processing, and relates to the field of computer technology. A specific implementation of the method includes: using one or more instances in a distributed cluster to respectively receive multiple pending messages triggered by a database, and the multiple pending messages correspond to the same data identifier; performing distributed locking processing on the one or more instances according to the data identifier to obtain the attribute value of the distributed lock; using the locked first instance to process the received multiple pending messages to process the data stored in itself according to the data in the database; using the unlocked second instance to update the attribute value of the distributed lock; when the attribute values ​​of the distributed locks of the first instance and the second instance are different, synchronizing the data in the first instance and the second instance. This implementation reduces the number of retries, avoids distributed lock conflicts, and improves message processing efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a message processing method and device. Background Art

[0002] In a distributed cluster, for changes to the business data of a data table in the database, each instance in the distributed cluster may receive a change message about the data table triggered by the database. When each instance processes these change messages, it usually does so in the following way: for multiple messages with the same business ID, each instance retries the multiple messages one by one based on the business ID. In other words, each instance repeatedly processes multiple change messages corresponding to the same business ID, resulting in low message processing efficiency.

[0003] Furthermore, when the instance is processing these change messages, if the data changes again, each instance will receive the change message again. After the messages are superimposed, the number of invalid retries will increase, further reducing the efficiency of message processing. Summary of the Invention

[0004] In view of this, an embodiment of the present invention provides a message processing method and device, which can lock the instances in the distributed cluster according to the data identifier (business ID), and then use the locked instance to process the multiple pending messages received, effectively reducing the number of retries, avoiding distributed lock conflicts, and improving message processing efficiency. At the same time, the accuracy of message processing is improved by setting the attribute value of the distributed lock.

[0005] To achieve the above object, according to one aspect of an embodiment of the present invention, a message processing method is provided, comprising:

[0006] Using one or more instances in the distributed cluster to respectively receive a plurality of to-be-processed messages triggered by a database, wherein the plurality of to-be-processed messages correspond to the same data identifier;

[0007] Performing distributed locking processing on the one or more instances according to the data identifier to obtain attribute values ​​of the distributed lock;

[0008] Using the locked first instance to process the received multiple messages to be processed, so as to process the data stored in the database according to the data;

[0009] Update the attribute value of the distributed lock using the second unlocked instance;

[0010] When the attribute values ​​of the distributed locks of the first instance and the second instance are different, data in the first instance and the second instance are synchronized.

[0011] Optionally, the processing the received multiple to-be-processed messages using the locked first instance includes:

[0012] The first instance is used to perform deduplication processing on the multiple messages to be processed received according to the data identifier, and the data stored in the self is processed according to the deduplication processing result and the data in the database.

[0013] Optionally, processing the stored data according to the deduplication processing result and the data in the database includes:

[0014] According to the data identifier indicated by the deduplication processing result, obtaining a data table corresponding to the data identifier from the database;

[0015] The data stored in the self-stored data is updated according to the acquired data table.

[0016] Optionally, performing distributed locking processing on the one or more instances according to the data identifier to obtain attribute values ​​of the distributed lock includes:

[0017] A random number is generated for the data identifier, distributed locking processing is performed on the one or more instances according to the random number, and the random number is used as the attribute value.

[0018] Optionally, when the second instance receives the data update message triggered by the database again, the attribute value of the distributed lock is updated again using the second instance.

[0019] Optionally, using the second instance to update the attribute value of the distributed lock includes:

[0020] The distributed attribute value is incremented using the second instance.

[0021] Optionally, synchronizing data in the first instance and the second instance includes:

[0022] According to the sizes of the attribute values ​​of the distributed locks corresponding to the first instance and the second instance respectively, a data synchronization source is determined from the first instance and the second instance, and data is synchronized according to the data in the data synchronization source.

[0023] According to a second aspect of an embodiment of the present invention, a message processing apparatus is provided, including:

[0024] a receiving module, a first processing module, a determining module, a second processing module, a third processing module, and a fourth processing module; wherein,

[0025] The receiving module is configured to receive a plurality of to-be-processed messages triggered by a database respectively received by one or more instances in a distributed cluster;

[0026] The first processing module performs distributed locking processing on the one or more instances according to the data identifier to obtain a property value of the distributed lock;

[0027] The second processing module processes the received plurality of to-be-processed messages using the locked first instance, so as to process the data stored in the second processing module according to the data in the database;

[0028] The third processing module updates the attribute value of the distributed lock using the unlocked second instance;

[0029] The determination module is configured to determine whether the attribute values ​​of the distributed locks of the first instance and the second instance are different. If so, the fourth processing module is triggered; if not, the process is terminated.

[0030] The fourth processing module is configured to synchronize data in the first instance and the second instance.

[0031] According to a third aspect of an embodiment of the present invention, there is provided an electronic device for message processing, including:

[0032] one or more processors;

[0033] a storage device for storing one or more programs,

[0034] When the one or more programs are executed by the one or more processors, the one or more processors implement any one of the message processing methods provided in the first aspect above.

[0035] According to a fourth aspect of an embodiment of the present invention, a computer-readable medium is provided, on which a computer program is stored. When the program is executed by a processor, any method in the message processing method provided in the first aspect is implemented.

[0036] An embodiment of the above invention has the following advantages or beneficial effects: the instance in the distributed cluster is locked according to the data identifier (business ID), and the locked instance is used to process the multiple pending messages received, which effectively reduces the number of retries, avoids distributed lock conflicts, and improves message processing efficiency. At the same time, the accuracy of message processing is improved by setting the attribute value of the distributed lock.

[0037] The further effects of the above-mentioned non-conventional optional manner will be described below in conjunction with specific embodiments. BRIEF DESCRIPTION OF THE DRAWINGS

[0038] The accompanying drawings are provided for a better understanding of the present invention and are not intended to limit the present invention.

[0039] Figure 1 This is a schematic flow chart of a message processing method according to the first embodiment of the present invention;

[0040] Figure 2 is a schematic flow chart of a message processing method corresponding to the second embodiment of the present invention;

[0041] Figure 3 is a schematic diagram of main modules of a message processing apparatus according to an embodiment of the present invention;

[0042] Figure 4 is an exemplary system architecture diagram in which embodiments of the present invention may be applied;

[0043] Figure 5 It is a schematic diagram of the structure of a computer system of a terminal device or a server suitable for implementing an embodiment of the present invention. DETAILED DESCRIPTION

[0044] The following description of exemplary embodiments of the present invention is made in conjunction with the accompanying drawings, in which various details of the embodiments of the present invention are included to facilitate understanding. These details should be considered as merely exemplary. Therefore, it should be appreciated by those skilled in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for the sake of clarity and conciseness, descriptions of well-known functions and structures are omitted in the following description.

[0045] Figure 1 This is a schematic flow chart of the message processing method corresponding to the first embodiment of the present invention. Figure 1 As shown, the method includes the following steps S101 to S104:

[0046] Step S101: using one or more instances in a distributed cluster to respectively receive a plurality of to-be-processed messages triggered by a database, wherein the plurality of to-be-processed messages correspond to the same data identifier.

[0047] In the case of multiple data sources, complete business data may be stored in multiple data tables, and multiple messages to be processed may be messages of different types, but the subsequent processing process is the same. Therefore, in one embodiment of the present invention, taking the receipt of database change messages sent by multiple data tables as an example, the message processing method provided by the embodiment of the present invention is described in detail.

[0048] In addition, the to-be-processed messages with the same data identifier are received by one or more instances in the distributed cluster respectively. In one embodiment of the present invention, the data identifier of the to-be-processed message may be a service ID.

[0049] In addition, for multiple messages received from the same instance, duplicates are removed based on the data identifiers of the messages to be processed, that is, multiple messages are removed based on the business ID.

[0050] For example, when the message processing method provided by an embodiment of the present invention is applied to an e-commerce scenario, during a message processing session, a business ID is often associated with many products with the same business ID. When many products are added at once, many product insertion messages are received simultaneously, representing message changes for the same business ID. In this case, multiple messages can be deduplicated based on the business ID. This deduplication process effectively reduces the number of messages to be processed and improves message processing efficiency.

[0051] An instance can be a server in a distributed cluster or a program running on a server that receives pending messages, acquires a distributed lock, and processes pending messages.

[0052] Step S102: Perform distributed locking processing on one or more instances according to the data identifier to obtain attribute values ​​of the distributed lock.

[0053] In one embodiment of the present invention, distributed locking is performed on one or more instances based on a data identifier, including: generating an arbitrary random number (the random number can be set according to actual needs) for the data identifier, performing distributed locking on one or more instances based on the random number, and using the random number as an attribute value.

[0054] For example, during a message processing, a distributed lock for a business ID has been acquired. A random number within 10,000 (for example only) is obtained, and the generated random number is used as the attribute value of the distributed lock. The instance of the lock for the business ID is locked. The attribute value of the distributed lock can be used to represent the update status information of the data corresponding to the current business ID, which helps to compare the attribute values ​​obtained by different instances for the same business ID in the future, and synchronize the data in the first instance and the second instance based on the comparison results.

[0055] Step S103: using the locked first instance to process the received multiple messages to be processed, so as to process the data stored in the instance according to the data in the database.

[0056] In one embodiment of the present invention, processing the received multiple messages to be processed includes:

[0057] Using the deduplication processing result of the first instance and the data in the database, according to the data identifier indicated by the deduplication processing result, the data table corresponding to the data identifier is obtained from the database, and the data stored in itself is updated according to the obtained data table.

[0058] For example, during a message processing session, an instance deduplicated the messages to be processed based on the business ID. Using the business ID corresponding to the deduplicated message, the instance retrieved complete business information from the database and updated its stored data based on the obtained complete business information. This step, querying the database based on the business ID to obtain complete business information, helps capture all modified data and improves message processing accuracy.

[0059] Step S104: using the unlocked second instance to update the attribute value of the distributed lock;

[0060] In one embodiment of the present invention, when the second instance receives the data update message triggered by the database again, the attribute value of the distributed lock is updated again using the second instance.

[0061] Specifically, when the second instance receives the data update message from the database again, the attribute value of the distributed lock is incremented.

[0062] For example, during a certain message processing, after the first instance performs a distributed lock locking process, the current cached value of the attribute value of the distributed lock corresponding to the second instance that is not locked is incremented by 1 (it should be noted that the above-mentioned incrementing by 1 is only an example, and its purpose is to distinguish the attribute values ​​of the distributed locks corresponding to the second instance and the first instance, so as to facilitate the subsequent synchronization update of the local data corresponding to the second instance with different attribute values). In the process of the first instance processing the data stored in itself, if the second instance receives the update message corresponding to the above-mentioned business ID again, the attribute value of the distributed lock of the second instance is incremented again (similarly, the incrementing process is also an example, and its purpose is to indicate that the data corresponding to the business ID has generated a new change message again in the process of the first instance processing the data stored in itself). The above settings help to determine the data synchronization source and the second instance that needs to be synchronized by comparing the attribute values ​​of the distributed locks corresponding to the first instance and the second instance respectively, and synchronize data for the second instance. It also helps to determine whether the business ID generates new change messages (i.e., new pending messages) when the business ID updates the corresponding data in the first instance and the second instance synchronizes the updated data of the first instance.

[0063] Step S105: When the attribute values ​​of the distributed locks of the first instance and the second instance are different, data in the first instance and the second instance are synchronized.

[0064] Through the above settings, only the locked first instance needs to process the pending message to realize the update of the local message. For the second instance of the business ID that is not locked (it can be understood that the number of second instances can be multiple), it is only necessary to compare the attribute values ​​of the distributed system to determine the data source that needs to be synchronized, thereby realizing data synchronization.

[0065] In one embodiment of the present invention, synchronizing data in a first instance and a second instance includes:

[0066] Since the attribute value of the distributed lock corresponding to the second instance has been incremented (or incremented) at least once, before the data in the second instance is synchronized, the attribute values ​​of the distributed locks corresponding to the first instance and the second instance are different. At this time, the data synchronization source is determined from the first instance and the second instance based on the attribute values ​​of the distributed locks corresponding to the first instance and the second instance respectively, and the data is synchronized based on the data in the data synchronization source.

[0067] Specifically, using the first instance as the synchronization data source, the data of the first instance is synchronized to the second data source, and the distributed lock attribute value of the first instance is also synchronized to the second instance. Through the above settings, while synchronizing the corresponding data in the second instance, the attribute value corresponding to the second instance is also synchronized. It can be determined which data corresponding to the second instance has completed the data synchronization operation, avoiding the situation where synchronization omissions occur in the second instance.

[0068] Furthermore, during a certain message processing process, after processing the normal business logic, the attribute value cache value of the current distributed lock is obtained again. If the difference between the attribute value of the distributed lock at the previous lock is greater than 1 (indicating that the attribute value of the distributed lock corresponding to the second instance that is not locked has been increased by 1 at least twice), it means that new data has entered during the change message processing, and the current message is retried.

[0069] Figure 2 This is a schematic flow chart of a message processing method corresponding to the second embodiment of the present invention. Figure 2 As shown, the method includes the following steps S201 to S206:

[0070] Step S201: using one or more instances in a distributed cluster to respectively receive a plurality of to-be-processed messages triggered by a database, wherein the plurality of to-be-processed messages correspond to the same data identifier.

[0071] Specifically, according to an embodiment of the present invention, the complete data of a business ID is stored in multiple data tables. For example, in an e-commerce scenario, a business ID is usually associated with multiple commodities, and the data tables corresponding to the complete data of the business ID are divided into two types of data tables, A and B. Among them, there are multiple type B data tables, such as detailed data including unit price details table, sales details table, etc.; type A data table is a general table (there is a one-to-many relationship between A and B, and both type A data table and type B data table correspond to the same business ID), which is used to store summary data such as the total sales volume and profit of the commodity. It can be known that the data stored in the type A data table is calculated based on the detailed data in at least one type B data table. Therefore, when a new message is added (such as a new sales detail), multiple change messages (i.e., the above-mentioned pending messages) will be generated. At this time, the database will send the generated multiple change information to one or more instances in the distributed cluster, so that one or more instances in the distributed cluster can synchronize local data according to the change information.

[0072] Step S202: Generate a random number for the data identifier, perform distributed locking processing on one or more instances according to the random number, and store the random number as an attribute value.

[0073] For example, during a message processing session, an instance acquires a distributed lock for a business ID. A random number within 10,000 (this number can be adjusted based on actual needs) is generated, and the instance that acquired the lock for the business ID is locked based on the random number. The generated random number is used as the attribute value of the distributed lock.

[0074] Step S203: using the first instance to perform deduplication processing on the received multiple messages to be processed according to the data identifier.

[0075] Specifically, the first instance is used to deduplicate multiple data to be processed according to data identifiers. The first instance only needs to process the deduplicated messages. Through the above deduplication, the number of messages to be processed is effectively reduced and the message processing efficiency is improved.

[0076] Step S204: according to the data identifier indicated by the deduplication processing result, a data table corresponding to the data identifier is obtained from the database; according to the obtained data table, the stored data is updated.

[0077] The above steps query the database based on the business ID to obtain complete business information, which helps to obtain all changed data and improves the accuracy of message processing.

[0078] Step S205: using the second instance to increment the attribute value of the distributed lock.

[0079] For example, during a certain message processing, after the first instance performs a distributed lock locking process, the current cached value of the attribute value of the distributed lock corresponding to the second instance that is not locked is incremented by 1 (the above incrementing by 1 is only an example, and its purpose is to distinguish the attribute values ​​of the distributed locks corresponding to the second instance and the first instance, so as to facilitate the subsequent synchronization update of the local data corresponding to the second instance with different attribute values). In the process of the first instance processing the data stored in itself, if the second instance receives the update message corresponding to the business ID again, the attribute value of the distributed lock of the second instance is incremented again (similarly, the incrementing process is also an example, and its purpose is to indicate that the data corresponding to the business ID has generated a new change message again in the process of the first instance processing the data stored in itself).

[0080] Step S206: Determine a data synchronization source from the first instance and the second instance according to the size of the attribute values ​​of the distributed locks corresponding to the first instance and the second instance respectively, and synchronize the data according to the data in the data synchronization source.

[0081] For example, during a message processing process, since the attribute value of the distributed lock corresponding to the second instance has been incremented (or incremented) at least once, before the data in the second instance is synchronized, the attribute values ​​of the distributed locks corresponding to the first instance and the second instance are different. Using the first instance as the synchronization data source, the data of the first instance is synchronized to the second data source, and the distributed lock attribute value of the first instance is also synchronized to the second instance. If the difference between the attribute value of the distributed lock at the previous lock is greater than 1 (indicating that the attribute value of the distributed lock corresponding to the second instance that is not locked has been incremented at least twice), it means that new data has entered during the change message processing, and the current message is retried.

[0082] Figure 3 It is a schematic diagram of main modules of a message processing device according to an embodiment of the present invention.

[0083] like Figure 3 As shown, the embodiment of the present invention provides a data processing device, including: a receiving module 301, a determining module 302, a first processing module 303, a second processing module 304, a third processing module 305 and a fourth processing module 306; wherein,

[0084] Receiving module 301, used for receiving a message to be processed;

[0085] The first processing module 303 is used to perform distributed locking processing on one or more instances according to the data identifier to obtain the attribute value of the distributed lock;

[0086] The second processing module 304 is configured to process the received multiple messages to be processed using the locked first instance, so as to process the data stored in the module according to the data in the database;

[0087] The third processing module 305 is configured to update the attribute value of the distributed lock using the unlocked second instance;

[0088] Determination module 302 is used to determine whether the attribute values ​​of the distributed locks of the first instance and the second instance are different. If so, trigger the fourth processing module 306;

[0089] The fourth processing module 306 is configured to synchronize data in the first instance and the second instance.

[0090] In one embodiment of the present invention, the first processing module 303 is used to use the first instance to deduplicate the multiple messages to be processed received according to the data identifier, and process the data stored in itself according to the deduplication results and the data in the database.

[0091] In one embodiment of the present invention, the second processing module 304 is configured to obtain a data table corresponding to the data identifier from a database according to the data identifier indicated by the deduplication processing result;

[0092] Update the data stored in itself according to the obtained data table.

[0093] In one embodiment of the present invention, the third processing module 305 is used to generate a random number for the data identifier, perform distributed locking processing on one or more instances according to the random number, and use the random number as an attribute value.

[0094] In one embodiment of the present invention, the third processing module 305 is configured to update the attribute value of the distributed lock again using the second instance when the second instance receives the data update message triggered by the database again.

[0095] In one embodiment of the present invention, the third processing module 305 is configured to incrementally increase the distributed attribute value using the second instance.

[0096] In one embodiment of the present invention, the determination module 302 is used to determine the data synchronization source from the first instance and the second instance based on the size of the attribute values ​​of the distributed locks corresponding to the first instance and the second instance respectively, and synchronize the data based on the data in the data synchronization source.

[0097] In one embodiment of the present invention, the fourth processing module 306 is used to determine the data synchronization source from the first instance and the second instance based on the size of the attribute values ​​of the distributed locks corresponding to the first instance and the second instance respectively, and synchronize the data based on the data in the data synchronization source.

[0098] According to the data storage device provided by an embodiment of the present invention, when processing multiple messages with the same business ID, the business ID is used for locking, and multiple messages are deduplicated based on the business ID. The multiple pending messages received are only processed by the locked instance. Therefore, when an application instance receives messages related to the same business ID, the present invention reduces the number of processing times while optimizing distributed lock conflict processing, reducing invalid retries, thereby improving message processing efficiency. In addition, the accuracy of message processing is improved by comparing distributed lock attribute values.

[0099] An embodiment of the present invention also provides a server, comprising: one or more processors; a storage device for storing one or more programs, wherein when the one or more programs are executed by one or more processors, the one or more processors implement a message processing method as provided in any of the above embodiments.

[0100] An embodiment of the present invention further provides a computer-readable medium having a computer program stored thereon, which, when executed by a processor, implements the message processing method provided in any of the above embodiments.

[0101] Figure 4 An exemplary system architecture 400 is shown to which the message processing method or message processing apparatus according to the embodiment of the present invention can be applied.

[0102] like Figure 4 As shown, system architecture 400 may include terminal devices 401, 402, 403, a network 404, and a server 405. Network 404 is used to provide a medium for communication links between terminal devices 401, 402, 403 and server 405. Network 404 may include various connection types, such as wired or wireless communication links or fiber optic cables.

[0103] Users can use terminal devices 401, 402, and 403 to interact with server 405 via network 404 to receive or send messages, etc. Terminal devices 401, 402, and 403 can be installed with various communication client applications, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social platform software, etc.

[0104] The terminal devices 401 , 402 , and 403 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, and desktop computers.

[0105] Server 405 may be a server that provides various services, such as a backend management server (for example only) that supports shopping websites browsed by users using terminal devices 401, 402, and 403. The backend management server may analyze and process received data such as product information query requests, and feed back processing results (for example, target push information and product information—for example only) to the terminal device.

[0106] It should be noted that the message processing method provided in the embodiment of the present invention is generally executed by the server 405 , and accordingly, the message processing device is generally set in the server 405 .

[0107] It should be understood that Figure 4 The number of terminal devices, networks and servers in the embodiment is merely illustrative. Any number of terminal devices, networks and servers may be provided as required.

[0108] Reference below Figure 5 , which shows a schematic structural diagram of a computer system 500 of a terminal device suitable for implementing an embodiment of the present invention. Figure 5 The terminal device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.

[0109] like Figure 5 As shown, the computer system 500 includes a central processing unit (CPU) 501, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 502 or a program loaded from a storage unit 508 into a random access memory (RAM) 503. Various programs and data required for the operation of the system 500 are also stored in the RAM 503. The CPU 501, ROM 502, and RAM 503 are connected to each other via a bus 504. An input / output (I / O) interface 505 is also connected to the bus 504.

[0110] The following components are connected to the I / O interface 505: an input section 506 including a keyboard, a mouse, and the like; an output section 507 including devices such as a cathode ray tube (CRT), a liquid crystal display (LCD), and a speaker; a storage section 508 including a hard disk; and a communication section 509 including a network interface card such as a LAN card or a modem. The communication section 509 performs communication processing via a network such as the Internet. A drive 510 is also connected to the I / O interface 505 as needed. A removable medium 511, such as a magnetic disk, an optical disk, a magneto-optical disk, or a semiconductor memory, is installed in the drive 510 as needed, so that computer programs read therefrom can be installed into the storage section 508 as needed.

[0111] In particular, according to the embodiments disclosed in the present invention, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, the embodiments disclosed in the present invention include a computer program product comprising a computer program carried on a computer-readable medium, the computer program comprising program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network via the communication section 509, and / or installed from a removable medium 511. When the computer program is executed by the central processing unit (CPU) 501, the above-mentioned functions defined in the system of the present invention are performed.

[0112] It should be noted that the computer-readable medium described in the present invention can be a computer-readable signal medium or a computer-readable storage medium, or any combination thereof. A computer-readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of computer-readable storage media can include, but are not limited to, an electrical connection having one or more conductors, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In the present invention, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In the present invention, a computer-readable signal medium can include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. This propagated data signal can take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium that can transmit, propagate, or transport a program for use by or in conjunction with an instruction execution system, apparatus, or device. Program code embodied on a computer-readable medium may be transmitted using any suitable medium, including but not limited to wireless, wireline, optical fiber cable, RF, or any suitable combination thereof.

[0113] The flowcharts and block diagrams in the accompanying drawings illustrate the possible implementation architecture, functions and operations of the systems, methods and computer program products according to various embodiments of the present invention. In this regard, each box in the flowchart or block diagram can represent a module, program segment, or a part of code, and the above-mentioned module, program segment, or a part of code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in an order different from that marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flowchart, and the combination of boxes in the block diagram or flowchart, can be implemented with a dedicated hardware-based system that performs the specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0114] The modules described in the embodiments of the present invention may be implemented in software or hardware. The modules described may also be provided in a processor. For example, the processor may be described as comprising a receiving module, a determining module, a first storage module, a second storage module, a third processing module, and a fourth processing module. The names of these modules do not, in some cases, limit the modules themselves. For example, the receiving module may also be described as a "module that receives data to be stored."

[0115] As another aspect, the present invention also provides a computer-readable medium, which may be included in the device described in the above embodiment; or it may exist independently and not be assembled into the device. The above computer-readable medium carries one or more programs. When the above one or more programs are executed by one of the devices, the device includes: using one or more instances in a distributed cluster to respectively receive multiple pending messages triggered by a database, and the multiple pending messages correspond to the same data identifier; performing distributed locking processing on one or more instances according to the data identifier to obtain the attribute value of the distributed lock; using the locked first instance to process the received multiple pending messages to process the data stored in itself according to the data in the database; using the unlocked second instance to update the attribute value of the distributed lock; when the attribute values ​​of the distributed locks of the first instance and the second instance are different, synchronizing the data in the first instance and the second instance.

[0116] According to the technical solution of the embodiment of the present invention, because one or more instances in a distributed cluster are used to respectively receive multiple pending messages triggered by a database, the multiple pending messages correspond to the same data identifier; distributed locking processing is performed on one or more instances according to the data identifier to obtain the attribute value of the distributed lock; the locked first instance is used to process the received multiple pending messages to process the data stored in itself according to the data in the database; the unlocked second instance is used to update the attribute value of the distributed lock; when the attribute values ​​of the distributed locks of the first instance and the second instance are different, the technical means of synchronizing the data in the first instance and the second instance overcomes the technical problems of low message processing efficiency, distributed lock conflicts, and low message processing accuracy in the prior art, thereby achieving the ability to lock the instances in the distributed cluster according to the data identifier (business ID), and then use the locked instance to process the received multiple pending messages, effectively reducing the number of retries, avoiding distributed lock conflicts, and improving message processing efficiency. At the same time, the accuracy of message processing is improved by setting the attribute value of the distributed lock.

[0117] The above specific embodiments do not limit the scope of protection of the present invention. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions may occur depending on design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention are intended to be included within the scope of protection of the present invention.

Claims

1. A message processing method, characterized in that: Applicable to distributed clusters; includes: Using one or more instances in the distributed cluster to respectively receive a plurality of to-be-processed messages triggered by a database, wherein the plurality of to-be-processed messages correspond to the same data identifier; Performing distributed locking processing on the one or more instances according to the data identifier to obtain a property value of the distributed lock; Using the locked first instance to process the received multiple messages to be processed, so as to process the data stored in the database according to the data; Using the unlocked second instance to update the attribute value of the distributed lock; When the attribute values ​​of the distributed locks of the first instance and the second instance are different, data in the first instance and the second instance are synchronized.

2. The method according to claim 1, characterized in that The method of using the locked first instance to process the multiple messages to be processed includes: using the first instance to deduplicate the multiple messages to be processed according to the data identifier, and processing the data stored in itself according to the deduplication result and the data in the database.

3. The method according to claim 2, characterized in that The processing of the stored data according to the deduplication processing result and the data in the database includes: obtaining a data table corresponding to the data identifier from the database according to the data identifier indicated by the deduplication processing result; According to the acquired data table, the data stored in itself is updated.

4. The method according to claim 1, characterized in that: Performing distributed locking processing on the one or more instances according to the data identifier to obtain attribute values ​​of the distributed lock includes: A random number is generated for the data identifier, distributed locking processing is performed on the one or more instances according to the random number, and the random number is used as the attribute value.

5. The method according to claim 1, characterized in that Also includes: When the second instance receives the data update message triggered by the database again, the attribute value of the distributed lock is updated again using the second instance.

6. The method according to claim 5, characterized in that Updating the attribute value of the distributed lock by using the second instance includes: The distributed attribute value is incremented using the second instance.

7. The method according to claim 1, characterized in that The synchronizing the data in the first instance and the second instance includes: According to the sizes of the attribute values ​​of the distributed locks respectively corresponding to the first instance and the second instance, a data synchronization source is determined from the first instance and the second instance, and the data is synchronized according to the data in the data synchronization source.

8. A data processing device, characterized in that: include: A receiving module, a first processing module, a determining module, a second processing module, a third processing module and a fourth processing module; wherein, The receiving module is used to receive a plurality of to-be-processed messages triggered by a database respectively received by one or more instances in the distributed cluster; The first processing module performs distributed locking processing on the one or more instances according to the data identifier to obtain a property value of the distributed lock; The second processing module processes the received multiple messages to be processed by using the locked first instance, so as to process the data stored in the module according to the data in the database; The third processing module updates the attribute value of the distributed lock using the unlocked second instance; The determination module is used to determine whether the attribute values ​​of the distributed locks of the first instance and the second instance are different; if yes, trigger the fourth processing module; if no, end the process; The fourth processing module is used to synchronize the data in the first instance and the second instance.

9. An electronic device for message processing, characterized in that: include: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 7.

10. A computer readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.

Citation Information

Patent Citations

  • Data processing method and device

    CN106657247A

  • Method, device and equipment of data clustering processing

    CN108733477A