Axon 3, using axon-spring-boot-autoconfigure : What is the right way of specifying an EventBus?

I’m using axon-spring-boot-autoconfigure, and I want to register an EventLoggingInterceptor. To do that I’d like to define my own EventBus, but I can’t work out what’s the right way of doing it.

AxonAutoConfiguration contains the following. Note that I configured my own EventStorageEngine.

`
@Qualifier(“eventStore”)
@Bean(name = “eventBus”)
@ConditionalOnMissingBean(EventBus.class)
@ConditionalOnBean(EventStorageEngine.class)
public EmbeddedEventStore eventStore(EventStorageEngine storageEngine, AxonConfiguration configuration) {
return new EmbeddedEventStore(storageEngine, configuration.messageMonitor(EventStore.class, “eventStore”));
}

@Bean
@ConditionalOnMissingBean({EventStorageEngine.class, EventBus.class})
public SimpleEventBus eventBus(AxonConfiguration configuration) {
return new SimpleEventBus(Integer.MAX_VALUE, configuration.messageMonitor(EventStore.class, “eventStore”));
}
`

I have to define both to get the app to start, but when I try to do:

`
@Bean
public EmbeddedEventStore eventStore(EventStorageEngine storageEngine, AxonConfiguration configuration) {
return new EmbeddedEventStore(storageEngine, configuration.messageMonitor(EventStore.class, “eventStore”));
}

@Bean
public SimpleEventBus eventBus(AxonConfiguration configuration) {
SimpleEventBus eventBus = new SimpleEventBus(Integer.MAX_VALUE, configuration.messageMonitor(EventStore.class, “eventStore”));
eventBus.registerDispatchInterceptor(new EventLoggingInterceptor());
return eventBus;
}
`

I see the following in the log: SpringAxonAutoConfigurer : Multiple beans of type EventBus found in application context: [eventStore, eventBus]. Chose eventStore

What is the right way to do this?

Hi Niel,

in Axon 3, you use either the EventStore or the EventBus, but not both. The EventStore is a specialized version of the EventBus, that is capable of storing Events (instead of just moving them around) .
In your case, you can register your interceptor on the EventStore instead.

Cheers,

Allard

Hi Allard,

Thanks for the quick response. I tried that before, but now I realised one must specify the bean name to be “eventBus”.

This worked:

@Bean(name = "eventBus") public EmbeddedEventStore eventStore(EventStorageEngine storageEngine, AxonConfiguration configuration) { return new EmbeddedEventStore(storageEngine, configuration.messageMonitor(EventStore.class, "eventStore")); }

Thanks
Niel