Hi,
I’m trying to use Mongo db as the repository for events, and through the doc, there’s a MongoEventStorageEngine is provided in the module axon-mongo.
Here’s my configure class
@Configuration
public class AxonConfiguration {
@Value("${mongodb.url}")
private String mongoUrl;
@Value("${mongodb.dbname}")
private String mongoDbName;
@Value("${mongodb.events.collection.name}")
private String eventsCollectionName;
@Value("${mongodb.events.snapshot.collection.name}")
private String snapshotCollectionName;
@Bean
Serializer axonJsonSerializer() {
return new JacksonSerializer();
}
@Bean
public EventStorageEngine eventStore(){
return new MongoEventStorageEngine(
axonJsonSerializer(),null, axonMongoTemplate(), new DocumentPerEventStorageStrategy());
}
@Bean(name = "axonMongoTemplate")
public MongoTemplate axonMongoTemplate() {
MongoFactory mongoFactory = new MongoFactory();
mongoFactory.setMongoAddresses(Arrays.asList(new ServerAddress(mongoUrl)));
MongoClient mongoClient = mongoFactory.createMongo();
MongoTemplate template = new DefaultMongoTemplate(mongoClient, mongoDbName, eventsCollectionName, snapshotCollectionName);
return template;
}
}
It’s actually working but in the console, I found there are two mongo connection, one is to the path I provided, and another is trying to connect localhost.
It seems after introducing this module, Spring will automatically do some initializing work to connect to a mongo db at localhost.
How can I make it avoid connecting localhost? Or can I configure the path to connect for the auto initialization?
Thanks,