CN108334545A - A kind of method and device for realizing asynchronous service - Google Patents

A kind of method and device for realizing asynchronous service Download PDF

Info

Publication number
CN108334545A
CN108334545A CN201711441697.6A CN201711441697A CN108334545A CN 108334545 A CN108334545 A CN 108334545A CN 201711441697 A CN201711441697 A CN 201711441697A CN 108334545 A CN108334545 A CN 108334545A
Authority
CN
China
Prior art keywords
task
database
processing
queue
status
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.)
Granted
Application number
CN201711441697.6A
Other languages
Chinese (zh)
Other versions
CN108334545B (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.)
Weimeng Chuangke Network Technology China Co Ltd
Original Assignee
Weimeng Chuangke Network Technology China 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 Weimeng Chuangke Network Technology China Co Ltd filed Critical Weimeng Chuangke Network Technology China Co Ltd
Priority to CN201711441697.6A priority Critical patent/CN108334545B/en
Publication of CN108334545A publication Critical patent/CN108334545A/en
Application granted granted Critical
Publication of CN108334545B publication Critical patent/CN108334545B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor
    • G06F16/273Asynchronous replication or reconciliation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/546Message passing systems or structures, e.g. queues

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Databases & Information Systems (AREA)
  • Computing Systems (AREA)
  • Data Mining & Analysis (AREA)
  • Debugging And Monitoring (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

An embodiment of the present invention provides a kind of method and device for realizing asynchronous service, this method includes:The task with unique identification information is received, judges whether store the task in first database;If not storing the task in the first database, the task is created in the first database;The task status of task described in Initialize installation is creates, and the change of the task status by task described in first database described in state machine monitors;The task is inserted into the task queue of the second database, when the processing for receiving the task is asked, the task is obtained from the task queue by task treatment progress;The task status of the task got is updated in processing, according to state machine to the monitored results of the task status of the task, the processing operation to match to the task status of the task execution and the task.Through the invention, the reliability consumption of task is met while realizing high-performance treatments task.

Description

A kind of method and device for realizing asynchronous service
Technical field
The present invention relates to technical field of the computer network more particularly to a kind of method and devices for realizing asynchronous service.
Background technology
With the development of computer technology, people’s lives increasingly be unable to do without internet, therewith, at internet data The timeliness and accuracy of reason also require higher and higher.Currently, having asynchronous place for Message Processing in the rear end of major network system Reason and synchronization process two ways.The synchronization process of message refers to terminating as consumer has to wait for processing side when handling message Subsequent operation could be carried out later;The asynchronous process of message refers to can be into after message unreachable message processing side such as consumer Other operations of row, Message Processing result is using readjustment or without call-back manner end operation.
For the scene for needing high-performance high concurrent, asynchronous mode largely may be used, message is handled, leads to Cross the distributed consumption for carrying out message;For needing the scene generally use method of synchronization of strong consistency to handle message, Ensure that message carries out and only carries out one-time-consumption.
But the demand that can have high-performance and consistency in actual application scenarios, in order to meet this demand, existing skill In art, usually operation flow is split, to the logic progress asynchronization raising performance for influencing performance and can be asynchronous, then profit It is handled with the queue of reliability consumption, (is such as a use increased income using Redis to ensure that data are finally consistent ANSI C writes, support network, can based on memory also can persistence log type, Key-Value databases), Kafka (be A kind of distributed post of high-throughput subscribes to message system) etc. the additional queue consumption model of queue services realize high performance disappear Asynchronization consumption is ceased, parallel dilatation can be reached by simple distributed deployment to meet the field of various high-performance high concurrents Scape.
In realizing process of the present invention, inventor has found that at least there are the following problems in the prior art:Although can utilize The additional queue consumption model of the queue services such as Redis, Kafka realizes high performance message asynchronization consumption, by simply dividing Cloth deployment can reach parallel dilatation to meet the scene of various high-performance high concurrents, still, can not meet strongly consistent simultaneously The demand of property.
Invention content
The embodiment of the present invention provides a kind of method and device for realizing asynchronous service, realizes the same of high-performance treatments task When meet task reliability consumption.
On the one hand, an embodiment of the present invention provides a kind of methods for realizing asynchronous service, including:
The task with unique identification information is received, and according to the unique identification information of the task, judges the first data Whether the task is stored in library;
If not storing the task in the first database, the task is created in the first database;
The task status of task described in Initialize installation is to create, and pass through institute in first database described in state machine monitors The change for stating the task status of task, for controlling the idempotence of the task;
The task is inserted into the task queue of the second database, when the processing for receiving the task is asked, is led to It crosses task treatment progress and obtains the task from the task queue;
The task status of the task got is updated in processing, according to state machine to the task shape of the task The monitored results of state, the processing operation to match to the task status of the task execution and the task.
On the other hand, an embodiment of the present invention provides a kind of devices for realizing asynchronous service, including:
Reception and judging unit, for receiving the task with unique identification information, and according to unique mark of the task Know information, judges whether store the task in first database;
Creating unit creates if for not storing the task in the first database in the first database The task;
Setting and monitoring unit, the task status for task described in Initialize installation are to create, and supervised by state machine The change for controlling the task status of task described in the first database, for controlling the idempotence of the task;
Insertion and acquiring unit, it is described when receiving for the task to be inserted into the task queue of the second database When the processing request of task, the task is obtained from the task queue by task treatment progress;
Update and execution unit, for the task status of the task got to be updated in processing, according to state Machine is to the monitored results of the task status of the task, the place to match to the task status of the task execution and the task Reason operation.
Above-mentioned technical proposal has the advantages that:According to unique identification information existing for each task, ensure that The uniqueness of each task, and important premise guarantee is provided for the idempotence of guarantee task;By in first database The task status of middle store tasks provides necessary precondition, together to realize by the idempotence of state machine control task When, ensure that mission reliability consumption provides important premise guarantee to be follow-up;Queue is realized in sharp task queue to greatest extent High-performance, to realize meet while high-performance treatments task task reliability consumption, further, improve use The usage experience at family.
Description of the drawings
In order to more clearly explain the embodiment of the invention or the technical proposal in the existing technology, to embodiment or will show below There is attached drawing needed in technology description to be briefly described, it should be apparent that, the accompanying drawings in the following description is only this Some embodiments of invention for those of ordinary skill in the art without creative efforts, can be with Obtain other attached drawings according to these attached drawings.
Fig. 1 is a kind of method flow diagram for realizing asynchronous service in one embodiment of the invention;
Fig. 2 is a kind of apparatus structure schematic diagram for realizing asynchronous service in another embodiment of the present invention;
Fig. 3 is the visioning procedure schematic diagram of task in one embodiment of the present invention;
Fig. 4 be in the method for realized in another preferred embodiment of the present invention asynchronous service task treatment progress cluster from task The flow diagram of task is obtained in queue cluster;
Fig. 5 is the processing procedure flow signal of task in the method for realized in another preferred embodiment of the present invention asynchronous service Figure;
Fig. 6 is that task repairs flow diagram in the method for realized in another preferred embodiment of the present invention asynchronous service.
Specific implementation mode
Following will be combined with the drawings in the embodiments of the present invention, and technical solution in the embodiment of the present invention carries out clear, complete Site preparation describes, it is clear that described embodiments are only a part of the embodiments of the present invention, instead of all the embodiments.It is based on Embodiment in the present invention, it is obtained by those of ordinary skill in the art without making creative efforts every other Embodiment shall fall within the protection scope of the present invention.
As shown in Figure 1, for a kind of flow chart of method that realizing asynchronous service in the embodiment of the present invention, including:
101, the task with unique identification information is received, and according to the unique identification information of the task, judges first Whether the task is stored in database;
If 102, not storing the task in the first database, the task is created in the first database;
103, the task status of task described in Initialize installation is to create, and pass through first database described in state machine monitors Described in task task status change, for controlling the idempotence of the task;
104, the task is inserted into the task queue of the second database, when the processing for receiving the task is asked When, the task is obtained from the task queue by task treatment progress;
105, the task status of the task got is updated in processing, the task is appointed according to state machine The monitored results of business state, the processing operation to match to the task status of the task execution and the task.
Preferably, described to judge the task whether is stored in first database, it specifically includes:
According to the unique identification information of the task, judge the task whether is cached in the caching of first database;
Wherein, described that the task is created in the first database, it specifically includes:
The task is written in the caching of the first database;
Wherein, the task status include create, in processing, handle successfully and processing failure.
Optionally, further include:
If being stored with the task in the first database, the task is returned to by the first database Mission bit stream;
Wherein, the mission bit stream includes the already present notification information of the task and the unique mark letter of the task Breath.
Preferably, described to be inserted into the task in the task queue of the second database, when the place for receiving the task When reason request, the task is obtained from the task queue by task treatment progress, including:
The task is inserted into the task queue of the second database, and has successfully been created by first database return The mission bit stream for the task built;
When the processing for receiving the task is asked, the task letter based on the task that the first database returns Breath, the task is obtained by task treatment progress from the task queue of the second database;
Wherein, the task queue of second database is the queue based on atomic operation.
Optionally, further include:
Task queue cluster is pre-created in second database;
Pre-create task treatment progress cluster;
Wherein, described when the processing for receiving the task is asked, based on described in first database return The mission bit stream of business obtains the task by task treatment progress from the task queue of the second database, including:
When the processing for receiving the task is asked, judge whether to receive described that the first database returns The mission bit stream of business, the processing request of the task include the unique identification information of the task;
If receiving, according to it is described processing request described in task unique identification information, by the task handle into Any task treatment progress in Cheng Jiqun obtains described appoint from the task queue cluster pre-created in second database Business;
If not receiving, according to the unique identification information of task described in the processing request, frequency is obtained based on predetermined By the task treatment progress cluster task is obtained from the task queue cluster pre-created in second database.
Preferably, the task status by the task got is updated in processing, according to state machine to described The monitored results of the task status of task, to the processing operation that the task status of the task execution and the task matches, Including:
The task status of the task got is updated in processing, is the task in processing to task status The callback operation of execution task, and whether the callback operation for monitoring the task is more than scheduled time threshold;
If being more than, it is based on predetermined operation agreement, the task execution task is adjusted back;
Wherein, described that the task execution task is adjusted back, including:
Step A judges whether succeed to task execution task readjustment;
If readjustment failure, is updated to processing failure, and based in predetermined operation agreement by the task status of the task Number is adjusted back, the task execution task is adjusted back again, redirects and executes step A, until readjustment number reaches the predetermined behaviour Make the readjustment number in agreement or adjusts back successfully;
If adjusting back successfully, the task status of the task is updated to handle successfully, and terminates the processing to the task.
Optionally, further include in the task queue cluster task repair queue, it is described according to state machine to the task The monitored results of task status the processing operation that the task status of the task execution and the task matches also is wrapped It includes:
There are task statuses in scheduled duration to be continuously establishment in by state machine monitors to the first database When first task, the first task is inserted into the task in second database and repairs queue, it is described first to complete The establishment of business;
There are task statuses in scheduled duration to be continuously in processing in by state machine monitors to the first database The second task when, second task is inserted into the task and repairs queue, to complete the processing of second task;
Wherein, the scheduled duration is more than the predetermined time span for obtaining the unit interval in frequency.
It is a kind of apparatus structure schematic diagram for realizing asynchronous service in another embodiment of the present invention shown in Fig. 2, including:
Reception and judging unit 21, for receiving the task with unique identification information, and according to the unique of the task Identification information judges the task whether is stored in first database;
Creating unit 22 is created if for not storing the task in the first database in the first database Build the task;
Setting and monitoring unit 23, the task status for task described in Initialize installation are to create, and pass through state machine The change for monitoring the task status of task described in the first database, for controlling the idempotence of the task;
Insertion and acquiring unit 24, for the task to be inserted into the task queue of the second database, when receiving When stating the processing request of task, the task is obtained from the task queue by task treatment progress;
Update and execution unit 25, for the task status of the task got to be updated in processing, according to shape State machine matches to the task status of the task execution and the task to the monitored results of the task status of the task Processing operation.
Preferably, the reception and judging unit, specifically include:
Judgment module judges whether delay in the caching of first database for the unique identification information according to the task Deposit the task;
Wherein, the creating unit, is specifically used for
The task is written in the caching of the first database;
Wherein, the task status include create, in processing, handle successfully and processing failure.
Optionally, further include:
Returning unit passes through the first database if for being stored with the task in the first database Return to the mission bit stream of the task;
Wherein, the mission bit stream includes the already present notification information of the task and the unique mark letter of the task Breath.
Preferably, the insertion and acquiring unit, including:
It is inserted into and is returned module, for the task to be inserted into the task queue of the second database, and passes through described the One database returns to the mission bit stream of the task successfully created;
Acquisition module, the institute for when the processing for receiving the task is asked, being returned based on the first database The mission bit stream for stating task obtains the task by task treatment progress from the task queue of the second database;
Wherein, the task queue of second database is the queue based on atomic operation.
Optionally, further include:
First pre-creates unit, for pre-creating task queue cluster in second database;
Second pre-creates unit, for pre-creating task treatment progress cluster;
Wherein, the acquisition module is specifically used for
When the processing for receiving the task is asked, judge whether to receive described that the first database returns The mission bit stream of business, the processing request of the task include the unique identification information of the task;
If receiving, according to it is described processing request described in task unique identification information, by the task handle into Any task treatment progress in Cheng Jiqun obtains described appoint from the task queue cluster pre-created in second database Business;
If not receiving, according to the unique identification information of task described in the processing request, frequency is obtained based on predetermined By the task treatment progress cluster task is obtained from the task queue cluster pre-created in second database.
Preferably, the update and execution unit, including:
Update and monitoring module, for the task status of the task got to be updated in processing, to task shape State is the callback operation of the task execution task in processing, and whether the callback operation for monitoring the task is more than scheduled Time threshold;
If execution module is based on predetermined operation agreement for being more than, and is adjusted back to the task execution task;
Wherein, the execution module, including:
Judging submodule, for judging whether succeed to task execution task readjustment;
Submodule is executed and redirected, if for adjusting back failure, the task status of the task is updated to processing failure, and Based on the readjustment number in predetermined operation agreement, the task execution task is adjusted back again, redirects execution judging submodule, directly Reach the readjustment number in the predetermined operation agreement to readjustment number or adjusts back successfully;
If the task status of the task is updated to handle successfully by update and end submodule for adjusting back successfully, and Terminate the processing to the task.
Optionally, further include that task repairs queue, the update and execution unit in the task queue cluster, also wrap It includes:
First is inserted into module, for when by the way that there are tasks in scheduled duration in state machine monitors to the first database When state is continuously the first task of establishment, the first task is inserted into the task in second database and repairs queue, To complete the establishment of the first task;
Second is inserted into module, for when by the way that there are tasks in scheduled duration in state machine monitors to the first database When state is continuously the second task in processing, second task is inserted into task reparation queue, to complete described the The processing of two tasks;
Wherein, the scheduled duration is more than the predetermined time span for obtaining the unit interval in frequency.
Above-mentioned technical proposal of the embodiment of the present invention has the advantages that:According to unique mark existing for each task Information ensure that the uniqueness of each task, and provide important premise guarantee for the idempotence of guarantee task;By The task status of store tasks in first database, for realize by the idempotence of state machine control task provide it is necessary before Condition is put forward, meanwhile, ensure that mission reliability consumption provides important premise guarantee to be follow-up;Sharp task queue comes to greatest extent The high-performance for realizing queue, to realize the reliability consumption for meeting task while high-performance treatments task, further, Improve the usage experience of user.
Above-mentioned technical proposal of the embodiment of the present invention is described in detail below in conjunction with application example:
Application example of the present invention meets the reliability consumption of task while seeking to fill that high-performance treatments task.
As shown in Figure 1, for example, in the task processes of asynchronous service A, pass through API (Application Programming Interface, application programming interface) task with unique identification information is submitted to rear end, and By api interface, asynchronous service is submitted the data to using the POST request method in HTTP request method, such as asynchronous service A, Subsequent asynchronous service A receives the task with unique identification information, if unique identification information is the task of task_id, then, According to the unique identification information task_id of the task, first database is judged, such as MySQL (Relational DBMS), In whether store the task, if non-store tasks task_id in MySQL, task task_id is created in MySQL;Initialization is set The task status for setting task task_id is to create, and pass through the task status of task task_id in state machine monitors MySQL Change, for controlling the idempotence of the task;Task task_id is inserted into the second database, such as Redis, task team In row, when the processing for receiving task task_id is asked, task is obtained from the task queue by task treatment progress task_id;The task status of the task task_id got is updated in processing, according to state machine to task task_id's The monitored results of task status execute the processing operation to match with the task status of task task_id to task task_id.
It should be noted that those skilled in the art it can be appreciated that refer to the characteristics of an idempotent operation in programming It is identical as the influence once executed that generated influence is arbitrarily performed a plurality of times in it.Idempotent function or idempotent method, referring to can be with It is repeated using identical parameters, and the function of identical result can be obtained.These functions do not interfere with system mode, without load The heart, which repeats, to be caused to change to system.Therefore, the idempotence of task refers to that task is arbitrarily performed a plurality of times to be produced in the present invention Raw influence is identical as the primary execution influence of task.
In a preferred embodiment, the step of judging whether to store the task in first database described in step 101, It specifically includes:According to the unique identification information of the task, judge the task whether is cached in the caching of first database.
Wherein, the step of creating the task in the first database described in step 102, specifically includes:By institute The task of stating is written in the caching of the first database.
Wherein, the task status include create, in processing, handle successfully and processing failure.
For example, in the task processes of asynchronous service A, the task with unique identification information is received, such as unique mark Know the task that information is task_id and then according to the unique identification information task_id of the task, judges first database, such as MySQL, caching in whether cache task task_id;If uncached, task task_id is created in MySQL, and by task Task_id is written in the caching of MySQL, and the visioning procedure of task task_id is with reference to figure 3.
Through this embodiment, it to realize that the reliability consumption of task provides necessary precondition, avoids first When being stored with the waiting task received in database, the feelings for creating the already present task are repeated in first database Condition occurs, and the resource of system has been saved, to improve the treatment effeciency of task.
In a preferred embodiment, this method further includes:If being stored with the task in the first database, lead to Cross the mission bit stream that the first database returns to the task.
Wherein, the mission bit stream includes the already present notification information of the task and the unique mark letter of the task Breath.
For example, in the task processes of asynchronous service A, the task with unique identification information is received, such as unique mark Know the task that information is task_id and then according to the unique identification information task_id of the task, judges first database, such as MySQL, tables of data in be stored with task task_id, then return to the mission bit stream of task task_id by MySQL, such as appoint The unique identification information task_id of business task_id already present notification information and task task_id.
In another example for example, in the task processes of asynchronous service A, the task with unique identification information is received, such as Unique identification information is that the task of task_id then according to the unique identification information task_id of the task, judges the first data Library, such as MySQL, caching in be stored with task task_id, then the mission bit stream of task task_id is returned by MySQL, Such as the unique identification information task_id of the already present notification informations of task task_id and task task_id.
In a preferred embodiment, the task is inserted into the task queue of the second database by step 104, when receiving When the processing request of the task, the task is obtained from the task queue by task treatment progress, including:It will be described Task is inserted into the task queue of the second database, and returns to the task successfully created by the first database Mission bit stream;When the processing for receiving the task is asked, the task based on the task that the first database returns Information obtains the task by task treatment progress from the task queue of the second database.
Wherein, the task queue of second database is the queue based on atomic operation.
For example, in the task processes of asynchronous service A, the task with unique identification information is received, such as unique mark Know the task that information is task_id then to store task task_id to first database, in MySQL, task is set The task status of the initialization of task_id passes through task task_id in state machine monitors MySQL if task status is to create Task status then task task_id is written in the caching of MySQL, and by task task_id the second data of radom insertion Library, such as Redis, any task queue in, and the mission bit stream of task task_id successfully created is returned to by MySQL, When the processing for receiving task task_id is asked, based on the mission bit stream of the MySQL task task_id returned, pass through task Treatment progress obtains task task_id from the task queue of Redis.
It should be noted that those skilled in the art are it can be appreciated that atomic operation refers to a service logic to be Or the failure of can not be split or successful execution does not execute completely.Those skilled in the art will also be appreciated that the present invention is real It is the queue based on atomic operation to apply the queue in the Redis databases in example, and the realization method of atom queue has more clocks, this hair Though bright can illustrate by taking the realization method of specific atom queue as an example, do not limit herein.
In a preferred embodiment, this method further includes:Task queue cluster is pre-created in second database;In advance Establishment task treatment progress cluster.
Wherein, described when the processing for receiving the task is asked, based on described in first database return The mission bit stream of business obtains the task by task treatment progress from the task queue of the second database, including:Work as reception To the task processing request when, judge whether to receive the mission bit stream for the task that the first database returns, The processing request of the task includes the unique identification information of the task;If receiving, institute in being asked according to the processing The unique identification information for stating task is counted by any task treatment progress in the task treatment progress cluster from described second According to obtaining the task in the task queue cluster pre-created in library;If not receiving, appoint according to described in processing request The unique identification information of business, it is pre- from second database by the task treatment progress cluster based on predetermined acquisition frequency The task is obtained in the task queue cluster of establishment.
For example, pre-creating task queue cluster M in the second database Redis, task queue cluster M includes multiple Task queue, such as task queue 1, task queue 2 and task queue 3;Pre-create task treatment progress cluster, including multiple tasks Treatment progress, as using Stark (be one as multi-process finger daemon in order to run the program library of PHP code) cluster, Including Stark1 and Stark2;In the task processes of asynchronous service A, when the processing for receiving task task_id is asked When, judge whether the mission bit stream for receiving the task task_id that the first database MySQL is returned, task task_id's Processing request includes the unique identification information task_id of the task;If receiving the mission bit stream of the task task_id of return When, according to the unique identification information task_id of task task_id, by any task treatment progress in Stark clusters, such as Stark1 obtains task task_id from the task queue cluster M pre-created in Redis;If not receiving the task of return When the mission bit stream of task_id, according to the unique identification information task_id of task task_id, frequency is obtained based on predetermined, such as 0.01 second/time of acquisition frequency obtains task by Stark clusters from the task queue cluster M pre-created in Redis task_id.The flow diagram of task is obtained from task queue cluster with reference to the task treatment progress cluster in figure 4.
Through this embodiment, high-performance and the Stark distributed consumers model of Redis queues are utilized to greatest extent to carry The performance of high system, to dramatically realize the high-performance of task consumption.
In a preferred embodiment, the task status of the task got is updated in processing by step 105, according to State machine matches to the task status of the task execution and the task to the monitored results of the task status of the task Processing operation, including:The task status of the task got is updated in processing, is in processing to task status The callback operation of the task execution task, and whether the callback operation for monitoring the task is more than scheduled time threshold;If It is more than to be based on predetermined operation agreement, the task execution task is adjusted back.
Wherein, described that the task execution task is adjusted back, including:Step A judges to adjust back the task execution task Whether succeed;If readjustment failure, is updated to processing failure, and based in predetermined operation agreement by the task status of the task Number is adjusted back, the task execution task is adjusted back again, redirects and executes step A, until readjustment number reaches the predetermined behaviour Make the readjustment number in agreement or returns successfully;If adjusting back successfully, the task status of the task is updated to handle successfully, and tie Processing of the beam to the task.
For example, in the task processes of asynchronous service A, when task treatment progress cluster has been obtained such as Stark clusters After the mission bit stream for getting task task_id, the task status of the task task_id got is updated in processing, it is right Task status is the callback operation of the task task_id execution tasks in processing, such as adjusts back the corresponding business of task task_id and connects The operation of mouth, and whether the callback operation of monitor task task_id is more than scheduled time threshold, such as 5 minutes;If more than predetermined Time threshold 5 minutes, be based on predetermined operation agreement, such as reach an agreement with business side for when the callback operation of task is more than to make a reservation for Time threshold when, execute the agreement of 1 callback operation again to the task, then, task readjustment executed to task task_id Operation, and judge to execute whether task readjustment succeeds to task task_id, if readjustment failure, by the task shape of task task_id State is updated to processing failure, and based on the readjustment number 1 time in predetermined operation agreement, executes task to task task_id again Readjustment;If adjusting back successfully, the task status of task task_id is updated to handle successfully, and terminates the place to task task_id Reason.The processing procedure of task is with reference to figure 5.
In a preferred embodiment, further include that task repairs queue, root described in step 105 in the task queue cluster According to state machine to the monitored results of the task status of the task, to the task status phase of the task execution and the task The step of processing operation matched, further include:There are appoint in scheduled duration in by state machine monitors to the first database When business state is continuously the first task of establishment, the first task is inserted into the task in second database and repairs team Row, to complete the establishment of the first task;There are in scheduled duration in by state machine monitors to the first database When task status is continuously the second task in processing, second task is inserted into the task and repairs queue, to complete State the processing of the second task.
Wherein, the scheduled duration is more than the predetermined time span for obtaining the unit interval in frequency.For example, pre- timing Between the section time span that is be 10 minutes, then make a reservation for obtain the time span of the unit interval of frequency and be less than 10 minutes.
For example, in the task processes of asynchronous service A, there is pre- timing in by state machine monitors to MySQL Between in section, in 10 minutes, when task status is continuously the task task_01 of establishment, using Crontab, (crontab orders are often Among the operating system for seeing Unix and class Unix, for the instruction being periodically performed to be arranged) task task_01 is inserted into Task in Redis repairs queue, to continue to complete establishment task task_01, until completing to create in task repairs queue Task task_01.Flow diagram is repaired with reference to the task in figure 6.
In another example in the task processes of asynchronous service A, exist in by state machine monitors to MySQL predetermined In period, as in 10 minutes, when task status is continuously the task task_02 in processing, using Crontab by task The task that task_02 is inserted into Redis repairs queue, to continue to complete processing task task_02, until repairing queue in task Middle completion processing task task_02.Flow diagram is repaired with reference to the task in figure 6.
Through this embodiment, it realizes and abnormal task is repaired when task is consumed, ensure that abnormal task also can quilt It executes, to ensure that the reliability consumption of task, realizes the reliability for meeting task while high-performance treatments task Consumption.
An embodiment of the present invention provides a kind of device for realizing asynchronous service, the method that above-mentioned offer may be implemented is implemented Example, concrete function realize the explanation referred in embodiment of the method, and details are not described herein.
It should be understood that the particular order or level of the step of during disclosed are the examples of illustrative methods.Based on setting Count preference, it should be appreciated that in the process the step of particular order or level can be in the feelings for the protection domain for not departing from the disclosure It is rearranged under condition.Appended claim to a method is not illustratively sequentially to give the element of various steps, and not It is to be limited to the particular order or level.
In above-mentioned detailed description, various features are combined together in single embodiment, to simplify the disclosure.No This published method should be construed to reflect such intention, that is, the embodiment of theme claimed needs to compare The more features of feature clearly stated in each claim.On the contrary, as appended claims is reflected Like that, the present invention is in the state fewer than whole features of disclosed single embodiment.Therefore, appended claims It is hereby expressly incorporated into detailed description, wherein each claim is used as alone the individual preferred embodiment of the present invention.
For so that any technical staff in the art is realized or using the present invention, above to disclosed embodiment into Description is gone.To those skilled in the art;The various modifications mode of these embodiments will be apparent from, and this The General Principle of text definition can also be suitable for other embodiments on the basis of not departing from the spirit and scope of the disclosure. Therefore, the disclosure is not limited to embodiments set forth herein, but most wide with principle disclosed in the present application and novel features Range is consistent.
Described above includes the citing of one or more embodiments.Certainly, in order to describe above-described embodiment and description portion The all possible combination of part or method is impossible, but it will be appreciated by one of ordinary skill in the art that each implementation Example can do further combinations and permutations.Therefore, embodiment described herein is intended to cover fall into the appended claims Protection domain in all such changes, modifications and variations.In addition, with regard to the term used in specification or claims The mode that covers of "comprising", the word is similar to term " comprising ", just as " including " solved in the claims as link word As releasing.In addition, the use of any one of specification in claims term "or" being to indicate " non-exclusionism Or ".
Those skilled in the art will also be appreciated that the various illustrative components, blocks that the embodiment of the present invention is listed (illustrative logical block), unit and step can pass through the knot of electronic hardware, computer software, or both Conjunction is realized.To clearly show that the replaceability (interchangeability) of hardware and software, above-mentioned various explanations Property component (illustrative components), unit and step universally describe their function.Such work( Can be that the design requirement for depending on specific application and whole system is realized by hardware or software.Those skilled in the art Can be for each specific function of applying, the realization of various methods can be used described, but this realization is understood not to Range beyond protection of the embodiment of the present invention.
Various illustrative logical blocks or unit described in the embodiment of the present invention can by general processor, Digital signal processor, application-specific integrated circuit (ASIC), field programmable gate array or other programmable logic devices, discrete gate Or described function is realized or is operated in transistor logic, the design of discrete hardware components or any of the above described combination.General place It can be microprocessor to manage device, and optionally, which may be any traditional processor, controller, microcontroller Device or state machine.Processor can also be realized by the combination of computing device, such as digital signal processor and microprocessor, Multi-microprocessor, one or more microprocessors combine a digital signal processor core or any other like configuration To realize.
The step of method described in the embodiment of the present invention or algorithm can be directly embedded into hardware, processor execute it is soft The combination of part module or the two.Software module can be stored in RAM memory, flash memory, ROM memory, EPROM storages Other any form of storaging mediums in device, eeprom memory, register, hard disk, moveable magnetic disc, CD-ROM or this field In.Illustratively, storaging medium can be connect with processor, so that processor can read information from storaging medium, and It can be to storaging medium stored and written information.Optionally, storaging medium can also be integrated into processor.Processor and storaging medium can To be set in ASIC, ASIC can be set in user terminal.Optionally, processor and storaging medium can also be set to use In different components in the terminal of family.
In one or more illustrative designs, above-mentioned function described in the embodiment of the present invention can be in hardware, soft Part, firmware or the arbitrary of this three combine to realize.If realized in software, these functions can store and computer-readable On medium, or with one or more instruction or code form be transmitted on the medium of computer-readable.Computer readable medium includes electricity Brain storaging medium and convenient for allow computer program to be transferred to from a place telecommunication media in other places.Storaging medium can be with It is that any general or special computer can be with the useable medium of access.For example, such computer readable media may include but It is not limited to RAM, ROM, EEPROM, CD-ROM or other optical disc storage, disk storage or other magnetic storage devices or other What can be used for carry or store with instruct or data structure and it is other can be by general or special computer or general or specially treated The medium of the program code of device reading form.In addition, any connection can be properly termed computer readable medium, example Such as, if software is to pass through a coaxial cable, fiber optic cables, double from a web-site, server or other remote resources Twisted wire, Digital Subscriber Line (DSL) are defined with being also contained in for the wireless way for transmitting such as example infrared, wireless and microwave In computer readable medium.The disk (disk) and disk (disc) includes compress disk, radium-shine disk, CD, DVD, floppy disk And Blu-ray Disc, disk is usually with magnetic duplication data, and disk usually carries out optical reproduction data with laser.Combinations of the above It can also be included in computer readable medium.
Above-described specific implementation mode has carried out further the purpose of the present invention, technical solution and advantageous effect It is described in detail, it should be understood that the foregoing is merely the specific implementation mode of the present invention, is not intended to limit the present invention Protection domain, all within the spirits and principles of the present invention, any modification, equivalent substitution, improvement and etc. done should all include Within protection scope of the present invention.

Claims (14)

1. a kind of method for realizing asynchronous service, which is characterized in that including:
The task with unique identification information is received, and according to the unique identification information of the task, is judged in first database Whether the task is stored;
If not storing the task in the first database, the task is created in the first database;
The task status of task described in Initialize installation is to create, and pass through described in first database described in state machine monitors The change of the task status of business, for controlling the idempotence of the task;
The task is inserted into the task queue of the second database, when the processing for receiving the task is asked, by appointing Business treatment progress obtains the task from the task queue;
The task status of the task got is updated in processing, according to state machine to the task status of the task Monitored results, the processing operation to match to the task status of the task execution and the task.
2. according to the method described in claim 1, it is characterized in that, described judge whether store described appoint in first database Business, specifically includes:
According to the unique identification information of the task, judge the task whether is cached in the caching of first database;
Wherein, described that the task is created in the first database, it specifically includes:
The task is written in the caching of the first database;
Wherein, the task status include create, in processing, handle successfully and processing failure.
3. according to the method described in claim 2, it is characterized in that, further including:
If being stored with the task in the first database, the task of the task is returned by the first database Information;
Wherein, the mission bit stream includes the unique identification information of the task already present notification information and the task.
4. according to the method described in claim 3, it is characterized in that, the task team that the task is inserted into the second database In row, when the processing for receiving the task is asked, described appoint is obtained from the task queue by task treatment progress Business, including:
The task is inserted into the task queue of the second database, and successfully created by first database return The mission bit stream of the task;
When the processing for receiving the task is asked, the mission bit stream based on the task that the first database returns, The task is obtained from the task queue of the second database by task treatment progress;
Wherein, the task queue of second database is the queue based on atomic operation.
5. according to the method described in claim 4, it is characterized in that, further including:
Task queue cluster is pre-created in second database;
Pre-create task treatment progress cluster;
Wherein, described when the processing for receiving the task is asked, the task based on first database return Mission bit stream obtains the task by task treatment progress from the task queue of the second database, including:
When the processing for receiving the task is asked, judge whether the task for receiving the first database return Mission bit stream, the processing request of the task include the unique identification information of the task;
If receiving, according to the unique identification information of task described in the processing request, pass through the task treatment progress collection Any task treatment progress in group obtains the task from the task queue cluster pre-created in second database;
If not receiving, according to the unique identification information of task described in the processing request, passed through based on predetermined acquisition frequency The task treatment progress cluster obtains the task from the task queue cluster pre-created in second database.
6. according to the method described in claim 5, it is characterized in that, the task status by the task got updates For in processing, according to state machine to the monitored results of the task status of the task, to the task execution and the task The processing operation that task status matches, including:
The task status of the task got is updated in processing, is the task execution in processing to task status The callback operation of task, and whether the callback operation for monitoring the task is more than scheduled time threshold;
If being more than, it is based on predetermined operation agreement, the task execution task is adjusted back;
Wherein, described that the task execution task is adjusted back, including:
Step A judges whether succeed to task execution task readjustment;
If readjustment failure, is updated to processing failure, and based on the readjustment in predetermined operation agreement by the task status of the task Number again adjusts back the task execution task, redirects and executes step A, until readjustment number reaches the predetermined operation association Readjustment number in view is adjusted back successfully;
If adjusting back successfully, the task status of the task is updated to handle successfully, and terminates the processing to the task.
7. according to the method described in claim 5, it is characterized in that, further including that task repairs team in the task queue cluster Row, it is described according to state machine to the monitored results of the task status of the task, the task execution and the task are appointed The processing operation that business state matches further includes:
There are first that task status in scheduled duration is continuously establishment in by state machine monitors to the first database When task, the first task is inserted into the task in second database and repairs queue, to complete the first task It creates;
The be continuously there are task status in scheduled duration in by state machine monitors to the first database in processing When two tasks, second task is inserted into the task and repairs queue, to complete the processing of second task;
Wherein, the scheduled duration is more than the predetermined time span for obtaining the unit interval in frequency.
8. a kind of device for realizing asynchronous service, which is characterized in that including:
Reception and judging unit are believed for receiving the task with unique identification information, and according to the unique mark of the task Breath, judges the task whether is stored in first database;
Creating unit, if for not storing the task in the first database, in the first database described in establishment Task;
Setting and monitoring unit, the task status for task described in Initialize installation are to create, and pass through state machine monitors institute The change for stating the task status of task described in first database, for controlling the idempotence of the task;
It is inserted into and acquiring unit, for the task to be inserted into the task queue of the second database, when receiving the task Processing request when, the task is obtained from the task queue by task treatment progress;
Update and execution unit, for the task status of the task got to be updated in processing, according to state machine pair The monitored results of the task status of the task grasp the processing that the task status of the task execution and the task matches Make.
9. device according to claim 8, which is characterized in that the reception and judging unit specifically include:
Judgment module judges institute whether is cached in the caching of first database for the unique identification information according to the task State task;
Wherein, the creating unit, is specifically used for
The task is written in the caching of the first database;
Wherein, the task status include create, in processing, handle successfully and processing failure.
10. device according to claim 9, which is characterized in that further include:
Returning unit is returned if for being stored with the task in the first database by the first database The mission bit stream of the task;
Wherein, the mission bit stream includes the unique identification information of the task already present notification information and the task.
11. device according to claim 10, which is characterized in that the insertion and acquiring unit, including:
It is inserted into and is returned module, for the task to be inserted into the task queue of the second database, and is counted by described first The mission bit stream of the task successfully created is returned according to library;
Acquisition module, for when receive the task processing ask when, based on the first database return described in appoint The mission bit stream of business obtains the task by task treatment progress from the task queue of the second database;
Wherein, the task queue of second database is the queue based on atomic operation.
12. according to the devices described in claim 11, which is characterized in that further include:
First pre-creates unit, for pre-creating task queue cluster in second database;
Second pre-creates unit, for pre-creating task treatment progress cluster;
Wherein, the acquisition module is specifically used for
When the processing for receiving the task is asked, judge whether the task for receiving the first database return Mission bit stream, the processing request of the task include the unique identification information of the task;
If receiving, according to the unique identification information of task described in the processing request, pass through the task treatment progress collection Any task treatment progress in group obtains the task from the task queue cluster pre-created in second database;
If not receiving, according to the unique identification information of task described in the processing request, passed through based on predetermined acquisition frequency The task treatment progress cluster obtains the task from the task queue cluster pre-created in second database.
13. device according to claim 12, which is characterized in that the update and execution unit, including:
Update and monitoring module are to task status for the task status of the task got to be updated in processing The callback operation of the task execution task in processing, and whether the callback operation for monitoring the task is more than the scheduled time Threshold value;
If execution module is based on predetermined operation agreement for being more than, and is adjusted back to the task execution task;
Wherein, the execution module, including:
Judging submodule, for judging whether succeed to task execution task readjustment;
Submodule is executed and redirected, if for adjusting back failure, the task status of the task is updated to processing failure, and be based on Readjustment number in predetermined operation agreement again adjusts back the task execution task, redirects execution judging submodule, until returning Number is adjusted to reach the readjustment number in the predetermined operation agreement or adjust back successfully;
If the task status of the task is updated to handle successfully, and terminate by update and end submodule for adjusting back successfully Processing to the task.
14. device according to claim 12, which is characterized in that further include that task repairs team in the task queue cluster Row, the update and execution unit further include:
First is inserted into module, for when by the way that there are task statuses in scheduled duration in state machine monitors to the first database When being continuously the first task of establishment, the first task is inserted into the task in second database and repairs queue, with complete At the establishment of the first task;
Second is inserted into module, for when by the way that there are task statuses in scheduled duration in state machine monitors to the first database When the second task being continuously in processing, second task is inserted into the task and repairs queue, to complete described second The processing of business;
Wherein, the scheduled duration is more than the predetermined time span for obtaining the unit interval in frequency.
CN201711441697.6A 2017-12-27 2017-12-27 Method and device for realizing asynchronous service Active CN108334545B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201711441697.6A CN108334545B (en) 2017-12-27 2017-12-27 Method and device for realizing asynchronous service

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201711441697.6A CN108334545B (en) 2017-12-27 2017-12-27 Method and device for realizing asynchronous service

Publications (2)

Publication Number Publication Date
CN108334545A true CN108334545A (en) 2018-07-27
CN108334545B CN108334545B (en) 2021-09-03

Family

ID=62923620

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201711441697.6A Active CN108334545B (en) 2017-12-27 2017-12-27 Method and device for realizing asynchronous service

Country Status (1)

Country Link
CN (1) CN108334545B (en)

Cited By (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109558254A (en) * 2018-11-21 2019-04-02 北京京东尚科信息技术有限公司 Asynchronism callback method, system, device and computer readable storage medium
CN110119305A (en) * 2019-05-13 2019-08-13 北京达佳互联信息技术有限公司 Task executing method, device, computer equipment and storage medium
CN110532108A (en) * 2019-08-15 2019-12-03 北京拉勾网络技术有限公司 Processing method, device, server and the system of resume delivery task
CN110751384A (en) * 2019-09-30 2020-02-04 口碑(上海)信息技术有限公司 Service monitoring method and device
CN110928746A (en) * 2019-11-14 2020-03-27 杭州天宽科技有限公司 Configurable service processing system, method, device and storage medium
CN111130951A (en) * 2019-12-31 2020-05-08 中消云(北京)物联网科技研究院有限公司 Equipment state detection method, device and storage medium
WO2020211376A1 (en) * 2019-04-15 2020-10-22 平安科技(深圳)有限公司 Method and apparatus for executing task by means of cluster server, and device and storage medium
CN112051993A (en) * 2020-08-17 2020-12-08 腾讯科技(深圳)有限公司 State machine template generation and task processing method, device, medium and equipment
CN113384874A (en) * 2021-05-27 2021-09-14 深圳市大头互动文化传播有限公司 Asynchronous solution method for game
CN116561221A (en) * 2023-04-21 2023-08-08 清华大学 Distributed time sequence database copy consensus protocol method supporting Internet of things scene

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20160004577A1 (en) * 2014-07-07 2016-01-07 International Business Machines Corporation Technology for stall detection
CN106095585A (en) * 2016-06-22 2016-11-09 中国建设银行股份有限公司 Task requests processing method, device and enterprise information system
CN107193827A (en) * 2016-03-14 2017-09-22 阿里巴巴集团控股有限公司 Divide the idempotent control method and device of storehouse point table

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20160004577A1 (en) * 2014-07-07 2016-01-07 International Business Machines Corporation Technology for stall detection
CN107193827A (en) * 2016-03-14 2017-09-22 阿里巴巴集团控股有限公司 Divide the idempotent control method and device of storehouse point table
CN106095585A (en) * 2016-06-22 2016-11-09 中国建设银行股份有限公司 Task requests processing method, device and enterprise information system

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
王一拙等: "一种支持容错的任务并行程序设计模型", 《软件学报》 *

Cited By (16)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109558254B (en) * 2018-11-21 2021-04-30 北京京东尚科信息技术有限公司 Asynchronous callback method, system, device and computer readable storage medium
CN109558254A (en) * 2018-11-21 2019-04-02 北京京东尚科信息技术有限公司 Asynchronism callback method, system, device and computer readable storage medium
WO2020211376A1 (en) * 2019-04-15 2020-10-22 平安科技(深圳)有限公司 Method and apparatus for executing task by means of cluster server, and device and storage medium
CN110119305A (en) * 2019-05-13 2019-08-13 北京达佳互联信息技术有限公司 Task executing method, device, computer equipment and storage medium
CN110119305B (en) * 2019-05-13 2022-01-21 北京达佳互联信息技术有限公司 Task execution method and device, computer equipment and storage medium
CN110532108A (en) * 2019-08-15 2019-12-03 北京拉勾网络技术有限公司 Processing method, device, server and the system of resume delivery task
CN110751384A (en) * 2019-09-30 2020-02-04 口碑(上海)信息技术有限公司 Service monitoring method and device
CN110928746A (en) * 2019-11-14 2020-03-27 杭州天宽科技有限公司 Configurable service processing system, method, device and storage medium
CN110928746B (en) * 2019-11-14 2023-10-24 杭州天宽科技有限公司 Configurable business processing system, method, device and storage medium
CN111130951A (en) * 2019-12-31 2020-05-08 中消云(北京)物联网科技研究院有限公司 Equipment state detection method, device and storage medium
CN111130951B (en) * 2019-12-31 2022-08-23 中消云(北京)物联网科技研究院有限公司 Equipment state detection method, device and storage medium
CN112051993A (en) * 2020-08-17 2020-12-08 腾讯科技(深圳)有限公司 State machine template generation and task processing method, device, medium and equipment
CN112051993B (en) * 2020-08-17 2023-10-24 腾讯科技(深圳)有限公司 Method, device, medium and equipment for generating state machine template and processing task
CN113384874A (en) * 2021-05-27 2021-09-14 深圳市大头互动文化传播有限公司 Asynchronous solution method for game
CN116561221A (en) * 2023-04-21 2023-08-08 清华大学 Distributed time sequence database copy consensus protocol method supporting Internet of things scene
CN116561221B (en) * 2023-04-21 2024-03-19 清华大学 Method for supporting distributed time sequence database copy consensus protocol of Internet of things scene

Also Published As

Publication number Publication date
CN108334545B (en) 2021-09-03

Similar Documents

Publication Publication Date Title
CN108334545A (en) A kind of method and device for realizing asynchronous service
CN109862065B (en) File downloading method and device and electronic equipment
US9984140B1 (en) Lease based leader election system
US11099891B2 (en) Scheduling requests based on resource information
US7478179B2 (en) Input/output priority inheritance wherein first I/O request is executed based on higher priority
CN105786448B (en) A kind of instruction dispatching method and device
US10929184B2 (en) Bandwidth aware resource optimization
US20200089594A1 (en) Artificial intelligence for load testing
US11314545B2 (en) Predicting transaction outcome based on artifacts in a transaction processing environment
CN111866099B (en) Method, device, system, equipment and storage medium for downloading mirror image file
US20170255498A1 (en) Dynamically optimized device driver protocol assist threads
CN109634989B (en) HIVE task execution engine selection method and system
CN108123851A (en) The lifetime detection method and device of main and subordinate node synchronization link in distributed system
CN106815251A (en) Distributed data base system, data bank access method and device
CN111061690B (en) RAC-based database log file reading method and device
CN108733585B (en) Cache system and related method
CN114489997A (en) Timing task scheduling method, device, equipment and medium
CN107015855A (en) A kind of asynchronous service centralized dispatching method and device for supporting time parameter method
CN117076096A (en) Task flow execution method and device, computer readable medium and electronic equipment
US20150112929A1 (en) Parallel Truncation Point Management for Log Based Replication
JP2017182783A (en) System and method for automated end-to-end web interaction testing
US20080282247A1 (en) Method and Server for Synchronizing a Plurality of Clients Accessing a Database
US20130219088A1 (en) Configurable prioritization of data transmission in a data storage topology
CN113821174B (en) Storage processing method, storage processing device, network card equipment and storage medium
US9851908B2 (en) Methods for managing read access of objects in storage media and devices thereof

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