Commit a6e8144f269a38c0d839294b54cf9741dc029329

Authored by xp.Huang
1 parent 44f989a8

feat: 将定时任务quartz的配置抽离到thingsboard.yml进行配置

1 package org.thingsboard.server.config.yunteng; 1 package org.thingsboard.server.config.yunteng;
2 2
3 -import lombok.AllArgsConstructor; 3 +import lombok.RequiredArgsConstructor;
  4 +import org.springframework.beans.factory.annotation.Value;
4 import org.springframework.context.annotation.Bean; 5 import org.springframework.context.annotation.Bean;
5 import org.springframework.context.annotation.Configuration; 6 import org.springframework.context.annotation.Configuration;
6 import org.springframework.scheduling.quartz.SchedulerFactoryBean; 7 import org.springframework.scheduling.quartz.SchedulerFactoryBean;
@@ -8,53 +9,87 @@ import org.springframework.scheduling.quartz.SchedulerFactoryBean; @@ -8,53 +9,87 @@ import org.springframework.scheduling.quartz.SchedulerFactoryBean;
8 import javax.sql.DataSource; 9 import javax.sql.DataSource;
9 import java.util.Properties; 10 import java.util.Properties;
10 11
11 -/**  
12 - * 定时任务配置(单机部署建议默认走内存,如需集群需要创建qrtz数据库表/打开类注释)  
13 - */ 12 +/** 定时任务配置(单机部署建议默认走内存,如需集群需要创建qrtz数据库表/打开类注释) */
14 @Configuration 13 @Configuration
15 -@AllArgsConstructor  
16 -public class ScheduleConfig  
17 -{  
18 - private final DataSource dataSource;  
19 - @Bean  
20 - public SchedulerFactoryBean schedulerFactoryBean()  
21 - {  
22 - SchedulerFactoryBean factory = new SchedulerFactoryBean();  
23 - factory.setDataSource(dataSource);  
24 -  
25 - // quartz参数  
26 - Properties prop = new Properties();  
27 - prop.put("org.quartz.scheduler.instanceName", "ThingKitScheduler");  
28 - prop.put("org.quartz.scheduler.instanceId", "AUTO");  
29 - // 线程池配置  
30 - prop.put("org.quartz.threadPool.class", "org.quartz.simpl.SimpleThreadPool");  
31 - prop.put("org.quartz.threadPool.threadCount", "20");  
32 - prop.put("org.quartz.threadPool.threadPriority", "5");  
33 - // JobStore配置  
34 - prop.put("org.quartz.jobStore.class", "org.springframework.scheduling.quartz.LocalDataSourceJobStore");  
35 - // 集群配置  
36 - prop.put("org.quartz.jobStore.isClustered", "true");  
37 - prop.put("org.quartz.jobStore.clusterCheckinInterval", "15000");  
38 - prop.put("org.quartz.jobStore.maxMisfiresToHandleAtATime", "1");  
39 -  
40 - // sqlserver 启用  
41 - // prop.put("org.quartz.jobStore.selectWithLockSQL", "SELECT * FROM {0}LOCKS UPDLOCK WHERE LOCK_NAME = ?");  
42 - // PostgreSQL 启用  
43 - prop.put("org.quartz.jobStore.driverDelegateClass", "org.quartz.impl.jdbcjobstore.PostgreSQLDelegate");  
44 - prop.put("org.quartz.jobStore.misfireThreshold", "12000");  
45 - prop.put("org.quartz.jobStore.tablePrefix", "QRTZ_");  
46 - factory.setQuartzProperties(prop);  
47 -  
48 - factory.setSchedulerName("ThingsKitScheduler");  
49 - // 延时启动  
50 - factory.setStartupDelay(1);  
51 - factory.setApplicationContextSchedulerContextKey("applicationContextKey");  
52 - // 可选,QuartzScheduler  
53 - // 启动时更新己存在的Job,这样就不用每次修改targetObject后删除qrtz_job_details表对应记录了  
54 - factory.setOverwriteExistingJobs(true);  
55 - // 设置自动启动,默认为true  
56 - factory.setAutoStartup(true);  
57 -  
58 - return factory;  
59 - } 14 +@RequiredArgsConstructor
  15 +public class ScheduleConfig {
  16 + private final DataSource dataSource;
  17 +
  18 + @Value("${spring.quartz.properties.org.quartz.scheduler.instanceName}")
  19 + private String instanceName;
  20 +
  21 + @Value("${spring.quartz.properties.org.quartz.scheduler.instanceId}")
  22 + private String instanceId;
  23 +
  24 + @Value("${spring.quartz.properties.org.quartz.threadPool.class}")
  25 + private String threadPoolClass;
  26 +
  27 + @Value("${spring.quartz.properties.org.quartz.threadPool.threadCount}")
  28 + private String threadCount;
  29 +
  30 + @Value("${spring.quartz.properties.org.quartz.threadPool.threadPriority}")
  31 + private String threadPriority;
  32 +
  33 + @Value("${spring.quartz.properties.org.quartz.jobStore.class}")
  34 + private String jobStoreClass;
  35 +
  36 + @Value("${spring.quartz.properties.org.quartz.jobStore.isClustered}")
  37 + private String isClustered;
  38 +
  39 + @Value("${spring.quartz.properties.org.quartz.jobStore.clusterCheckinInterval}")
  40 + private String clusterCheckinInterval;
  41 +
  42 + @Value("${spring.quartz.properties.org.quartz.jobStore.maxMisfiresToHandleAtATime}")
  43 + private String maxMisfiresToHandleAtATime;
  44 +
  45 + @Value("${spring.quartz.properties.org.quartz.jobStore.driverDelegateClass}")
  46 + private String driverDelegateClass;
  47 +
  48 + @Value("${spring.quartz.properties.org.quartz.jobStore.misfireThreshold}")
  49 + private String misfireThreshold;
  50 +
  51 + @Value("${spring.quartz.properties.org.quartz.jobStore.tablePrefix}")
  52 + private String tablePrefix;
  53 +
  54 + @Bean
  55 + public SchedulerFactoryBean schedulerFactoryBean() {
  56 + SchedulerFactoryBean factory = new SchedulerFactoryBean();
  57 + factory.setDataSource(dataSource);
  58 +
  59 + // quartz参数
  60 + Properties prop = new Properties();
  61 + prop.put("org.quartz.scheduler.instanceName", instanceName);
  62 + prop.put("org.quartz.scheduler.instanceId", instanceId);
  63 + // 线程池配置
  64 + prop.put("org.quartz.threadPool.class", threadPoolClass);
  65 + prop.put("org.quartz.threadPool.threadCount", threadCount);
  66 + prop.put("org.quartz.threadPool.threadPriority", threadPriority);
  67 + // JobStore配置
  68 + prop.put("org.quartz.jobStore.class", jobStoreClass);
  69 + // 集群配置
  70 + prop.put("org.quartz.jobStore.isClustered", isClustered);
  71 + prop.put("org.quartz.jobStore.clusterCheckinInterval", clusterCheckinInterval);
  72 + prop.put("org.quartz.jobStore.maxMisfiresToHandleAtATime", maxMisfiresToHandleAtATime);
  73 +
  74 + // sqlserver 启用
  75 + // prop.put("org.quartz.jobStore.selectWithLockSQL", "SELECT * FROM {0}LOCKS UPDLOCK WHERE
  76 + // LOCK_NAME = ?");
  77 + // PostgreSQL 启用
  78 + prop.put("org.quartz.jobStore.driverDelegateClass", driverDelegateClass);
  79 + prop.put("org.quartz.jobStore.misfireThreshold", misfireThreshold);
  80 + prop.put("org.quartz.jobStore.tablePrefix", tablePrefix);
  81 + factory.setQuartzProperties(prop);
  82 +
  83 + factory.setSchedulerName(instanceName);
  84 + // 延时启动
  85 + factory.setStartupDelay(1);
  86 + factory.setApplicationContextSchedulerContextKey("applicationContextKey");
  87 + // 可选,QuartzScheduler
  88 + // 启动时更新己存在的Job,这样就不用每次修改targetObject后删除qrtz_job_details表对应记录了
  89 + factory.setOverwriteExistingJobs(true);
  90 + // 设置自动启动,默认为true
  91 + factory.setAutoStartup(true);
  92 +
  93 + return factory;
  94 + }
60 } 95 }
@@ -546,6 +546,25 @@ spring: @@ -546,6 +546,25 @@ spring:
546 password: "${SPRING_DATASOURCE_PASSWORD:postgres}" 546 password: "${SPRING_DATASOURCE_PASSWORD:postgres}"
547 hikari: 547 hikari:
548 maximumPoolSize: "${SPRING_DATASOURCE_MAXIMUM_POOL_SIZE:16}" 548 maximumPoolSize: "${SPRING_DATASOURCE_MAXIMUM_POOL_SIZE:16}"
  549 + quartz:
  550 + properties:
  551 + org:
  552 + quartz:
  553 + scheduler:
  554 + instanceName: "${SPRING_QUARTZ_INSTANCE_NAME:ThingKitScheduler}"
  555 + instanceId: "${SPRING_QUARTZ_INSTANCE_ID:AUTO}"
  556 + jobStore:
  557 + class: "${SPRING_QUARTZ_JOB_STORE_CLASS:org.springframework.scheduling.quartz.LocalDataSourceJobStore}"
  558 + driverDelegateClass: "${SPRING_QUARTZ_JOB_STORE_DRIVER_DELEGATE_CLASS:org.quartz.impl.jdbcjobstore.PostgreSQLDelegate}"
  559 + misfireThreshold: "${SPRING_QUARTZ_JOB_STORE_MISFIRE_THRESHOLD:12000}"
  560 + tablePrefix: "${SPRING_QUARTZ_JOB_STORE_TABLE_PREFIX:QRTZ_}"
  561 + isClustered: "${SPRING_QUARTZ_JOB_STORE_IS_CLUSTERED:true}"
  562 + clusterCheckinInterval: "${SPRING_QUARTZ_JOB_STORE_CLUSTER_CHECKIN_INTERVAL:15000}"
  563 + maxMisfiresToHandleAtATime: "${SPRING_QUARTZ_JOB_STORE_MAX_MISFIRES_TO_HANDLE_AT_ATIME:1}"
  564 + threadPool:
  565 + class: "${SPRING_QUARTZ_THREAD_POOL_CLASS:org.quartz.simpl.SimpleThreadPool}"
  566 + threadCount: "${SPRING_QUARTZ_THREAD_POOL_THREAD_COUNT:100}"
  567 + threadPriority: "${SPRING_QUARTZ_THREAD_POOL_THREAD_PRIORITY:5}"
549 568
550 # Audit log parameters 569 # Audit log parameters
551 audit-log: 570 audit-log:
@@ -1195,10 +1214,10 @@ file: @@ -1195,10 +1214,10 @@ file:
1195 staticUrl: /static/files/** #oss静态访问路径 只有type = local需要 1214 staticUrl: /static/files/** #oss静态访问路径 只有type = local需要
1196 randomFileName: ${file.storage.randomFileName} 1215 randomFileName: ${file.storage.randomFileName}
1197 minio: 1216 minio:
1198 - minioUrl: ${MINIO_URL:http://localhost:9000} #minio储存地址 1217 + minioUrl: ${MINIO_URL:https://demo.thingskit.com:9000} #minio储存地址
1199 minioName: ${MINIO_NAME:thingskit} #minio账户 1218 minioName: ${MINIO_NAME:thingskit} #minio账户
1200 - minioPass: ${MINIO_PWD:thingskit} #minio访问密码  
1201 - bucketName: yunteng #minio储存桶名称 1219 + minioPass: ${MINIO_PWD:Dzr227+bjsz} #minio访问密码
  1220 + bucketName: yunteng-test #minio储存桶名称
1202 randomFileName: ${file.storage.randomFileName} 1221 randomFileName: ${file.storage.randomFileName}
1203 account: 1222 account:
1204 info: 1223 info: