Hello guys I use axon 4.7 and spring 3.0.6 need some one can help how I can use mongo as created or updated commands in mucroservices need samples code config becuase I try to do but failed
@Configuration
public class AxonConfig {
@Value("${spring.data.mongodb.host:127.0.0.1}")
private String mongoHost;
@Value("${spring.data.mongodb.port:27017}")
private int mongoPort;
@Value("${spring.data.mongodb.database:bank}")
private String mongoDatabase;
@Bean
public MongoClient mongo() {
var mongoFactory = new MongoFactory();
mongoFactory.setMongoAddresses(Collections.singletonList(new ServerAddress(mongoHost, mongoPort)));
return mongoFactory.createMongo();
}
@Bean
public MongoTemplate axonMongoTemplate() {
return DefaultMongoTemplate.builder()
.mongoDatabase(mongo(), mongoDatabase)
.build();
}
@Bean
public TokenStore tokenStore(Serializer serializer) {
return MongoTokenStore.builder()
.mongoTemplate(axonMongoTemplate())
.serializer(serializer)
.build();
}
@Bean
public EventStorageEngine storageEngine(MongoClient client) {
return MongoEventStorageEngine.builder()
.mongoTemplate(DefaultMongoTemplate.builder()
.mongoDatabase(client)
.build())
.build();
}
@Bean
public EmbeddedEventStore eventStore(EventStorageEngine storageEngine, AxonConfiguration configuration) {
return EmbeddedEventStore.builder()
.storageEngine(storageEngine)
.messageMonitor(configuration.messageMonitor(EventStore.class, "eventStore"))
.build();
}
Can you explain what didn’t work? I’m not sure if you use Spring Boot with the MongDB starter? If so, you kind of don’t have to configure anything, just setting mongo.event-store.enabled to true in your case.
Let me use it when I found some misunderstanding I will tell you.
Other question I try to run 3 microservices After running and try to test them but return “OUT_OF_RANGE: [AXONIQ-2000] Invalid sequence number 0 for aggregate 1, expected” one of them has 13 records fields, second 10 records fields. can you help what I do
Hello Guys, is possible to use mongoDB as Event store(Write database) and SQL server (Read database) and axon.axonserver.enable=false??? in spring boot 3.0.6 and axon 4.7.0
Not sure what you want to establish. Can you expand for which parts you want to use a relational database and for which parts a document database. Combining both with Spring Boot can become a bit of a challenge, since if you just have one of them, most is auto configured. When you use both you need more manual configuration.
I want to use both once time Mongo as event store(write database) and sql as read database for Bank account. for 3 microservices no distributor commandBus use
I would advise against that. It’s much better to use SQL for the event store and you can use MongoDB for the projection. Why do you want to use MongoDB for the event store?
There are properties to disable auto config for the token store, which you don’t need in your case. However if you already use JPA (SQL) the auto configuration from the mongo extension won’t work. Since those components are already created based on JPA variants. One way out of this is to configure the event store yourself. The easiest way is to copy past from the GitHub repository, and remove the conditionals.