[go: up one dir, main page]

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 PDF

Info

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
Application number
CN202111538304.XA
Other languages
Chinese (zh)
Other versions
CN114328194A (en
Inventor
王伟
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shenzhen Qianhai Huanrong Lianyi Information Technology Service Co Ltd
Original Assignee
Shenzhen Qianhai Huanrong Lianyi Information Technology Service Co Ltd
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by Shenzhen Qianhai Huanrong Lianyi Information Technology Service Co Ltd filed Critical Shenzhen Qianhai Huanrong Lianyi Information Technology Service Co Ltd
Priority to CN202111538304.XA priority Critical patent/CN114328194B/en
Publication of CN114328194A publication Critical patent/CN114328194A/en
Application granted granted Critical
Publication of CN114328194B publication Critical patent/CN114328194B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • YGENERAL 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
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE 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/00Energy 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

Method for implementing overtime retry execution based on socket mq
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)

1.一种基于rocket mq来实现超时重试执行方法,其特征在于,包括如下步骤:1. A method for implementing timeout retry execution based on Rocket MQ, characterized in that it includes the following steps: 步骤S1:应用程序启动时把所有需要超时重试的异步任务的任务触发方法绑定对应一个任务触发策略,并保存在应用缓存中;Step S1: When the application is started, the task triggering methods of all asynchronous tasks that need to time out and retry are bound to a corresponding task triggering strategy and saved in the application cache; 步骤S2:将任务触发方法的参数、任务触发策略、超时重试的时间、最大重试次数组装成任务消息,并发送给rocket mq;并设置任务消息的延时时间;Step S2: Assemble the parameters of the task trigger method, the task trigger strategy, the time of the timeout retry, and the maximum number of retries into a task message and send it to Rocket MQ; and set the delay time of the task message; 步骤S3:根据延时时间,rocket mq将任务消息推送给应用程序,应用程序根据所述任务触发策略,获取保存在应用缓存中对应的任务触发方法,根据所述任务触发方法,匹配所述任务触发方法的参数,完成超时重试;Step S3: Rocket MQ pushes the task message to the application according to the delay time. The application obtains the corresponding task trigger method stored in the application cache according to the task trigger strategy, matches the parameters of the task trigger method according to the task trigger method, and completes the timeout retry; 在所述步骤S3中,在匹配所述任务触发方法的参数之前,还先从数据库查询一下所述异步任务是否返回了结果,如是则不作处理,如否则重试次数+1;累加后,当当前重试次数等于或大于最大重试次数时,则不作处理,当当前重试次数小于最大重试次数时,则匹配所述任务触发方法的参数,完成超时重试;In step S3, before matching the parameters of the task triggering method, it is also checked from the database whether the asynchronous task has returned a result. If so, no processing is performed. If not, the number of retries is increased by 1. After accumulation, when the current number of retries is equal to or greater than the maximum number of retries, no processing is performed. When the current number of retries is less than the maximum number of retries, the parameters of the task triggering method are matched to complete the timeout retry. 步骤S1中,所述任务触发方法为基于反射获取的任务触发方法;并且,步骤S3中,是使用反射机制完成任务触发方法的调用来完成超时重试;In step S1, the task triggering method is a task triggering method based on reflection acquisition; and in step S3, the reflection mechanism is used to complete the call of the task triggering method to complete the timeout retry; 步骤S2中,所述任务触发策略、超时重试的时间、最大重试次数均在超时重试注解上设置;并且,步骤S1中,所有需要超时重试的异步任务为带有超时重试注解的异步任务。In step S2, the task triggering strategy, time of timeout retry, and maximum number of retries are all set on the timeout retry annotation; and in step S1, all asynchronous tasks that require timeout retry are asynchronous tasks with timeout retry annotation. 2.根据权利要求1所述的基于rocket mq来实现超时重试执行方法,其特征在于:步骤S2中,所述延时时间设置为所述超时重试的时间。2. According to the method for implementing timeout retry execution based on Rocket MQ in claim 1, it is characterized in that: in step S2, the delay time is set to the time of the timeout retry. 3.根据权利要求1所述的基于rocket mq来实现超时重试执行方法,其特征在于:步骤S2中,是通过写一个自定义的spring aop切面用于异步任务超时重试的超时重试注解拦截,将拦截的超时重试注解上的任务触发策略、超时重试的时间、最大重试次数、以及任务触发方法的参数组装成任务消息,并发送给rocket mq。3. According to the method for implementing timeout retry execution based on Rocket MQ in claim 1, it is characterized in that: in step S2, a custom Spring AOP aspect is written to intercept the timeout retry annotation of asynchronous task timeout retry, and the task triggering strategy, timeout retry time, maximum number of retries, and parameters of the task triggering method on the intercepted timeout retry annotation are assembled into a task message and sent to Rocket MQ.
CN202111538304.XA 2021-12-15 2021-12-15 A method for implementing timeout retry execution based on Rocket MQ Active CN114328194B (en)

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)

* Cited by examiner, † Cited by third party
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)

* Cited by examiner, † Cited by third party
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

Patent Citations (3)

* Cited by examiner, † Cited by third party
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