Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of SpringBoot Project Integration xxljob

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Editor to share with you the example analysis of SpringBoot project integration xxljob, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Xxljob introduction

XXL-JOB is a distributed task scheduling platform, and its core design goal is rapid development, easy learning, lightweight and easy to expand. Now open source code and access to a number of companies online product lines, out of the box.

It is called task scheduling center and can do scheduled tasks.

The advantages are as follows:

1. Simple: CRUD the task through the Web page. It is easy to operate and can be used in one minute.

2. Dynamic: support to dynamically modify task status, start / stop tasks, and terminate running tasks, effective immediately

3. Dispatching center HA (centralized): dispatching adopts central design. Dispatching center develops scheduling components and supports cluster deployment, which ensures dispatching center HA.

4. Executor HA (distributed): distributed task execution. Task "executor" supports cluster deployment to ensure task execution HA.

5. Registry: the executor will automatically register the task periodically, and the dispatch center will automatically discover the registered task and trigger the execution. At the same time, it also supports manual entry of actuator addresses.

6. Blocking processing strategy: processing strategy when scheduling is too dense for executors to process in time, including: single machine serial (default), discarding subsequent scheduling, scheduling before overwriting

7. Task timeout control: custom task timeout is supported. Task timeout will actively interrupt the task.

8. Task failure retry: custom task failure retry times are supported. When a task fails, it will actively retry according to the preset number of failed retries. Shard tasks support failed retry with sharding granularity.

9. Task failure alarm; email failure alarm is provided by default, while an extended interface is reserved for convenient expansion of SMS, nails and other alarm methods.

10. Task progress monitoring: support real-time monitoring of task progress

11. Rolling real-time log: supports online viewing of scheduling results, and supports real-time viewing of the complete execution log of the executor output in Rolling mode

12. Custom task parameters: online configuration and scheduling of task input parameters are supported, effective immediately

13. Data encryption: the communication between the dispatching center and the actuator encrypts the data to improve the security of scheduling information.

14. Mail alarm: email alarm is supported when a task fails, and multiple email addresses are supported to send alarm messages in groups.

Official website address: XXL open source community | Project

Code configuration process 1. The dependency com.xuxueli xxl-job-core 2.0.12 of xxl-job is introduced. Write configuration file xxl: job: admin: addresses: http://d-xxljob.dmsd.tech:8081/job-admin-dev # xxljob dispatching center deployment for example: http://127.0.0.1:8080/xxl-job-admin executor: appname: testJob # xxljob configuration executor name, ip: # actuator IP The default is empty to automatically obtain the port number configured by IP port: 9999 # xxljob, and the default is 9999 logpath: / data/xxl-job/jobhandler # executor running log file storage disk path logretentiondays:-1 # the number of days that log table data is saved in dispatching center, and the expired logs are cleaned automatically It takes effect when the limit is greater than or equal to 7, otherwise, such as-1, turn off the automatic cleaning function accessToken: # dispatching center communication TOKEN [optional]: enable 3 when non-empty. Write the configuration class / * xxl-job timer configuration, read the contents in the configuration file * * @ author Zhang Youbo * @ version 0.0.1 * @ since November 14, 2021 * / @ Configuration@ComponentScan (basePackages = "com.dmsdbj.integral.zentao.provider.job") / / configure the job class @ Slf4jpublic class XxlJobConfig {@ Value ("${xxl.job.admin.addresses}") private String adminAddresses to be scanned @ Value ("${xxl.job.executor.appname}") private String appName; @ Value ("${xxl.job.executor.ip}") private String ip; @ Value ("${xxl.job.executor.port}") private int port; @ Value ("${xxl.job.accessToken}") private String accessToken; @ Value ("${xxl.job.executor.logpath}") private String logPath @ Value ("${xxl.job.executor.logretentiondays}") private int logRetentionDays; @ Bean (initMethod = "start", destroyMethod = "destroy") public XxlJobSpringExecutor xxlJobExecutor () {log.info ("> xxl-job config init."); XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor (); xxlJobSpringExecutor.setAdminAddresses (adminAddresses); xxlJobSpringExecutor.setAppName (appName); xxlJobSpringExecutor.setIp (ip); xxlJobSpringExecutor.setPort (port) XxlJobSpringExecutor.setAccessToken (accessToken); xxlJobSpringExecutor.setLogPath (logPath); xxlJobSpringExecutor.setLogRetentionDays (logRetentionDays); return xxlJobSpringExecutor;} 4. Create a new Job folder and put the classes you wrote under this folder

Correspond to the XxlJobConfig class, the package to be scanned

5. Write business code package com.dmsdbj.integral.zentao.provider.job; import com.xxl.job.core.biz.model.ReturnT;import com.xxl.job.core.handler.IJobHandler;import com.xxl.job.core.handler.annotation.JobHandler;import com.xxl.job.core.log.XxlJobLogger;import lombok.extern.slf4j.Slf4j;import org.springframework.stereotype.Component / * the test class of XXLJob Need to inherit IJobHandler class * * @ author Promsing (Zhang Youbo) * @ version 1.0.0 * @ since 2021-11-14-19:51 * / @ Slf4j@Component@JobHandler (value = "TestJob") / / correspond to jobHandler on xxl-job as public class TestJob extends IJobHandler {/ * execute handler Invoked when executor receives a scheduling request * * @ param param * @ return * @ throws Exception * / @ Override public ReturnT execute (String param) {XxlJobLogger.log (this.getClass (). GetSimpleName () + "--start") Try {System.out.println ("Business Code 1"); System.out.println ("Business Code 2"); System.out.println ("Business Code 3"); System.out.println ("Business Code 4"); System.out.println ("Business Code 5") } catch (Exception e) {log.error (e.getMessage (), e); throw e;} XxlJobLogger.log (this.getClass (). GetSimpleName () + "--end"); return ReturnT.SUCCESS;}} log in to xxl-Job and configure 1. Actuator Management-New Actuator

two。 Task Management-New tasks

The configured parameters are as follows:

Here is a recommended website for parsing Cron: online Cron expression Builder

Testing: breakpoint debugging

View the scheduling log:

The process of configuring xxlJob is not very complicated, but it needs to be careful.

The above is all the contents of the article "sample Analysis of SpringBoot Project Integration xxljob". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report