使用轴突框架我有错误:
应用事件后,聚合标识符必须为非空。确保在处理创建事件时最迟初始化聚合标识符。我使用这个 StorageEngine:
@Bean
public JdbcEventStorageEngine jdbcEventStorageEngine() throws Exception{
return new JdbcEventStorageEngine(dataSource::getConnection, NoTransactionManager.INSTANCE);
}
当第二次收到aggregateId 的消息时,代码失败,就像在这个处理程序中一样:
@CommandHandler
public void handle(CreateProductCommand command) throws Exception {
Aggregate<Product> productAggregate = null;
try {
productAggregate = repository.load(command.getId());
} catch (AggregateNotFoundException exception) {
logger.info("Aggregate with " + command.getId() + " is not found. Creating new one...");
productAggregate = repository.newInstance(() -> new Product(command.getId()));
}
productAggregate.execute(product -> product.createProduct(command.getId()));
}
但如果我使用它,它工作正常:
@Bean
public EventStorageEngine eventStorageEngine() {
return new InMemoryEventStorageEngine();
}
我应该如何为 postgres/mysql 数据库配置 eventStorageEngine?