Distributed batch running method and system based on message-oriented middleware
Through the distributed batch running method based on message middleware, the problems of high cost and data skew in the distributed computing framework are solved, efficient and reliable data processing is achieved, suitable for data processing needs of different scales, and supports real-time processing.
Patent Information
- Application Number
- CN202411032700.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-30
- Publication Date
- 2024-09-24
AI Technical Summary
Existing distributed computing frameworks suffer from high deployment and operation and maintenance costs, data skew problems, and inapplicability to real-time processing and high-frequency updates when processing large-scale data, making it difficult to meet the needs of small projects or start-ups.
Adopt a distributed batch running method based on message middleware, generate KafkaTopic, query data in pages and send it to Kafka middleware, configure multiple consumer threads for data processing, perform idempotence check before consumption, and call the decision engine interface. Start monitoring threads to regularly check task execution and clean up resources to ensure even distribution of data and system stability.
It reduces the deployment threshold and operation and maintenance costs of distributed running batches, improves data processing efficiency and system performance, avoids data skew, supports real-time processing requirements for large amounts of data, and ensures system stability and reliability.
Smart Images

Figure CN118689653A
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data processing technology, and in particular to a distributed batch running method and system based on message middleware. Background Art
[0002] With the rapid development of big data technology, the amount of data is showing an explosive growth trend. When processing large-scale data sets, the traditional single-node computing method often cannot meet the needs of efficient and real-time data processing due to limited computing resources. Therefore, the distributed computing framework came into being and became an important means of processing large-scale data sets.
[0003] At present, there are many mature distributed computing frameworks on the market, such as Hadoop and Spark, which effectively improve the efficiency and scalability of data processing through cluster computing. However, these frameworks also have some shortcomings in practical applications. First, distributed computing frameworks such as Hadoop usually require high deployment and operation and maintenance costs, including investment in hardware resources, cluster construction and maintenance, etc., which may be too large and expensive for some small projects or start-ups. Secondly, although these frameworks are powerful, they often focus on batch processing tasks, and may not be fully applicable to business batch running scenarios that require real-time processing or high-frequency updates.
[0004] In addition, distributed computing frameworks also face the problem of data skew when processing data. Data is unevenly distributed in a distributed system, resulting in some nodes being overloaded while other nodes being underloaded. This not only affects the speed and efficiency of data processing, but may also cause problems such as resource competition and failures. Summary of the invention
[0005] The purpose of the present invention is to propose a distributed batch running method and system based on message middleware. The technical solution provides an efficient and reliable data processing system, which can reduce the deployment threshold and operation and maintenance costs of distributed batch running.
[0006] To achieve the above-mentioned objectives, in the first aspect, an embodiment of the present disclosure provides a distributed batch running method based on a message middleware, including: using rules to generate at least two Topic names, and creating corresponding KafkaTopics, while starting a monitoring thread to monitor the task execution status; paging query of credit user data and sending it to the Kafka middleware; configuring multiple consumer threads, each thread is responsible for one or more Partition data; performing an idempotence check before consumption, calling a decision engine interface, and performing business processing based on the decision results; the task monitoring thread regularly checks the task execution status and cleans up resources.
[0007] Beneficial effects of the basic solution: This technical solution simplifies system components and dependencies, making it easier to deploy and use distributed batch systems; by optimizing data sharding and processing mechanisms, the system can process large-scale data more efficiently and improve overall data processing capabilities. By relying on the characteristics of existing middleware, such as Kafka's Partition mechanism and Redis's key-value storage, it ensures uniform distribution of data and avoids data skew, thereby improving the overall performance and stability of the system. This system is designed to be flexible and can be horizontally expanded according to business needs to adapt to data processing needs of different scales.
[0008] Specifically, by creating a KafkaTopic and querying the credit user data in pages and sending it to the Kafka middleware, the system can efficiently transfer a large amount of data from the data source to the processing system asynchronously, avoiding system blockage or performance degradation that may be caused by direct processing. Kafka's high throughput and low latency ensure that data can be transmitted quickly and reliably, supporting the real-time processing requirements of large amounts of data.
[0009] This technical solution is configured with multiple consumer threads, each of which is responsible for data processing of one or more partitions, making full use of computing resources and improving data processing capabilities. Kafka's partition mechanism enables the system to scale horizontally, responding to higher data processing requirements by increasing the number of consumer threads and nodes in the Kafka cluster.
[0010] Perform an idempotence check before consumption to ensure that messages will not cause data inconsistency or business logic errors due to repeated processing, thus ensuring system stability and data accuracy.
[0011] The decision engine interface is called to process business according to the decision results, realizing flexible configuration and rapid response of business logic. The decision engine can provide personalized processing strategies for each user data based on complex business rules, machine learning models or AI algorithms.
[0012] Start the monitoring thread to regularly check the execution of tasks, so as to timely discover and handle abnormalities or failures in task execution and ensure the stability and reliability of the system. The monitoring thread is also responsible for cleaning up resources that are no longer needed, such as closing useless network connections and releasing memory, to avoid resource leakage and waste.
[0013] Through task monitoring and logging, it is easy to track the system's operating status and performance indicators, and quickly locate and solve potential problems. The monitoring and logging system improves the observability of the system, making it easier to maintain and optimize the system.
[0014] As an implementable preferred solution, use rules to generate at least two Topic names and create corresponding KafkaTopics, including the following: Use the KafkaAdminAPI or command line tool to create a KafkaTopic and customize the number of partitions and replicas.
[0015] As an implementable preferred solution, paging query of credit user data and sending it to Kafka middleware includes the following: Use SQL statements to query the trusted user table in pages, send the queried user data to the Kafka middleware, and store the total data volume in Redis.
[0016] As an implementable optimal solution, an idempotence check is performed before consumption, the decision engine interface is called, and business processing is performed based on the decision results, including the following: Assemble necessary subsidiary information based on the main information consumed; call the decision engine interface, pass in the assembled data, and obtain the decision result.
[0017] As an implementable preferred solution, idempotency check is performed before consumption, including the following: Assign a unique identifier to each message. Before processing the message, check whether the identifier has been processed before. For scenarios that need to be processed based on user and business logic, use a combination of user ID or business ID as the basis for checking.
[0018] As an implementable preferred solution, a task suspension, resumption and retry mechanism is also included, including the following: When a pause command is received, all consumer threads persist the current Offset to Redis and stop the consumer threads; when a resume command is received, the consumer threads are restarted according to the Offset saved in Redis and continue consuming from the last stopped position.
[0019] As an implementable preferred solution, a failure message processing mechanism is also included, including the following contents: Make multiple attempts to consume the failed messages and record the number of retries. If all retries fail, send the data to the dead letter queue Topic. Start another consumer task to process the data in the Topic for further processing or recording. If all processing fails, record the data in the database for subsequent investigation.
[0020] As an implementable preferred solution, a task completion mechanism is also included, including the following contents: The task monitoring thread checks the task execution status at intervals, comparing the total number of records in Redis with the sum of the number of successful and failed data records in the database; if the data is consistent, the task is completed and the metadata is recorded; clean up resources, delete topics, stop all consumption tasks, and release related resources.
[0021] In a second aspect, the embodiments of the present disclosure also provide a distributed batch running system based on a message middleware, which utilizes the above-mentioned distributed batch running method based on a message middleware. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] Figure 1 This is a logical diagram of a distributed batch running method based on message middleware.
[0023] Figure 2 This is a schematic diagram of the architecture of a distributed batch system based on message middleware.
[0024] Figure 3 Schematic diagram of the structure of an electronic device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0025] In order to make the technical solution and advantages of the present application clearer, the technical solution of the present invention will be further described in detail below in conjunction with the accompanying drawings. It will be understood that the specific embodiments described herein are only partial embodiments of the present invention, which are only used to explain the present application, rather than to limit the present application. It should be noted that the technical features or combinations of technical features described in the following embodiments should not be considered isolated, and they can be combined with each other to achieve better technical effects. The same reference numerals appearing in the drawings of the following embodiments represent the same features or components, which can be applied to different embodiments.
[0026] In addition, unless otherwise defined, the technical terms or scientific terms used in the description of the present invention should have the common meanings understood by those skilled in the art in the art to which the present invention belongs.
[0027] The present invention is further described in detail below in conjunction with the accompanying drawings: Reference numerals: electronic device 500 , processor 501 , communication interface 502 , memory 503 , bus 504 .
[0028] This embodiment uses the afka message middleware to perform batch processing of loan tasks for credit users as an example. Figure 1 , a distributed batch running method based on message middleware, including: Step S100, starting the task and preparing the environment, including: Step S101, use the rules to generate two Topic names, one for normal message sending and the other for messages to be forwarded after an exception occurs, such as credit_batch_topic (normal message Topic) and credit_dead_letter_topic (dead letter queue Topic).
[0029] Step S102: Use AdminAPI (or command line tool) in Kafka to create the above Topic and customize the number of partitions and replicas.
[0030] Step S103, start a thread to monitor the task execution status, check the task completion status every certain time, in this embodiment, check every five minutes, including the start, pause, continue and completion of the task.
[0031] Step S200, data generation and transmission, includes: Step S201, query the credit user data in pages, and use SQL statements to query the credit user table in pages.
[0032] Step S202, sending the queried detailed data to the Kafka middleware, and sending the queried user data to the credit_batch_topic, and the KafkaProducerAPI can be used.
[0033] Step S203, store the total amount of data into Redis, with the key name being the unique identifier of the task.
[0034] Step S300, consumer-side task initiation and data consumption, including: Step S301, start multiple consumption threads according to task requirement configuration.
[0035] Step S302: Each thread is responsible for the consumption of one or more partitions, and the messages are evenly distributed on each partition to ensure that the data consumed by each thread is uniform and avoid data skew problems.
[0036] Step S400: the consumer server starts the consumption task, including: Step S401, performing an idempotency check before consumption, includes: Step S401-1, assign a unique identifier to each message, and before processing the message, check whether the identifier has been processed.
[0037] Step S401-2: For some scenarios that need to be processed according to user and business logic, a combination of user ID or business ID is used as a check basis.
[0038] Step S402, assembling necessary auxiliary information according to the consumed main information.
[0039] Step S403, calling the decision engine interface, passing in the assembled data, and obtaining the decision result.
[0040] Step S404: Perform business processing according to the decision result, such as updating the user's credit status.
[0041] Step S405: After successful processing, submit the Offset to Kafka to ensure the correctness of data consumption.
[0042] Step S500, the pause, resume and retry mechanism includes: Step S501, when a pause command is received, all consumer threads persist the current Offset to Redis and stop the consumer threads.
[0043] Step S502, when a recovery command is received, restart the consumption thread according to the Offset saved in Redis, and continue consumption from the position where it was stopped last time.
[0044] Step S600, processing the failed message, includes: Step S601: For the message that fails to be consumed, multiple retries are performed and the number of retries is recorded.
[0045] Step S602: If all retries fail, the data is sent to the dead letter queue Topic.
[0046] Step S603, start another consumption task to specifically process the data in the Topic for further processing or recording.
[0047] Step S604: If the final processing still fails, the data is recorded in the database for subsequent investigation.
[0048] Step S700, completing the batch running task, includes: Step S701, the task monitoring thread checks the task execution status every 5 minutes, compares the total number of records in Redis with the sum of the number of successful and failed data in the database, and if the data is consistent, the task is completed, and records the total number of task executions, execution time and other metadata.
[0049] Step S702: clean up resources, delete topics, stop all consumption tasks, and release related resources.
[0050] The present disclosure also provides a distributed batch running system based on message middleware, referring to Figure 2 The system uses the above-mentioned distributed batch running method based on message middleware.
[0051] The embodiment of the present disclosure also provides a storage medium, in which a computer program is stored. When the computer program is executed by a processor, all the steps of the above-mentioned distributed batch running method based on message middleware can be implemented.
[0052] Those of ordinary skill in the art can understand that the implementation of all or part of the process in a distributed batch running method based on a message middleware can be completed by instructing related hardware through a computer program, and the program can be stored in a non-volatile computer-readable storage medium. When the program is executed, it can include a process of each embodiment of a distributed batch running method based on a message middleware. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application may include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.
[0053] The embodiment of 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 the processor implements the steps of the above-mentioned distributed batch running method based on message middleware when executing the program. In the embodiment of the present application, the processor is the control center of the computer system, which can be the processor of a physical machine or the processor of a virtual machine.
[0054] Reference Figure 3, the electronic device 500 includes: at least one processor 501, at least one communication interface 502, at least one memory 503 and at least one bus 504. Among them, the bus 504 is used to realize the connection and communication between these components, the communication interface 502 is used to communicate with other node devices for signaling or data, and the memory 503 stores machine-readable instructions executable by the processor 501. When the electronic device 500 is running, the processor 501 communicates with the memory 503 through the bus 504, and the machine-readable instructions are called by the processor 501 to perform the steps of the above-mentioned distributed batch running method based on message middleware. The above content is only an embodiment of the present invention, and the common sense such as the known specific structure and characteristics in the scheme is not described in detail here. Ordinary technicians in the relevant field know all the common technical knowledge in the technical field of the invention before the application date or priority date, can know all the existing technologies in the field, and have the ability to apply conventional experimental means before that date. Ordinary technicians in the relevant field can improve and implement this scheme in combination with their own abilities under the enlightenment given by this application. Some typical known structures or known methods should not become obstacles for ordinary technicians in the relevant field to implement this application. It should be pointed out that for those skilled in the art, several modifications and improvements can be made without departing from the structure of the present invention, which should also be regarded as the protection scope of the present invention, and these will not affect the effect of the implementation of the present invention and the practicality of the patent. The protection scope required by this application shall be based on the content of its claims, and the specific implementation methods and other records in the specification can be used to interpret the content of the claims.
Claims
1. A distributed batch running method based on message middleware, characterized by: include: Generate at least two Topic names using rules, create corresponding KafkaTopics, and start a monitoring thread to monitor the task execution status; Query the credit user data in pages and send it to Kafka middleware; configure multiple consumption threads, each thread is responsible for one or more Partition data; perform idempotence check before consumption, call the decision engine interface, and perform business processing based on the decision results; the task monitoring thread regularly checks the task execution status and cleans up resources.
2. According to claim 1, a distributed batch running method based on message middleware is characterized in that: Generate at least two topic names using the rules and create corresponding Kafka topics, including the following: Use the KafkaAdminAPI or command line tool to create a KafkaTopic and customize the number of partitions and replicas.
3. According to a distributed batch running method based on message middleware according to claim 1, it is characterized in that: Paginated query of credit user data and sending it to Kafka middleware includes the following: Use SQL statements to query the trusted user table in pages, send the queried user data to the Kafka middleware, and store the total data volume in Redis.
4. According to claim 1, a distributed batch running method based on message middleware is characterized in that: Perform idempotency check before consumption, call the decision engine interface, and perform business processing based on the decision results, including the following: Assemble necessary subsidiary information based on the main information consumed; Call the decision engine interface, pass in the assembled data, and obtain the decision result.
5. A distributed batch running method based on message middleware according to claim 4, characterized in that: Perform idempotency checks before consumption, including the following: Assign a unique identifier to each message and check if the identifier has been processed before processing the message; For scenarios that require processing based on user and business logic, use a combination of user ID or business ID as the basis for inspection.
6. A distributed batch running method based on message middleware according to claim 1, characterized in that: It also includes task suspension, resumption, and retry mechanisms, including the following: When a pause command is received, all consumer threads persist the current Offset to Redis and stop the consumer threads; when a resume command is received, the consumer threads are restarted according to the Offset saved in Redis and continue consuming from the last stopped position.
7. A distributed batch running method based on message middleware according to claim 1, characterized in that: It also includes a failure message handling mechanism, including the following: Make multiple attempts to consume the failed messages and record the number of retries. If all retries fail, send the data to the dead letter queue Topic. Start another consumer task to process the data in the Topic for further processing or recording. If all processing fails, record the data in the database for subsequent investigation.
8. A distributed batch running method based on message middleware according to claim 1, characterized in that: The task monitoring thread periodically checks the task execution status and cleans up resources, including the following: The task monitoring thread checks the task execution status at intervals, comparing the total number of records in Redis with the sum of the number of successful and failed data records in the database; if the data is consistent, the task is completed and the metadata is recorded; clean up resources, delete topics, stop all consumption tasks, and release related resources.
9. A distributed batch processing system based on message middleware, characterized by: A distributed batch running method based on message middleware as described in any one of claims 1 to 8 is used.
Citation Information
Cited By
Integration method of judicial library system and financial core system, equipment and medium
CN121117087A
