Quartz Job configuration and store for mongodb

1,076 views
Skip to first unread message

Master Mind

unread,
Oct 9, 2016, 3:26:41 PM10/9/16
to Axon Framework Users

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,


Allard Buijze

unread,
Oct 12, 2016, 7:11:26 AM10/12/16
to Axon Framework Users
There is a Quartz-MongoDB project on GitHub. I haven't tried it, though.

--
You received this message because you are subscribed to the Google Groups "Axon Framework Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to axonframewor...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Master Mind

unread,
Oct 12, 2016, 7:43:07 AM10/12/16
to Axon Framework Users
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 ?

Allard Buijze

unread,
Oct 12, 2016, 7:46:55 AM10/12/16
to Axon Framework Users
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

Master Mind

unread,
Oct 12, 2016, 8:53:59 AM10/12/16
to Axon Framework Users
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.

Allard Buijze

unread,
Oct 12, 2016, 9:06:02 AM10/12/16
to Axon Framework Users
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
Reply all
Reply to author
Forward
0 new messages