Spring Cloud整合XXL-Job的示例代码
作者:冷艳无情的小妈 发布时间:2021-06-09 06:01:59
标签:Spring,Cloud,整合,XXL-Job
第一步:
整合pom文件,在Spring Cloud中添加XXL-Job的依赖
<!-- xxl-job-core -->
<dependency>
<groupId>com.xuxueli</groupId>
<artifactId>xxl-job-core</artifactId>
<version>2.0.1</version>
</dependency>
第二步:
把XXL-Job中的lohback.xml导入到Spring Cloud 项目中
<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="false" scan="true" scanPeriod="1 seconds">
<contextName>logback</contextName>
<!-- 日志文件位置-->
<property name="log.path" value="D:/ZM/xxl-job-executor-sample-springboot.log"/>
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} %contextName [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<appender name="file" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.path}</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${log.path}.%d{yyyy-MM-dd}.zip</fileNamePattern>
</rollingPolicy>
<encoder>
<pattern>%date %level [%thread] %logger{36} [%file : %line] %msg%n
</pattern>
</encoder>
</appender>
<root level="info">
<appender-ref ref="console"/>
<appender-ref ref="file"/>
</root>
</configuration>
第三步:
application.properties整合
server.port=8091
server.tomcat.max-threads=10
spring.application.name=service-order
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/shop?useSSL=false&serverTimezone=UTC&useUnicode=true&characterEncoding=utf8&userSSL=false&allowPublicKeyRetrieval=true
spring.datasource.username=root
spring.datasource.password=123456
spring.jpa.properties.show-sql=true
spring.jpa.properties.database=mysql
spring.jpa.properties.database-platform=mysql
spring.jpa.properties.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL57Dialect
spring.cloud.nacos.discovery.server-addr=192.168.136.1:8848
#跟控制台交流的端口,随意制定一个未使用的端口即可
spring.cloud.sentinel.transport.port=9999
#指定控制台服务的地址
spring.cloud.sentinel.transport.dashboard=localhost:8080
#关闭sentinel的CommonFilter实列化
spring.cloud.sentinel.filter.enabled=false
feign.sentinel.enabled=true
#通过修改配置来调整Ribbon的负载均衡策略
service-product.ribbon.NFLoadBalancerRuleClassName=com.netflix.loadbalancer.RandomRule
#rocketMQ服务的地址
rocketmq.name-server=192.168.136.111:9876
# 生产者组
rocketmq.producer.group=shop-order
spring.cloud.nacos.config.namespace=public
spring.cloud.nacos.config.group=SEATE_GROUP
spring.cloud.alibaba.seata.tx-service-group=${spring.application.name}
spring.cloud.nacos.config.env=dev
logging.config=classpath:logback.xml
### xxl-job admin address list, such as "http://address" or "http://address01,http://address02"
xxl.job.admin.addresses=http://192.168.136.111:8080/xxl-job-admin
### xxl-job executor address
xxl.job.executor.appname=xxl-job-executor-sample
xxl.job.executor.ip=
xxl.job.executor.port=9999
### xxl-job, access token
xxl.job.accessToken=
### xxl-job log path
xxl.job.executor.logpath=/opt/module/xxl-job-2.0.1/jobhandler
### xxl-job log retention days
xxl.job.executor.logretentiondays=-1
第四步:
向Spring Cloud中导入XxlJobConfig.class
@Configuration
@ComponentScan(basePackages = "com.xxl.job.executor.service.jobhandler")
public class XxlJobConfig {
private Logger logger = LoggerFactory.getLogger(XxlJobConfig.class);
@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}")
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() {
logger.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;
}
}
重点:
来源:https://blog.csdn.net/wuhahaq/article/details/130583300


猜你喜欢
- Android 获取手机信息应用信息:包名、版本号、版本名,手机是否有Root权限手机信息:手机屏幕宽和高、当前可用内存大小、总内存大小、I
- 新建一个类MyPageInterceptor.java(注意在springboot中要添加注解@Component)package com.
- 实现一个自定义的 @Conditional 派生注解自定义一个注解,继承 @Conditional 注解// 派生注解@Retention(
- 一、Error:All flavors must now belong to a named flavor dimension问题描述:Er
- 本文通过一个简单的小例子简述SharpZipLib压缩文件的常规用法,仅供学习分享使用,如有不足之处,还请指正。什么是SharpZipLib
- 本文实例讲述了C#模拟window操作鼠标的方法。分享给大家供大家参考。具体实现方法如下:using System;using System
- 如下所示:using System;using System.Collections.Generic;using System.Diagno
- 本文实例讲述了android编程实现图片库的封装方法。分享给大家供大家参考,具体如下:大家在做安卓应用的时候 经常要从网络中获取图片 都是通
- 1. 首先新建一个shiroConfig shiro的配置类,代码如下:@Configurationpublic class SpringS
- 前言在写项目的时候经常需要特定的时间做一些特定的操作,尤其是游戏服务器,维护线程之类的,这时候就需要用到定时器。如果此时你刚好用的是spri
- 一、线程池简介线程池的使用主要是解决两个问题:①当执行大量异步任务的时候线程池能够提供更好的性能,在不使用线程池时候,每当需要执行异步任务的
- 很多时候忘记Android摄像头如何打开,查看google文档的话,发现太复杂(只是单纯的想打开摄像头而已,不想添加那么多设置,添加那么功能
- 前言在Java中,集合和数组是我们经常会用到的数据结构,需要经常对他们做增、删、改、查、聚合、统计、过滤等操作。相比之下,关系型数据库中也同
- 本文实例讲述了WinForm中comboBox控件数据绑定实现方法。分享给大家供大家参考,具体如下:下面介绍三种对comboBox绑定的方式
- 本文实例讲述了Android编程实现自定义ProgressBar样式。分享给大家供大家参考,具体如下:效果图如下,本例中设置了第一级进度条和
- 本文实例为大家分享了Android实现随手指移动小球的具体代码,供大家参考,具体内容如下这个随手指移动小球,首先要使用paint画笔在can
- Java实现简单台球桌问题,供大家参考,具体内容如下需求:使小球可以在桌面上移动,移动到桌面边缘将被弹回,显示小区的移动素材:小球照片桌球照
- Bean Validation 中内置的 constraint @Null 被注释的元素必须为 null @NotNull 被注释的元素必须
- 引言在Google I/O 2014上,Google公布了Android L Preview版本,此版本的UI有了非常大的改变,很炫很给力!
- 本文接上文“java反射之方法反射的基本操作方法”,利用反射了解下java集合中泛型的本质1、初始化两个集合,一个使用泛型,一个不使用Arr