Axon 3 eventstore vs eventbus

Morning All,

We are using a JpaEventStorageEngine with various EventProcessors in a spring context.
Initally Axon complained about a missing eventBus bean so we added a SimpleEventBus to our configuration.
On startup Axon now finds 2 eventBus beans and states it will use the eventStore bean, not the eventBus bean.
So Axon requires an eventBus on startup but won't use it. In debug mode I can see all our EventProcessors are subscribed to both the eventStore as well as the eventBus.
What is that SimpleEventBus used for?

Regards,
Benoît

Hi Benoit,

it shouldn’t be necessary to configure bith the EventStore abd the EventBus. In fact, if you use Spring AutoConfiguration, you don’t need either. The EventStorageEngine (which is also automatic when using JPA) is enough.
Maybe, just a guess, some component has a named dependency on ‘eventbus’. In that case, putting an (additional) alias on the EventStore will suffice.

Cheers,

Allard

PS. Are you using @EnableAxon? It is recommended not to, in favour of ‘proper’ autoconfiguration.

Hi Allard,

Now that you mention, I think we autowire an EventBus type param to build the EventProcessor instances.
I would expect spring to resolve this to the EventStore bean. Make me wonder how Autowire is implemented though.

We are not using @EnableAxon btw.

Thanks,
Benoît

Hi Allard,

I should have checked the code before replying, I was wrong all the way: we are using @EnableAxon and our spring context does not have any reference to class EventBus or any bean named ‘eventBus’.

I’ll see what happens without @EnableAxon.

Cheers,
Benoît

Hi Allard,

Without @EnableAxon annotation the application boots properly but it cannot resolve any command handler in the aggregate. I tried adding and AggregateAnnotationCommandHandler bean (with an explicit call to AggregateAnnotationCommandHandler.subcribe(commandBus) ? ) but then the command handler outside the aggregate cannot be resolved? For the latter we already have an AnnotationCommandHandlerBeanPostProcessor.

Can I not mix both sort of command handler for a single aggregate?

Regards,
Benoît

Hi Benoit,

you should be able to do that. Did you annotate your command handler “bean” with @Component? And did you include the axon-spring-boot-autoconfigure dependency (or one of the axon-spring-boot-starter modules)?

Cheers,

Allard

Hi Allard,

For sure the command handler bean is annotated with @Component.
Should I still have axon-spring-boot-autoconfigure on my classpath when I’m not using Spring Boot at all?

Regards,
Benoît

Hi Benoit,

yes, the Axon-Spring autoconfiguration support requires Spring Boot Autoconfiguration. Even though strictly speaking, the @EnableAxon works without Autoconfiguration, it is very fragile and we cannot guarantee it works as expected in all conditions. The reason is that with Spring Autoconfiguration, there are better guarantees on the ordering in which beans are processed. A guarantee you don’t have with just the annotation.

Note that Spring Boot AutoConfiguration doesn’t require you to also use the Spring Boot embedded tomcat or fat jar approach.

Cheers,

Allard