您好,登錄后才能下訂單哦!
本篇文章和大家了解一下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; } }
以上就是Spring Cloud整合XXL-Job的幾個步驟的簡略介紹,當然詳細使用上面的不同還得要大家自己使用過才領會。如果想了解更多,歡迎關注億速云行業資訊頻道哦!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。