Spring Cloud整合XXL-Job的几个步骤
短信预约 -IT技能 免费直播动态提醒
本篇文章和大家了解一下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=8091server.tomcat.max-threads=10spring.application.name=service-order spring.datasource.driver-class-name=com.mysql.jdbc.Driverspring.datasource.url=jdbc:mysql://localhost:3306/shop?useSSL=false&serverTimezone=UTC&useUnicode=true&characterEncoding=utf8&userSSL=false&allowPublicKeyRetrieval=truespring.datasource.username=rootspring.datasource.password=123456 spring.jpa.properties.show-sql=truespring.jpa.properties.database=mysqlspring.jpa.properties.database-platform=mysqlspring.jpa.properties.hibernate.ddl-auto=updatespring.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-orderspring.cloud.nacos.config.namespace=publicspring.cloud.nacos.config.group=SEATE_GROUPspring.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 addressxxl.job.executor.appname=xxl-job-executor-samplexxl.job.executor.ip=xxl.job.executor.port=9999 ### xxl-job, access tokenxxl.job.accessToken= ### xxl-job log pathxxl.job.executor.logpath=/opt/module/xxl-job-2.0.1/jobhandler### xxl-job log retention daysxxl.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; }}
重点:
以上就是Spring Cloud整合XXL-Job的几个步骤的简略介绍,当然详细使用上面的不同还得要大家自己使用过才领会。如果想了解更多,欢迎关注编程网行业资讯频道哦!
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341