Task scheduling method, device and scheduling center
By configuring RabbitMQ dependencies and parameters in the scheduling center, and rewriting the execute method for message encapsulation processing, the problem of cumbersome task scheduling of RabbitMQ type is solved, and a simpler and more efficient task scheduling is achieved.
Patent Information
- Application Number
- CN202311685817.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-12-08
- Publication Date
- 2024-11-05
- Estimated Expiration
- 2043-12-08
AI Technical Summary
In business process automation and collaborative processing, the dispatch center needs to configure the executor of the dispatch task, which leads to cumbersome operations when generating push messages in some scenarios, especially when using RabbitMQ-type timing tasks.
Add RabbitMQ dependencies in the scheduling center and configure the parameters required for RabbitMQ messages. By rewriting the execute method, the message is encapsulated and processed and sent in the MQ message timing task executor, and supports custom switch name, queue name and routing key name.
The scheduling process of RabbitMQ type timing tasks has been simplified, making it more concise and efficient in multiple project scenarios, and has significantly improved the task scheduling method in related technologies.
Smart Images

Figure CN117724812B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of computer technology, and in particular to a task scheduling method, device and scheduling center. Background Art
[0002] The dispatch center can automatically perform task scheduling according to the predetermined time, frequency, priority and other rules to meet the enterprise's needs for business process automation and collaborative processing. When scheduling tasks, the dispatch center needs to configure the executor of the scheduling task, that is, configure the timeout time, number of failed retries, scheduling expiration strategy, blocking processing strategy, routing strategy, timing expression, operation mode, etc. of the scheduling task. However, in some scenarios, it is necessary to generate push messages in the business code. First, you need to write a job method in the microservice operation mode, and then create a scheduled task in the dispatch center to execute the job method regularly. This method is more cumbersome. Summary of the invention
[0003] In order to solve the above technical problems, the embodiments of the present application provide a task scheduling method, device and scheduling center.
[0004] In a first aspect of the present application, a task scheduling method is provided, which is applied to a scheduling center, comprising:
[0005] Polling scheduled tasks, and when the scheduled tasks meet the scheduled time, determining whether the scheduled tasks are of RabbitMQ type;
[0006] If yes, enter the RabbitMQ type executor to obtain the switch name, queue name and routing key name parameters;
[0007] Call the RabbitMQ service to send messages;
[0008] in,
[0009] The pom file of the scheduling center is configured with RabbitMQ dependency;
[0010] The trigger object is configured with the parameters required by the RabbitMQ message, including the queue switch, queue routing key, queue, and message body;
[0011] The client calls the execution task method of the executor service implementation class ExecutorBizImpl, which is configured with the judgment of the RabbitMQ type;
[0012] The scheduling center is configured with an MQ message scheduled task executor, which inherits the general executor IJobHandler. By overriding the execute method, the message encapsulation processing, switch encapsulation processing, queue encapsulation processing, routing key encapsulation processing are performed within the method, and the sending message type is configured to create an MQ message scheduled task executor.
[0013] In a second aspect of the present application, a task scheduling device is provided, which is applied to a scheduling center, and includes:
[0014] A task judgment module is used to poll the scheduled task and judge whether the scheduled task is of RabbitMQ type when the scheduled task meets the scheduled time;
[0015] A parameter acquisition module, used for entering the RabbitMQ type executor to obtain the switch name, queue name and routing key name parameters when the scheduled task is of RabbitMQ type;
[0016] Message sending module, used to call RabbitMQ service to send messages;
[0017] in,
[0018] The pom file of the scheduling center is configured with RabbitMQ dependency;
[0019] The trigger object is configured with the parameters required by the RabbitMQ message, including the queue switch, queue routing key, queue, and message body;
[0020] The client calls the execution task method of the executor service implementation class ExecutorBizImpl, which is configured with the judgment of the RabbitMQ type;
[0021] The scheduling center is configured with an MQ message scheduled task executor, which inherits the general executor IJobHandler. By overriding the execute method, the message encapsulation processing, switch encapsulation processing, queue encapsulation processing, routing key encapsulation processing are performed within the method, and the sending message type is configured to create an MQ message scheduled task executor.
[0022] In a third aspect of the present application, a dispatch center is provided, comprising a memory and a processor, wherein a computer program is stored in the memory, and when the processor executes the computer program, the method described in the first aspect is implemented.
[0023] In a possible implementation, the scheduling center supports customizing RabbitMQ switch names, queue names, and routing key names.
[0024] In the task scheduling method, device and scheduling center provided in the embodiment of the present application, the scheduled task is polled, and when the scheduled task meets the scheduled time, it is determined whether the scheduled task is of RabbitMQ type; if so, the RabbitMQ type executor is entered to obtain the switch name, queue name and routing key name parameters; the RabbitMQ service is called to send the message. Among them, the RabbitMQ dependency is configured in the pom file of the scheduling center; the parameters required for the RabbitMQ message are configured in the trigger object, and the parameters required for the RabbitMQ message include the queue switch, queue routing key, queue and message body; the client calls the execution task method of the executor service implementation class ExecutorBizImpl, which is configured with the judgment of the RabbitMQ type; the scheduling center is configured with an MQ message scheduled task executor, which inherits the general executor IJobHandler, and by rewriting the execute method, the message encapsulation processing, switch encapsulation processing, queue encapsulation processing, routing key encapsulation processing are performed in the method, and the sending message type is configured to create an MQ message scheduled task executor. The embodiment of the present application adopts the above-mentioned method to implement the scheduling center to support RabbitMQ type scheduled tasks in multiple projects and multiple scenarios, which is more concise and efficient than the task scheduling method in the related art.
[0025] It should be understood that the contents described in the Summary of the Invention are not intended to limit the key or important features of the embodiments of the present application, nor are they intended to limit the scope of the present application. Other features of the present application will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] The above and other features, advantages and aspects of the embodiments of the present application will become more apparent with reference to the following detailed description in conjunction with the accompanying drawings. In the accompanying drawings, the same or similar reference numerals represent the same or similar elements, wherein:
[0027] Figure 1 A flowchart of a task scheduling method according to an embodiment of the present application is shown;
[0028] Figure 2 A block diagram of a task scheduling device according to an embodiment of the present application is shown;
[0029] Figure 3 A schematic diagram of the structure of a dispatching center suitable for implementing the embodiment of the present application is shown. DETAILED DESCRIPTION
[0030] In order to make the purpose, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application.
[0031] In the related technology, when the scheduling center performs task scheduling, it needs to configure the executor of the scheduling task, that is, configure the timeout period of the scheduling task, the number of failed retries, the scheduling expiration strategy, the blocking processing strategy, the routing strategy, the timing expression (the timing expression is the execution rule of the scheduling task), the operation mode (the operation mode is the way in which the scheduling task is executed), etc.
[0032] However, in some scenarios, it is necessary to generate push messages in the business code. First, you need to write a job method in the microservice operation mode, and then create a scheduled task in the scheduling center to execute the job method on a scheduled basis. This operation is more cumbersome.
[0033] Next, the task scheduling method is further described in conjunction with one or more embodiments of this specification.
[0034] It should be noted that the task scheduling method provided in the embodiment of the present application can be executed by a scheduling center. To implement the scheduling center's support for RabbitMQ type scheduled tasks, the following method can be used:
[0035] First, you can add the RabbitMQ dependency in the pom file of the scheduling center to ensure that the scheduling center can use the MQ middleware to send messages.
[0036] Then, add the parameters required by the RabbitMQ message in the trigger object, where the parameters required by the RabbitMQ message include the queue switch, queue routing key, queue, and message body.
[0037] Finally, in the execution task method of the executor service implementation class ExecutorBizImpl called by the client, add a method to judge the RabbitMQ type.
[0038] If it is determined that the current scheduled task type is RabbitMQ type, the corresponding MQ message scheduled task executor is required to execute the scheduled task.
[0039] Therefore, it is also necessary to create an MQ message scheduled task executor, which inherits the general executor IJobHandler. By overriding the execute method, the message encapsulation processing, switch encapsulation processing, queue encapsulation processing, routing key encapsulation processing are performed within the method, and the sending message type is configured.
[0040] After the scheduling center supports RabbitMQ-type scheduled tasks, the scheduling center can perform the following operations when scheduling tasks: Figure 1 The task scheduling method shown.
[0041] See also Figure 1 , the task scheduling method includes the following steps:
[0042] Step 101, polling the scheduled task, when the scheduled task meets the scheduled time, determining whether the scheduled task is of RabbitMQ type.
[0043] Step 102, when the scheduled task is of RabbitMQ type, enter the RabbitMQ type executor to obtain the switch name, queue name and routing key name parameters.
[0044] Step 103: Call the RabbitMQ service to send a message.
[0045] Among them, the pom file of the scheduling center is configured with RabbitMQ dependency. The parameters required for RabbitMQ messages are configured in the trigger object, including queue switch, queue routing key, queue and message body. The client calls the execution task method of the executor service implementation class ExecutorBizImpl, which is configured with the judgment of RabbitMQ type. The scheduling center is configured with MQ message scheduled task executor, which inherits the general executor IJobHandler. By overriding the execute method, the method encapsulates the message, the switch, the queue, and the routing key, and configures the sending message type to create the MQ message scheduled task executor.
[0046] In the task scheduling method, device and scheduling center provided in the embodiment of the present application, the scheduled task is polled, and when the scheduled task meets the scheduled time, it is determined whether the scheduled task is of RabbitMQ type; if so, the RabbitMQ type executor is entered to obtain the switch name, queue name and routing key name parameters; the RabbitMQ service is called to send the message. Among them, the RabbitMQ dependency is configured in the pom file of the scheduling center; the parameters required for the RabbitMQ message are configured in the trigger object, and the parameters required for the RabbitMQ message include the queue switch, queue routing key, queue and message body; the client calls the execution task method of the executor service implementation class ExecutorBizImpl, which is configured with the judgment of the RabbitMQ type; the scheduling center is configured with an MQ message scheduled task executor, which inherits the general executor IJobHandler, and by rewriting the execute method, the message encapsulation processing, switch encapsulation processing, queue encapsulation processing, routing key encapsulation processing are performed in the method, and the sending message type is configured to create an MQ message scheduled task executor. The embodiment of the present application adopts the above-mentioned method to implement the scheduling center to support RabbitMQ type scheduled tasks in multiple projects and multiple scenarios, which is more concise and efficient than the task scheduling method in the related art.
[0047] It should be noted that, for the aforementioned method embodiments, for the sake of simplicity, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the present application is not limited by the described order of actions, because according to the present application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all optional embodiments, and the actions and modules involved are not necessarily required by the present application.
[0048] The above is an introduction to the method embodiment. The following is a further explanation of the scheme described in this application through an apparatus embodiment.
[0049] See also Figure 2 , the task scheduling device comprises:
[0050] The task determination module 201 is used to poll the scheduled task and determine whether the scheduled task is of RabbitMQ type when the scheduled task meets the scheduled time.
[0051] The parameter acquisition module 202 is used to enter the RabbitMQ type executor to obtain the switch name, queue name and routing key name parameters when the scheduled task is of RabbitMQ type.
[0052] The message sending module 203 is used to call the RabbitMQ service to send a message.
[0053] in,
[0054] The pom file of the scheduling center is configured with RabbitMQ dependency;
[0055] The trigger object is configured with the parameters required by the RabbitMQ message, including the queue switch, queue routing key, queue, and message body;
[0056] The client calls the execution task method of the executor service implementation class ExecutorBizImpl, which is configured with the judgment of the RabbitMQ type;
[0057] The scheduling center is configured with an MQ message scheduled task executor, which inherits the general executor IJobHandler. By overriding the execute method, the message encapsulation processing, switch encapsulation processing, queue encapsulation processing, routing key encapsulation processing are performed within the method, and the sending message type is configured to create an MQ message scheduled task executor.
[0058] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the described module can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.
[0059] The embodiment of the present application also provides a scheduling center that supports customizing the switch name, queue name, and routing key name of RabbitMQ.
[0060] See also Figure 3 , the dispatch center 300 includes: a processor 301 and a memory 303. The processor 301 and the memory 303 are connected, such as through a bus 302. Optionally, the dispatch center 300 may also include a transceiver 304. It should be noted that in actual applications, the transceiver 304 is not limited to one, and the structure of the dispatch center 300 does not constitute a limitation on the embodiments of the present application.
[0061] Processor 301 may be a CPU (Central Processing Unit), a general purpose processor, a DSP (Digital Signal Processor), an ASIC (Application Specific Integrated Circuit), an FPGA (Field Programmable Gate Array) or other programmable logic devices, transistor logic devices, hardware components or any combination thereof. It may implement or execute various exemplary logic blocks, modules and circuits described in conjunction with the disclosure of this application. Processor 301 may also be a combination that implements computing functions, such as a combination of one or more microprocessors, a combination of a DSP and a microprocessor, etc.
[0062] The bus 302 may include a path to transmit information between the above components. The bus 302 may be a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus. The bus 302 may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 3 Only one thick line is used in the diagram, but this does not mean that there is only one bus or only one type of bus.
[0063] The memory 303 can be a ROM (Read Only Memory) or other types of static storage devices that can store static information and instructions, a RAM (Random Access Memory) or other types of dynamic storage devices that can store information and instructions, or an EEPROM (Electrically Erasable Programmable Read Only Memory), a CD-ROM (Compact Disc Read Only Memory) or other optical disk storage, optical disk storage (including compressed optical disk, laser disk, optical disk, digital versatile disk, Blu-ray disk, etc.), a magnetic disk storage medium or other magnetic storage device, or any other medium that can be used to carry or store the desired program code in the form of instructions or data structures and can be accessed by a computer, but is not limited to these.
[0064] The memory 303 is used to store the application code for executing the solution of the present application, and the execution is controlled by the processor 301. The processor 301 is used to execute the application code stored in the memory 303 to implement the contents shown in the above method embodiment.
[0065] It should be understood that, although the steps in the flowchart of the accompanying drawings are displayed in sequence as indicated by the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least a part of the steps in the flowchart of the accompanying drawings may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a part of the sub-steps or stages of other steps.
[0066] The above description is only a partial implementation method of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.
Claims
1. A task scheduling method, applied to a scheduling center, characterized in that: include: Polling scheduled tasks, and when the scheduled tasks meet the scheduled time, determining whether the scheduled tasks are of RabbitMQ type; If yes, enter the RabbitMQ type executor to obtain the switch name, queue name, and routing key name parameters; Call the RabbitMQ service to send messages; in, The pom file of the scheduling center is configured with RabbitMQ dependency; The trigger object is configured with the parameters required by the RabbitMQ message, including the queue switch, queue routing key, queue, and message body. The client calls the execution task method of the executor service implementation class ExecutorBizImpl, which is configured with the judgment of the RabbitMQ type; The scheduling center is configured with an MQ message scheduled task executor, which inherits the general executor IJobHandler. By overriding the execute method, the message encapsulation processing, switch encapsulation processing, queue encapsulation processing, routing key encapsulation processing are performed within the method, and the sending message type is configured to create an MQ message scheduled task executor.
2. A task scheduling device, applied to a scheduling center, characterized in that: include: A task judgment module is used to poll the scheduled task and judge whether the scheduled task is of RabbitMQ type when the scheduled task meets the scheduled time; A parameter acquisition module, used for entering the RabbitMQ type executor to obtain the switch name, queue name and routing key name parameters when the scheduled task is of RabbitMQ type; Message sending module, used to call RabbitMQ service to send messages; in, The pom file of the scheduling center is configured with RabbitMQ dependency; The trigger object is configured with the parameters required by the RabbitMQ message, including the queue switch, queue routing key, queue, and message body. The client calls the execution task method of the executor service implementation class ExecutorBizImpl, which is configured with the judgment of the RabbitMQ type; The scheduling center is configured with an MQ message scheduled task executor, which inherits the general executor IJobHandler. By overriding the execute method, the message encapsulation processing, switch encapsulation processing, queue encapsulation processing, routing key encapsulation processing are performed within the method, and the sending message type is configured to create an MQ message scheduled task executor.
3. A dispatch center, comprising a memory and a processor, wherein a computer program is stored in the memory, characterized in that: When the processor executes the computer program, the method according to claim 1 is implemented.
4. The dispatch center according to claim 3, characterized in that: The scheduling center supports customizing the switch name, queue name, and routing key name of RabbitMQ.
