Xxl-job Github address github.com/xuxueli/xxl…
Xxl-job Document address www.xuxueli.com/xxl-job/
Docker deployment and scheduling center
- The new table
SQL statement in the project /xxl-job/doc/db/tables_xxl_job. SQL Executes statements to create databases and tables in the target database
- Pull the Docker image
# docker pull xuxueli/xxl-job-admin: version number docker pull xuxueli/xxl-job-admin:2.3.0Copy the code
- Start the
The parameters after -e PARAMS can be found at github.com/xuxueli/xxl… In reference to
Docker run - e PARAMS = "-- spring. The datasource. Url = JDBC: mysql: / / 127.0.0.1:3306 / nbot? useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=Asia/Shanghai --spring.datasource.username=nbot --spring.datasource.password=ySbPqDWLo --xxl.job.accessToken=dasj2nd81jf9asjdkl5jk234" -p 2222:8080 --name xxl-job-admin -d xuxueli/xxl-job-admin:2.3.0Copy the code
Note that the mysql address is not localhost or 127.0.0.1, but IP
Xxl.job. AccessToken = is the token used to communicate with the client. If the token is not empty, the client needs to fill in the same token in the production environment.
- Small mistake
Mysql 8 does not allow remote access when testing on the host
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
FLUSH PRIVILEGES;
Copy the code
- Access visual interface
Visit http://localhost:8086/xxl-job-admin, the default user name password: admin / 123456
After login, you can change the default user name and password, you can add users and so on
Two. Need to refactor
- To send mail, you need to use your own mail delivery method and have your own server, so you need to rewrite the source project
Add it to xxl-job-admin’s application.propertites
Enable =true # Mail server address spring.mail-api.url= # mail sending service key spring.mail-api.secretId= # Mail sending service key spring.mail-api.secretKey=Copy the code
Turn an existing SpringBoot project into an executor
- Maven rely on
<dependency>
<groupId>com.xuxueli</groupId>
<artifactId>xxl-job-core</artifactId>
<version>2.3.0</version>
</dependency>
Copy the code
- Modifying a Configuration File
Modify the Application. propertites of the SpringBoot project
### Dispatch center deployment and ADDRESS [Optional] : If multiple addresses exist in the dispatch center cluster deployment, separate them with commas (,). The executor will use this address for "executor heartbeat registration" and "task result callback". If it is null, auto registration is disabled. XXL. Job. Admin. Addresses = http://127.0.0.1:8080/xxl-job-admin # # # actuators communication TOKEN (optional) : not empty enabled when; Xxl.job. AccessToken = ### actuator AppName [optional] : actuator heartbeat registration group basis; Appname =xxl-job-executor-sample ### Executor registration: This configuration is preferred as the registration address. If this configuration is empty, the embedded service IP:PORT is used as the registration address. This supports container type executor dynamic IP and dynamically mapped port issues more flexibly. Xxl.job.executor. Address = ### executor IP address [optional] : The default value is empty, indicating that the IP address is automatically obtained. If multiple nics are used, you can manually set the specified IP address. Address information is used for "actuator registration" and "dispatch center requests and triggers tasks"; Xxl.job.executor. IP = ### The port number of the executor is smaller than or equal to 0. The default port number is 9999. If multiple actuators are deployed on a single machine, configure different actuators. Xxl.job.executor. port=9999 ### The path to the disk where the executor run log files are stored [Optional] : You need to have read and write permission on this path. If it is empty, the default path is used. Xxl.job.executor. Logpath =/data/applogs/ XXL -job/ jobHandler ### Number of days for storing executor log files [Optional] : Expired logs are automatically cleared. The validity takes effect when the limit value is greater than or equal to 3. Otherwise, for example, -1, disable the automatic clearing function. xxl.job.executor.logretentiondays=30Copy the code
- The registration service
The new Java class
@Slf4j @Configuration public class XxlJobConfig { @Value("${xxl.job.admin.addresses}") private String adminAddresses; @Value("${xxl.job.executor.appname}") private String appname; @Value("${xxl.job.executor.ip}") private String ip; @Value("${xxl.job.executor.port:9998}") 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 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; }}Copy the code
Then start the project and you can see the log reason printed with XXL information
>>>>>>>>>>> xxl-job remoting server start success, nettype = class com.xxl.job.core.server.EmbedServer, port = 9999
Copy the code
And so on, the registration is successful
If you cannot register, that is, the list of actuators does not have the actuators we just started, then first add the actuators we just started in the management interface
(Select Automatic registration)
Then, restart the executor project, say New Admin again, and here I have my own executor
- Scheduled Task development
@component public class HelloWorldJobHandler {/** * simple task */ @xxlJob ("sampleJobHandler") public void Slf4j @component public class HelloWorldJobHandler {/** * simple task */ @xxlJob ("sampleJobHandler") public void executeSampleJobHandler() { log.info("XXL-JOB, Hello World."); }}Copy the code
For more examples, see github.com/xuxueli/xxl…
“Reference”
- www.xuxueli.com/xxl-job/#%E…
- Juejin. Cn/post / 684490…