Application in Axon 4 refused to start when I tried to create MongoEventStorageEngine and EmbeddeIdEventStore beans

I created a simple axon 4 project today and I would like to store my event in mongodb.
here is my config.

Pom.xml

`

org.springframework.boot

spring-boot-starter-test

test

io.projectreactor

reactor-test

test

org.axonframework

axon-spring-boot-starter

4.0.3

org.axonframework

axon-mongo

4.0-M2

`

Configuration class

`

public class EventStorageConfiguration {

@Bean

EventStore eventStore(EventStorageEngine engine) {

return EmbeddedEventStore.builder().storageEngine(engine).build();

}

@Bean

public EventStorageEngine engineStorage(MongoTemplate template) {

return new MongoEventStorageEngine(template);

}

@Bean

public MongoTemplate template(MongoClient client) {

return new DefaultMongoTemplate(client, “events-db-4”);

}

@Bean

public TokenStore tokenStore(Serializer serializer, MongoTemplate template) {

return new MongoTokenStore(template, serializer);

}

@Bean

public Snapshotter snapshotter(ParameterResolverFactory parameterResolverFactory,

EventStore eventStore, TransactionManager transactionManager) {

final Executor executor = Executors.newSingleThreadExecutor();

return SpringAggregateSnapshotter.builder()
.eventStore(eventStore)
.parameterResolverFactory(parameterResolverFactory)
.executor(executor)

.transactionManager(transactionManager)
.build();

}

@Bean

public SnapshotTriggerDefinition snapshotTriggerDefinition(Snapshotter snapshotter) throws Exception {

return new EventCountSnapshotTriggerDefinition(snapshotter, 3);

}

}

`

In axon 3.4.2 the application start without problem but il axon 4 I get this.

`

Hi Martin,

When using the axon-spring-boot-starter dependency with version 4 and up, it will auto wire the AxonServerClient for you.
This takes the place of any other non-Axon Server centric command, event and query buses, similarly for your MongoEventStorageEngine.
To omit the AxonServerConnector, you can exclude it’s dependency from the ‘axon-spring-boot-starter’ like so:

org.axonframework axon-server-connector

Or, you could opt to try out the free-to-use AxonServer solution for storing your events and residing as the dedicated routing solution between your services.
Pretty sure it will safe you a lot of configuration to use Axon Server instead of the open source solution to get event storage and message routing working.

Nonetheless, I hope this helps you out Martin!

Cheers,
Steven

Hi Martin,

the reason is that you’ve got a wrong dependency for Mongo. It should be:

org.axonframework.**extensions**

axon-mongo

4.0

Steven’s comment is still valid, using AxonServer is obviously highly recommended.

Cheers,

Allard

Thank you Allard.

I updated the axon-mongo dependency and everything working as I expected.
by the way it seems the dependency is

org.axonframework.**extensions.mongo**

axon-mongo

4.0

instead of

org.axonframework.**extensions**

axon-mongo

4.0

I have a couple of questions.
1- Actually the event storage get configured my events get stored in mongo. My question is where is axon serveur actually get datas? from my mongo store or for it own db?. if axon server still get data from it db is that mean that must choose between using axon-server and continue as in axon 3?
2- The second question is about Rabbit and kafka. Steven mention routing event between services. Do we still need rabbit or kafka to exchange message between the command and the query side event if we have axon-server?

Actually I tried my events get stored in mongodb but no event have been publish in rabbit. is that because axon-server and rabbit does work together?

Cheers.

Martin.

Hi Martin,

Thanks for pointing out the discrepancy between the Mongo group id, valuable info for everybody here.
Now to your follow up question:

  1. Axon Server, as it stands now, is the database for your events. Hence, you cannot configure Axon Server to use a storage mechanism yourself. This is intentional, as we see a lot of value in tackling the specific use case of an Event Store. Relational Databases, as well as Mongo, aren’t specialized to be an Event Store, hence why those aren’t set to be one for Axon Server. Additionally, Axon Server should be correctly usable Axon 3 and Axon 4. If this is not the case, please let us know.

  2. Axon Server is a dedicated Message Routing solution, for all your Commands, Events and Queries. You can still use Rabbit or Kafka along side that to get your events from one place to another, if you want. If you are however using Axon Server, then I’d very likely use it all the way, as much as possible that is. I could imagine there are third party applications in your system for which you cannot control how they get their events, other than the mandatory usage of (in that third party service it’s standards that is) Rabbit/Kafka.

Hope this helps to clarify things!

Cheers,
Steven

Thanks you for the clarification Steve.

Cheers.