Quartz Job configuration and store for mongodb

Hi,

I am creating my first Saga (I started using axon a month ago) along with Quartz scheduler for firing events in the future.

I am asking you fellow axonners if anyone had already created / used mongodb as a store for Quartz ? If it is the case could you please share the config and relevant code concerning that?

Thanks in advance,

There is a Quartz-MongoDB project on GitHub. I haven’t tried it, though.
https://github.com/michaelklishin/quartz-mongodb

Thanks Allard I am trying it right now … How should I register the the Mongo store for QuartzEventScheduler ? I have added the dependency in the classpath and added the quartz.properties but even though It is using RAMJobStore instead of using MongoDBJobStore may be I should set the store in via SchedulerFactoryBean ?

Inc ase you use Spring and the QuartzEventSchedulerFactoryBean, you have to have a bean of type Scheduler in your context. It’s probably easiest to use Spring’s SchedulerFactoryBean for this.

Cheers,

Allard

Hi Allard,

I am using Spring, I have tried to configure the EventScheduler with SchedulerFactoryBean like this:

@Bean
public EventScheduler eventScheduler(EventBus eventBus, SchedulerFactoryBean schedulerFactoryBean) {
    final QuartzEventScheduler quartzEventScheduler = new QuartzEventScheduler();
    quartzEventScheduler.setEventBus(eventBus);
    quartzEventScheduler.setScheduler(schedulerFactoryBean.getScheduler());

    return quartzEventScheduler;
}

but it picks always RAMJobStore, I am using the SpringResourceInjector

Here is my Saga configuration class

String sagaCollection = "sagas";

@Bean
public SagaRepository sagaRepository() {
    MongoTemplate template = new DefaultMongoTemplate(mongo, databaseName, sagaCollection , null, null);
    MongoSagaRepository rep = new MongoSagaRepository(template);
    rep.setResourceInjector(resourceInjector());
    return rep;
}

@Bean
public AnnotatedSagaManager sagaManager(SagaRepository sagaRepository, EventBus eventBus) {
    final AnnotatedSagaManager annotatedSagaManager = new AnnotatedSagaManager(
            sagaRepository, sagaFactory(),
            PostStatusSaga.class
    );
    eventBus.subscribe(annotatedSagaManager);
    return annotatedSagaManager;
}

@Bean
public SagaFactory sagaFactory() {
    final GenericSagaFactory sagaFactory = new GenericSagaFactory();
    sagaFactory.setResourceInjector(resourceInjector());
    return sagaFactory;
}

@Bean
public EventScheduler eventScheduler(EventBus eventBus, SchedulerFactoryBean schedulerFactoryBean) {
    final QuartzEventScheduler quartzEventScheduler = new QuartzEventScheduler();
    quartzEventScheduler.setEventBus(eventBus);
    quartzEventScheduler.setScheduler(schedulerFactoryBean.getScheduler());

    return quartzEventScheduler;
}

@Bean
public ResourceInjector resourceInjector() {
    return new SpringResourceInjector();
}

@Bean
public SchedulerFactoryBean eventSchedulerFactoryBean() {
    return new SchedulerFactoryBean();
}

Thanks a lot for your efforts.

Hi,

you probably need to explicitly reference the configuration file in your SchedulerFactoryBean.
Note that it’s a FactoryBean, so you shouldn’t (have to) inject it as a dependency directly in your EventScheduler bean configuration. Instead, pass the Scheduler as a parameter in that method. Spring will resolve the dependency through the SchedulerFactoryBean.

Cheers,

Allard