【发布时间】:2020-05-06 08:42:56
【问题描述】:
我有一个实体列表List<Entity> entitiesList。我需要发布和存储每个实体的事件列表。
我有一个 Entity 聚合,所有必要的处理程序,CreateEntityCommand 和 EntityCreatedEvent。
目前我在做什么:
1. 在循环中创建命令,并通过命令网关为实体列表中的每个实体发送这些命令。
for (Entity entity : entitiesList) {
CreateEntityCommand createEntityCommand = new CreateEntityCommand();
… here I set command’s fields …
commandGateway.send(createEntityCommand);
}
- 在我的聚合中
@CommandHandler
public EntityAggregate(CreateEntityCommand createAlertCommand) {
EntityCreatedEvent entityCreatedEvent = new EntityCreatedEvent();
…. here I set event’s fields
AggregateLifecycle.apply(entityCreatedEvent);
}
结果,事件被创建并一一发布并保存到循环内的 DomainEventEntry 表中。 如果我有 10000 个实体——这个过程需要很多时间…… 我的问题是——如何改进创建、发布和保存实体列表的过程?
我使用这个版本的轴突:
<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>
带有注解@SpringBootApplication 的SpringBoot 配置。 我没有在 Axon 周围配置任何特定的东西。
【问题讨论】:
-
所以,在真正回答您的问题之前,我需要您提供一些额外的信息: 1. 您使用的是哪个版本的 Axon? 2.你使用的是Spring Boot自动配置吗? 3. 您是否针对 Axon 配置了任何特定内容?我建议用这些问题的答案更新你的问题,这样任何人都可以立即看到它们。
-
我使用 axon-spring-boot-starter 4.3。带有注解 @SpringBootApplication 的 SpringBoot 配置。我没有在 Axon 周围配置任何特定的东西。
标签: axon