使用Apache Quartz + Spring Boot进行作业调度

huangapple 未分类评论48阅读模式
英文:

Job Scheduling with Apache Quartz + Spring Boot

问题

我是Apache Quartz的新手,想在我的Spring Boot项目中使用它。我只想问几个问题。我已经阅读了文档,想要在项目中使用Quartz与PostgreSQL。然而,我的第一个问题是:

1-) JobDataMap用于在JobDetails中保存一些数据,因此在PostgreSQL中,文档表示:仅存储基本数据类型的JobDataMap,以避免短期和长期的数据序列化问题。

我能否在其中存储自定义对象?如果我想要安排多个作业类(如Job1.class,Job2.class,Job3.class等),它是否可以存储为不同的表?如果在PostgreSQL中是同一个表,jobDataMap列会不同,对吗?或者这取决于调度程序,即每个调度程序是否将存储为不同的表?

2-) 我无法确定我应该实现哪种方式。我想编写自己的Quartz库,以便我的微服务可以导入我的库并使用通用方法来注入Quartz和实现Job接口的相关类。这种方式我应该使用Spring Quartz还是仅使用Quartz?这对我来说似乎非常复杂,因为示例不太易读。也许我想得不对?

我是否能够仅使用Quartz库,使用PostgreSQL属性,如下所示:

org.quartz.jobStore.class=org.quartz.impl.jdbcjobstore.JobStoreTX
org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.PostgreSQLDelegate

并且仅仅导入Quartz依赖项

<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>2.2.3</version>

等等?我能否在连接到REST API时创建动态触发器、作业和作业详情,以便用户可以从外部创建作业?通过这种方式,我是否需要将触发器和作业配置为bean?我可以将它们提交给我的调度程序,其中包括动态创建的触发器和作业详情吗?

还是应该在我的pom.xml中导入spring-context-support,以便能够使用PersistableCronTriggerFactoryBean、SimpleTriggerFactoryBean、JobDetailFactoryBean等bean,并通过在某个Util类中编写静态方法来动态配置它们。

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context-support</artifactId>
</dependency>

有谁能够就我的问题提供一些想法并分享您的经验?谢谢!

英文:

I am new to Apache-Quartz and I want to use in my spring-boot project. I just want to ask a few questions. I have read the documentation and I want to use quartz with postgreSQL. However, my first question:

1-) JobDataMap is used for keep some data in JobDetails so in PostgreSQL, documentation says: Only store primitive data types JobDataMap to avoid data serialization issues short and long-term.

Can I store my custom objects in it ? Can it be stored as a different tables if I want to schedule more than one Job classes like Job1.class, Job2.class, Job3.class etc.? If it is same table in postgreSQL the jobDataMap column will be different, right ? Or does it depend to Scheduler to Scheduler I mean each Scheduler will be stored as different table ?

2-) I can not exactly understand that which way I should implement. I want to code my own quartz library so my microservices should import my library and use common methods to inject quartz and related classes which implement Job interface. This way should I use Spring quartz or just the quartz ? It looks to me very complicated because examples are not quite readable. May be I am thinking wrongly :/

Am I able to do that use only Quartz library with using PostgreSQL properties using

org.quartz.jobStore.class=org.quartz.impl.jdbcjobstore.JobStoreTX
org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.PostgreSQLDelegate

and only and only importing quartz dependency

        &lt;groupId&gt;org.quartz-scheduler&lt;/groupId&gt;
        &lt;artifactId&gt;quartz&lt;/artifactId&gt;
        &lt;version&gt;2.2.3&lt;/version&gt;

Job etc etc ? Can I create dynamic trigger,job & job details when I connect with the REST API, so users can able to create a job from outside ? With this way, do I need to configure trigger,job as a bean ? Can I submit them to my Scheduler with created dynamically Triggers & Job Details ?

Or should I import spring-context-support to my pom.xml to be able to use PersistableCronTriggerFactoryBean, SimpleTriggerFactoryBean, JobDetailFactoryBean beans and configure them dynamically by writing static methods in some Util class.

	&lt;dependency&gt;
	    &lt;groupId&gt;org.springframework&lt;/groupId&gt;
	    &lt;artifactId&gt;spring-context-support&lt;/artifactId&gt;
	&lt;/dependency&gt;

Can anyone give an idea about my questions & share your experience please ? 使用Apache Quartz + Spring Boot进行作业调度

Thanks !

huangapple
  • 本文由 发表于 2020年5月4日 22:16:03
  • 转载请务必保留本文链接:https://java.coder-hub.com/61594349.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定