I could not find any tutorial example from Axon that show case the Quartz integration for the deadline scheduling. The only thing I found is a post from this forum. https://groups.google.com/forum/#!topic/axonframework/mSpw9AJaDfE which really gives me a starting point (appreciate it). But do you happen to have a demo somewhere? Thanks.
Hi,
we have implemented Deadlines with Axon 4.1 and Quartz in a Spring Boot 2.0.6 application. The configuration patterns are quite similar throughout the framework so most of the configuration was quite intuitive. For the remaining parts I think I found my way also mostly via this forum and inspecting the Axon Framework code itself. I try to list the crucial parts (we use Spring Boot 2.0.6 and axon-spring-boot-starter, which comes with a lot of auto-configuration):
- add quartz to your classpath (we added spring-boot-starter-quartz)
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-quartz</artifactId>
</dependency>
- configure quartz to use persistence (if you need to - in most cases you should - to make deadlines survive application restarts)
spring.quartz.job-store-type=jdbc
spring.quartz.jdbc.initialize-schema=never
spring.quartz.properties.org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.PostgreSQLDelegate
-> you need to properly set up your spring.datasource.url (username, password) properly to point to a databse of your choice
-> for initializing the database schema for the jobstore you can either set the spring.quartz.jdbc.initialize-schema to always/embedded or you use something like liquibase to initialize the schema (which we did)
-> instead of a db-server like postgres (we used this since we have one running as the saga-store and token-store as well) you could also use an embedded database (like derby, hsqldb or h2)
-> if you just want to test everything you can set spring.quartz.job-store-type to memory and leave the latter two configurations out (quartz will store the scheduled jobs in memory, but apparently they will be lost on application restart)
- configure the Axon Deadline Manager to use Quartz (we use a Spring @Configuration class)
@Bean
public DeadlineManager deadlineManager(Scheduler scheduler, AxonConfiguration configuration) {
return QuartzDeadlineManager.builder()
.scheduler(scheduler)
.scopeAwareProvider(new ConfigurationScopeAwareProvider(configuration))
.serializer(axonJsonSerializer())
.build();
}
Thanks so much for the help. I was about to post what I did in my sample (I found out by going through the source code that the DeadlineManager construction changed to use builder pattern) But you replied before me with a complete sample. Great work.