We are using axon version 4.1.1 and axon-mongo version 4.4. We added the configuration for snapshots in our config class. The code of our config class is added below:
@Configuration
public class EventStoreConfig {@Autowired private transient MongoClient mongoClient; @Autowired private ConnectionFactory connectionFactory; @Bean public SimpleCommandBus commandBus(TransactionManager txManager, AxonConfiguration axonConfiguration) { SimpleCommandBus commandBus = SimpleCommandBus.builder() .transactionManager(txManager) .messageMonitor(axonConfiguration.messageMonitor(CommandBus.class, "commandBus")) .build(); commandBus.registerHandlerInterceptor( new CorrelationDataInterceptor<>(axonConfiguration.correlationDataProviders()) ); return commandBus; } @Bean public SimpleQueryBus queryBus(AxonConfiguration axonConfiguration, TransactionManager transactionManager) { return SimpleQueryBus.builder() .messageMonitor(axonConfiguration.messageMonitor(QueryBus.class, "queryBus")) .transactionManager(transactionManager) .errorHandler(axonConfiguration.getComponent( QueryInvocationErrorHandler.class, () -> LoggingQueryInvocationErrorHandler.builder().build() )) .queryUpdateEmitter(axonConfiguration.getComponent(QueryUpdateEmitter.class)) .build(); } @Bean public QueryGateway queryGateway(QueryBus queryBus) { return DefaultQueryGateway.builder().queryBus(queryBus).build(); } @Bean public CommandGateway commandGateway(CommandBus commandBus) { return DefaultCommandGateway.builder().commandBus(commandBus).build(); } @Bean public EmbeddedEventStore eventStore(EventStorageEngine storageEngine, AxonConfiguration configuration) { return EmbeddedEventStore.builder() .storageEngine(storageEngine) .messageMonitor(configuration.messageMonitor(EventStore.class, "eventStore")) .build(); } @Bean public EventStorageEngine storageEngine() { return MongoEventStorageEngine.builder().eventSerializer(JacksonSerializer.builder().build()).mongoTemplate(mongoTemplate()).build(); } @Bean public DefaultMongoTemplate mongoTemplate() { return DefaultMongoTemplate.builder().mongoDatabase(mongoClient).build(); } @Bean public SagaStore<Object> mySagaStore() { return MongoSagaStore.builder().serializer(JacksonSerializer.builder().build()).mongoTemplate(mongoTemplate()).build(); } @Bean public TokenStore tokenStore(Serializer serializer) { return MongoTokenStore.builder() .mongoTemplate(mongoTemplate()) .serializer(serializer) .build(); } @Bean public SnapshotTriggerDefinition mySnapshotTriggerDefinition(Snapshotter snapshotter) { System.out.println("mySnapshotTriggerDefinition called"); return new EventCountSnapshotTriggerDefinition(snapshotter, 2); } @Bean public SpringAggregateSnapshotterFactoryBean springAggregateSnapshotterFactoryBean() { return new SpringAggregateSnapshotterFactoryBean(); }
}
And I have used the snapshot trigger definition with my aggregate as below:
@Aggregate(snapshotTriggerDefinition = “mySnapshotTriggerDefinition”)
public class MyAggregate implements Serializable {
}
But while my application is trying to create a snapshot it is throwing error as shown below:
o.a.eventsourcing.AbstractSnapshotter : An attempt to create and store a snapshot resulted in an exception. Exception summary: An event for aggregate [12345] at sequence [1] could not be persisted.
Can anyone suggest if I’m missing anything?