DeadlineManager bean definition

Hi Everyone,
I’m trying to use Axon Framework (4.7.3) with Spring Boot. Stuck on DeadlineManager configuration. I supposed that Spring autoconfiguration will do all the job due axon-spring-boot-starter dependency. Like it did for CommandGateway, QueryGateway, etc. But I see that DeadlineManager is null and I unable to inject it.

In Axon documentation I read:

The DeadlineManager can be injected as a resource. It has three flavors: SimpleDeadlineManager , JobRunrDeadlineManager and QuartzDeadlineManager

also

Spring Boot users will need to define a DeadlineManager bean using one of the available implementations.

Could you please provide example of code DeadlineManager bean definition by SimpleDeadlineManager at least. I do not need fine tuning now. Just simplest and default configuration for proof of concepts.

I found some examples in internet but it based on deprecated AxonConfiguration.

Thanks in advance,
Andrew

We need to update the documentation, as for Jobrunr we will autoconfigure, but only if there is a JobRunr JobScheduler.

So you can go with JobRunr, and add the starter with these instructions.

You can also use the Simple one, by adding:

    @Bean
    public DeadlineManager deadlineManager(){
        return SimpleDeadlineManager.builder().build();
    }

Somewhere in an @Configuration annotated class.
From 4.8.0 we will likely also support db-scheduler.
Please let us know if you have any follow-up questions.

Gerard, thanks for assistance,
But with this Simple Bean code in @Configuration annotated class I got exception:

Error creating bean with name ‘deadlineManager’ defined in class path resource [com/example/idp/domain/configuration/DomainConfiguration.class]:
Failed to instantiate [org.axonframework.deadline.DeadlineManager]: Factory method ‘deadlineManager’ threw exception with message: The ScopeAwareProvider is a hard requirement and should be provided

Thanks, it was a bit too minimal, try this instead please:

    @Bean
    public DeadlineManager deadlineManager(
        org.axonframework.config.Configuration configuration,
        TransactionManager transactionManager,
        SpanFactory spanFactory
    ){
        ScopeAwareProvider scopeAwareProvider = new ConfigurationScopeAwareProvider(configuration);
        return SimpleDeadlineManager.builder()
                .scopeAwareProvider(scopeAwareProvider)
                .transactionManager(transactionManager)
                .spanFactory(spanFactory).build();
    }

Please note that by using the SimpleDeadlineMenager it will not persist the scheduled deadlines.

1 Like

Hi,

I’am curious how to continue using persistent schedules with jobRunner. Before bumping axon-bom from 4.7.4 to 4.8.0 this configuration in kotlin did the job, but now it results in a java.lang.ClassNotFoundException: org.jobrunr.scheduling.JobBuilder

 @Profile("postgres")
    @Bean
    fun jobRunrStorageProvider(dataSource: DataSource): StorageProvider {
        // Hard to create compatible schema for h2 and postgres in liquibase, so let jobrunr do it
        return DefaultSqlStorageProvider(dataSource, AnsiDialect(), DatabaseOptions.CREATE)
    }

    @Bean
    fun jobScheduler(storageProvider: StorageProvider): JobScheduler {
        return JobRunr.configure()
            .useStorageProvider(storageProvider)
            .useBackgroundJobServer().initialize().jobScheduler
    }

    @Bean
    fun deadlineManager(
        @Qualifier("eventSerializer") serializer: Serializer,
        jobScheduler: JobScheduler,
        transactionManager: TransactionManager,
        axonConfiguration: SpringAxonConfiguration,
        spanfactory: SpanFactory,
    ): DeadlineManager {
        return JobRunrDeadlineManager.builder()
            .scopeAwareProvider(ConfigurationScopeAwareProvider(axonConfiguration.`object`)).jobScheduler(jobScheduler)
            .serializer(serializer).transactionManager(transactionManager).spanFactory(spanfactory).build()
    }

Hi Frank,

The JobBuilder was introduced with JobRunner 6.0. Could it be you are using an older version of JobRunner. I don’t think I mentioned it anywhere. Aligning versions can be a bit tricky in some cases.

Hi Gerard,

Thanks for your reply, but it is confusing to me. I’am using axon-bom 4.7.4, with spring-boot-starter-parent 3.1.0 and jobrunr-spring-boot-starter version 5.3.3 and this works fine.

But only changing the axon-bom version to 4.8.0 causes the JobRunner class not found.So which combination should I use?

Thanks in advance,

Frank

From 4.8.0, you need jobrunner to be at minimal 6. Of course, we could force this, adding it to the bom. But to prevent having the same artifacts in multiple bom’s, the axon bom contains almost only axon dependencies. Most likely it’s also possible to use Jobrunner 6 with 4.7.4, but I haven’t tested it. We changed the implementation a bit, using the JobBuilder, hence why 4.8.0 of axon together with 5 of JobRunner is breaking.

Thx Gerard,

It’s clear to me, besides updating the jobrunr version I also had to change the artifactId from jobrunr-spring-boot-starter to jobrunr-spring-boot-3-starter.

Thanks for your time.

1 Like