MongoEventStorageEngine configuration

Hi All,
Firstly I used axon4.5 and with default configuration created aggregate,commands and events and exposed services as rest apis and invoke some rest calls to store events in default way.Then I changed the storage engine to mongodb engine.

@Bean
public EventStorageEngine storageEngine(EventUpcasterChain upcasterChain) {
	    return MongoEventStorageEngine.builder()
	        .eventSerializer(eventSerializer())
	        .snapshotSerializer(eventSerializer())
	        .mongoTemplate(axonMongoTemplate())
	        .upcasterChain(upcasterChain)
	        .storageStrategy(new DocumentPerEventStorageStrategy())
	        .build();
}

When I start the springboot app axon is trying to deserialize object events in the previous eventstorage and throw below error.

Caused by: com.fasterxml.jackson.core.JsonParseException: Unexpected character ('<' (code 60)): expected a valid value (JSON String, Number, Array, Object or token 'null', 'true' or 'false')
 at [Source: (byte[])"<com.axon.axonapp.events.BookCreatedEvent><libraryId>1</libraryId><isbn>123460</isbn><title>My Title</title></com.axon.axonapp.events.BookCreatedEvent>"; line: 1, column: 2]
	at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:1851) ~[jackson-core-2.11.4.jar:2.11.4]
	at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:707) ~[jackson-core-2.11.4.jar:2.11.4]
	at com.fasterxml.jackson.core.base.ParserMinimalBase._reportUnexpectedChar(ParserMinimalBase.java:632) ~[jackson-core-2.11.4.jar:2.11.4]
	at com.fasterxml.jackson.core.json.UTF8StreamJsonParser._handleUnexpectedValue(UTF8StreamJsonParser.java:2686) ~[jackson-core-2.11.4.jar:2.11.4]
	at com.fasterxml.jackson.core.json.UTF8StreamJsonParser._nextTokenNotInObject(UTF8StreamJsonParser.java:865) ~[jackson-core-2.11.4.jar:2.11.4]
	at com.fasterxml.jackson.core.json.UTF8StreamJsonParser.nextToken(UTF8StreamJsonParser.java:757) ~[jackson-core-2.11.4.jar:2.11.4]
	at com.fasterxml.jackson.databind.ObjectReader._initForReading(ObjectReader.java:357) ~[jackson-databind-2.11.4.jar:2.11.4]
	at com.fasterxml.jackson.databind.ObjectReader._bindAndClose(ObjectReader.java:2064) ~[jackson-databind-2.11.4.jar:2.11.4]
	at com.fasterxml.jackson.databind.ObjectReader.readValue(ObjectReader.java:1555) ~[jackson-databind-2.11.4.jar:2.11.4]
	at org.axonframework.serialization.json.JacksonSerializer.deserialize(JacksonSerializer.java:202) ~[axon-messaging-4.5.jar:4.5]
	... 25 common frames omitted

How to ensure previous events are not picked by mongodb event sorage engine?

Also I cant see event stored in mongodb for new requests.I can only see emptytracking tokens collection in mongodb?Why events are not storing in mongodb?

Thanks
Isuru

After I add below @Bean error went away

@Bean
public EmbeddedEventStore eventStore(EventStorageEngine storageEngine, AxonConfiguration configuration) {
    return EmbeddedEventStore.builder()
            .storageEngine(storageEngine)
           // .messageMonitor(configuration.messageMonitor(EventStore.class, "eventStore"))
            .build();
}

HOwever still I cant see any events stored in mongodb.I can only see emptytracking tokens collection in mongodb?Why events are not storing in mongodb?

Hi Isuru,

Did you have a look at @Ivan_Dugalic repo where he is showing how to configure axon to mongo? GitHub - idugalic/axon-mongo-demo: Axon demo application - MongoDB as an event store

-Ben

1 Like

Hi Ben,
After analysing further I found that axon server is the recommended event storage and I decided not to explore further on mongodb event storage since it has very low applicability.

Thanks for your pointers.

Regards,
ISuru