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

590 views
Skip to first unread message

Niel de Wet

unread,
Aug 30, 2017, 6:45:50 AM8/30/17
to Axon Framework Users
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?

Allard Buijze

unread,
Aug 30, 2017, 7:07:21 AM8/30/17
to Axon Framework Users
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

Op wo 30 aug. 2017 om 12:45 schreef Niel de Wet <nie...@gmail.com>:
--
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.
--

Niel de Wet

unread,
Aug 30, 2017, 8:06:07 AM8/30/17
to Axon Framework Users
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
Reply all
Reply to author
Forward
0 new messages