CN114328194B - A method for implementing timeout retry execution based on Rocket MQ - Google Patents
A method for implementing timeout retry execution based on Rocket MQ Download PDFInfo
- Publication number
- CN114328194B CN114328194B CN202111538304.XA CN202111538304A CN114328194B CN 114328194 B CN114328194 B CN 114328194B CN 202111538304 A CN202111538304 A CN 202111538304A CN 114328194 B CN114328194 B CN 114328194B
- Authority
- CN
- China
- Prior art keywords
- task
- retry
- timeout retry
- retries
- timeout
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
- 238000000034 method Methods 0.000 title claims abstract description 80
- 238000009825 accumulation Methods 0.000 claims description 3
- 230000002159 abnormal effect Effects 0.000 description 1
- 230000009286 beneficial effect Effects 0.000 description 1
- 238000005065 mining Methods 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
- 239000011435 rock Substances 0.000 description 1
- 230000001960 triggered effect Effects 0.000 description 1
Classifications
-
- Y—GENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
- Y02—TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
- Y02D—CLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
- Y02D10/00—Energy efficient computing, e.g. low power processors, power management or thermal management
Landscapes
- Executing Machine-Instructions (AREA)
Abstract
The invention discloses a method for realizing overtime retry execution based on a task mq, which comprises the following steps of step S1, binding all task trigger methods of asynchronous tasks needing overtime retry to a task trigger strategy when an application program is started and storing the task trigger methods in an application cache, step S2, assembling parameters of the task trigger methods, the task trigger strategy, overtime retry time and maximum retry times into task information and sending the task information to the task mq, setting delay time of the task information, and step S3, pushing the task information to the application program according to the delay time by the task mq, acquiring the task trigger methods corresponding to the task trigger methods stored in the application cache by the application program according to the task trigger strategy, and matching the parameters of the task trigger methods according to the task trigger methods to finish overtime retry. The invention has high inquiry efficiency, high execution speed, less occupied CPU resource and universality.
Description
Technical Field
The invention relates to the field of computer software, in particular to a method for realizing overtime retry execution based on a socket mq.
Background
In a financial business system, relevant business information rules of enterprises need to be acquired to make a wind control decision, the business information rules need to be executed and an execution result is displayed, and because the logic of executing the business rules is complex and time-consuming, asynchronous processing needs to be performed, namely, a task is triggered to a rule engine system, and the rule engine system notifies the business system after the execution is finished.
Because the rule engine system executes the rule, sometimes there is a timeout unreturned result (high concurrency or long timeout or other abnormal condition of part of enterprise information mining time), the service system retries at this time, and triggers the task to the rule engine system again, and a timeout retrying mechanism is needed.
There are of course other similar tasks that require asynchronous processing that may have time-out situations.
The prior art mainly adopts a task of timing task polling query timeout without returning a result and retries triggering processing.
Disadvantages of the prior art:
1. The efficiency is lower, tasks which do not return results after the database is queried overtime are needed, the data volume is large, and the query efficiency is low. 2. The CPU resources are occupied, and in order to retry overtime as accurately as possible, the timing tasks are frequently executed due to the short interval of the timing tasks. 3. And the universality is not enough, and if other asynchronous tasks are overtime retries, the code of the whole retry logic needs to be changed.
Accordingly, the prior art has drawbacks and needs improvement.
Disclosure of Invention
The invention aims to solve the technical problems of high query efficiency, high execution speed, less CPU resource occupation and universality, and provides a method for realizing overtime retry execution based on a socket mq.
The method is characterized by comprising the following steps of binding all task trigger methods of asynchronous tasks needing overtime retry to one task trigger strategy when an application program is started and storing the task trigger methods in an application cache, assembling parameters of the task trigger methods, the task trigger strategy, overtime retry time and maximum retry times into task information and sending the task information to the task mq, setting delay time of the task information, and pushing the task information to the application program according to the delay time, wherein the application program obtains the corresponding task trigger methods stored in the application cache according to the task trigger strategy, and matching the parameters of the task trigger methods according to the task trigger methods to finish overtime retry.
In the step S3, before matching the parameters of the task triggering method, it is also queried from the database whether the asynchronous task returns a result, if yes, no processing is performed, if not, the number of retries is +1, after accumulation, when the current number of retries is equal to or greater than the maximum number of retries, no processing is performed, and when the current number of retries is less than the maximum number of retries, the parameters of the task triggering method are matched, thus completing the overtime retry.
The method is applied to the technical schemes, in the method for realizing overtime retry execution based on the rock mq, in the step S1, the task triggering method is a task triggering method based on reflection acquisition, and in the step S3, the overtime retry is completed by using a reflection mechanism to complete the call of the task triggering method.
In the above technical solutions, in the method for implementing timeout retry execution based on the socket mq, in step S2, the delay time is the timeout retry time.
In the method for implementing overtime retry execution based on the socket mq, in the step S2, the task trigger strategy, the overtime retry time and the maximum retry times are all set on the overtime retry annotation, and in the step S1, all asynchronous tasks requiring overtime retry are asynchronous tasks with overtime retry annotations.
In the above technical solutions, in the method for implementing the overtime retry execution based on the task mq, in step S2, a self-defined spring aop section is written for intercepting the overtime retry solution of the asynchronous task overtime retry, and the task trigger strategy, the overtime retry time, the maximum retry times and the parameters of the task trigger method on the intercepted overtime retry annotation are assembled into a task message and sent to the task mq.
The beneficial effects of the invention are as follows:
1. the problem of the inefficiency that above presented only needs to inquire whether current overtime task is accomplished and returned the result, and inquiry efficiency is high, and execution speed is also fast naturally.
2. The problem that the CPU is occupied is solved, and the state of the query task does not need to be polled during non-timeout time, so that the CPU is reduced.
3. The method has universality, the tasks of the same type which can be retried asynchronously and overtime only need to self-define one trigger strategy and a corresponding trigger method, and then the corresponding trigger strategy is annotated on the method band which needs overtime retrying, thereby following the switching principle of a design mode.
Drawings
FIG. 1 is a flow chart of the present invention.
Detailed Description
The invention will be described in detail below with reference to the drawings and the specific embodiments.
The embodiment provides a method for implementing timeout retry execution based on a socket mq, which mainly implements a timeout retry mechanism based on the socket mq, and also uses a spring aop, jdk reflection mechanism.
Step S1, binding all task triggering methods of asynchronous tasks needing overtime retry to a task triggering strategy when an application program is started, and storing the task triggering methods in an application cache.
The method comprises the steps of starting a task triggering strategy, loading all methods with overtime retry comments when starting, and binding the methods with the task triggering strategy on the comments, wherein the key is the task triggering strategy, and the value is the method based on reflection acquisition, namely the task triggering method.
And step S2, assembling the parameters of the task triggering method, the task triggering strategy, the overtime retry time and the maximum retry times into a task message, sending the task message to a socket mq, and setting the delay time of the task message.
The time delay time is the time of overtime retry, the task trigger strategy, the time of overtime retry and the maximum retry times are all set on the overtime retry annotation, and a custom spring aop section is written for overtime retry solution interception of asynchronous task overtime retry, the task trigger strategy, the time of overtime retry, the maximum retry times and the parameters of a task trigger method on the intercepted overtime retry annotation are assembled into a task message and sent to a task mq, the parameters of the task trigger method are written and acquired from spring aop, namely, the task message is sent to the task mq to be processed at a spring aop section and coupled with a service method.
And finally, step S3, pushing the task message to the application program according to the delay time by the socket mq, and obtaining a corresponding task triggering method stored in an application cache by the application program according to the task triggering strategy, and matching parameters of the task triggering method according to the task triggering method to finish overtime retry.
Before matching the parameters of the task triggering method, inquiring whether the asynchronous task returns a result or not from a database, if so, not processing, if not, carrying out retry times +1, and after accumulation, if the current retry times are equal to or greater than the maximum retry times, not processing, and if the current retry times are less than the maximum retry times, matching the parameters of the task triggering method, and finishing overtime retry.
In step S3, the overtime retry is completed by using a reflection mechanism to complete the invocation of the task triggering method.
In this way, when the number of retries is smaller than the maximum number of retries, the corresponding task is retried, the message acquired from the socket mq contains the parameter of the task triggering method and the task triggering strategy, the method in the buffer memory in the first step corresponding to the triggering of the method can be obtained according to the task triggering strategy, the method is reflected, the method is used for completing the method calling after the overtime after the method is obtained, and the method parameter is acquired from the socket mq.
According to the method, before the parameters of the task triggering method are matched, whether the asynchronous task returns a result is also queried from the database, so that the problem of low efficiency is solved, only whether the current overtime task finishes returning the result is queried, the query efficiency is high, and the execution speed is natural.
And the invention binds a corresponding task trigger strategy through the task trigger method and stores the task trigger strategy in the application cache, and assembles the parameters of the task trigger method, the task trigger strategy, the time of overtime retry and the maximum retry times into task information and sends the task information to the socket mq, thereby solving the problem of excessively high occupation of CPU, and reducing the CPU usage because the non-overtime time does not need to poll the state of the query task.
The method has universality, the tasks of the same type of asynchronous overtime retrying can be achieved by only customizing one trigger strategy and a corresponding trigger method, and then annotating the corresponding trigger strategy on the method band needing overtime retrying, so that the switching principle of a design mode is followed.
The foregoing description of the preferred embodiment of the invention is not intended to be limiting, but rather is intended to cover all modifications, equivalents, and alternatives falling within the spirit and principles of the invention.
Claims (3)
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202111538304.XA CN114328194B (en) | 2021-12-15 | 2021-12-15 | A method for implementing timeout retry execution based on Rocket MQ |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202111538304.XA CN114328194B (en) | 2021-12-15 | 2021-12-15 | A method for implementing timeout retry execution based on Rocket MQ |
Publications (2)
Publication Number | Publication Date |
---|---|
CN114328194A CN114328194A (en) | 2022-04-12 |
CN114328194B true CN114328194B (en) | 2025-03-14 |
Family
ID=81053507
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202111538304.XA Active CN114328194B (en) | 2021-12-15 | 2021-12-15 | A method for implementing timeout retry execution based on Rocket MQ |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN114328194B (en) |
Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN107391271A (en) * | 2017-05-17 | 2017-11-24 | 阿里巴巴集团控股有限公司 | A kind of delayed tasks triggering method and device based on Message Queuing system |
CN111367723A (en) * | 2020-03-09 | 2020-07-03 | 山东汇贸电子口岸有限公司 | Automatic retry device and method based on reflection mechanism |
CN111600738A (en) * | 2020-03-30 | 2020-08-28 | 福建天泉教育科技有限公司 | Method for optimizing timeout processing and storage medium |
Family Cites Families (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US8793691B2 (en) * | 2010-04-15 | 2014-07-29 | Salesforce.Com, Inc. | Managing and forwarding tasks to handler for processing using a message queue |
CN107548039B (en) * | 2016-06-24 | 2021-06-25 | 中兴通讯股份有限公司 | Short message retry processing method, device and system |
CN111694645B (en) * | 2020-05-26 | 2022-05-24 | 平安普惠企业管理有限公司 | Task processing method and related device in distributed task scheduling system |
CN112698969A (en) * | 2020-12-30 | 2021-04-23 | 佰年颐堂医疗科技股份有限公司 | MQ message reliability delivery solution method based on message drop base |
-
2021
- 2021-12-15 CN CN202111538304.XA patent/CN114328194B/en active Active
Patent Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN107391271A (en) * | 2017-05-17 | 2017-11-24 | 阿里巴巴集团控股有限公司 | A kind of delayed tasks triggering method and device based on Message Queuing system |
CN111367723A (en) * | 2020-03-09 | 2020-07-03 | 山东汇贸电子口岸有限公司 | Automatic retry device and method based on reflection mechanism |
CN111600738A (en) * | 2020-03-30 | 2020-08-28 | 福建天泉教育科技有限公司 | Method for optimizing timeout processing and storage medium |
Also Published As
Publication number | Publication date |
---|---|
CN114328194A (en) | 2022-04-12 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US8533682B2 (en) | Amplification of dynamic checks through concurrency fuzzing | |
CN108512930B (en) | Shared file management method, device, server and storage medium | |
Luecke et al. | Deadlock detection in MPI programs | |
WO2020220764A1 (en) | Blockchain-based data compression and query method and apparatus, and electronic device | |
CN111198751A (en) | Service processing method and device | |
CN109542964B (en) | Data calling method and data calling system | |
CN110222119A (en) | A kind of data conversion synchronous method, equipment and the storage medium of heterogeneous database | |
CN112667439A (en) | Data processing method and device and electronic equipment | |
CN109842621A (en) | A kind of method and terminal reducing token storage quantity | |
CN114691309A (en) | Batch business processing system, method and device | |
CN111813579A (en) | Communication method, communication device, readable storage medium and file system | |
CN113220471A (en) | Data processing method and device, computing equipment and storage medium | |
CN113568976A (en) | A processing system, method, device and storage medium for delayed message | |
CN114328194B (en) | A method for implementing timeout retry execution based on Rocket MQ | |
US20130198138A1 (en) | Model for capturing audit trail data with reduced probability of loss of critical data | |
CN114489968A (en) | Task processing method, device, equipment and storage medium | |
CN113419832A (en) | Processing method and device of delay task and terminal | |
CN112667371A (en) | Asynchronous task processing method, device, equipment and storage medium | |
CN118151857A (en) | Data synchronization method, system, device, computer equipment and storage medium | |
CN113254467B (en) | Method and blockchain node for performing transactions in blockchain system | |
CN116842090A (en) | Accounting system, method, equipment and storage medium | |
CN110543349B (en) | Application starting acceleration method and device and computer readable storage medium | |
US7421711B2 (en) | System, method and apparatus for supporting a kernel mode driver | |
CN115760318A (en) | An order task update method, device, equipment and storage medium | |
CN115499425A (en) | Cloud platform file export method |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |