I have a list of entities List<Entity> entitiesList
. I need to publish and store the list of events for each of entity.
I have an aggregate for Entity , all necessary handlers, CreateEntityCommand and EntityCreatedEvent.
Currently what I do:
1. Create commands in the loop and send these commands via command gateway for each entity from entitiesList.
for (Entity entity : entitiesList) {
CreateEntityCommand createEntityCommand = new CreateEntityCommand();
… here I set command’s fields …
commandGateway.send(createEntityCommand);
}
- Inside the aggregate I have
@CommandHandler
public EntityAggregate(CreateEntityCommand createAlertCommand) {
EntityCreatedEvent entityCreatedEvent = new EntityCreatedEvent();
…. here I set event’s fields
AggregateLifecycle.apply(entityCreatedEvent);
}
As the result, the events are created published and saved into the DomainEventEntry table inside the loop one by one. If I have 10000 of entities – this process takes a lot of time … My question is – how can I improve this process of creating, publishing and saving a list of entities ?
I use this version of axon:
<dependency>
<groupId>org.axonframework</groupId>
<artifactId>axon-spring-boot-starter</artifactId>
<version>4.3</version>
<exclusions>
<exclusion>
<groupId>org.axonframework</groupId>
<artifactId>axon-server-connector</artifactId>
</exclusion>
</exclusions>
</dependency>
SpringBoot configuration with annotation @SpringBootApplication. I haven't configured anything specific around Axon.