如何使用 Axon 3.3.3 版本从 RDBS PostgreSQL 加载事件?

How to load events from RDBS PostgreSQL using Axon 3.3.3 version?

轴突版本:3.3.3

我想从 PostgreSQL 数据库加载(读取)事件,我找不到正确的配置,能否请您分享配置详细信息以从 domain_event_entry table 读取事件.

以下是在数据库中存储事件的当前配置

@SpringBootApplication

public class UserServiceApplication {

public static void main(String[] args) throws Exception {
    SpringApplication.run(UserServiceApplication.class, args);
}

@Bean(name = "userAggregateFactory")
public AggregateFactory<UserAggregate> userAggregateFactory() {

    SpringPrototypeAggregateFactory<UserAggregate> aggregateFactory = new SpringPrototypeAggregateFactory<>();
    aggregateFactory.setPrototypeBeanName("userAggregate");

    return aggregateFactory;

}}

由于您处于 Spring 引导环境中,我假设您正在使用 axon-spring-boot-starter 依赖项来连接所有内容。 因此,这意味着 Axon 将为您创建所有必需的 bean,例如 CommandBus、聚合 Repository 以及 EventStore.

在大多数 Axon 应用程序中,您不需要自己从 EventStore 检索事件。您可以简单地拥有一个带有 @EventHandler 注释方法的 class。如果此 class 是 Spring 环境中的 Bean,Axon 将自动将其注册为能够处理事件。因此,这将省去您自己直接查询事件的需要。

但是,如果您需要读取一组事件,我建议连接 EventStore,因为它包含检索事件流的方法。

最后,我强烈建议增加您正在使用的 Axon Framework 版本。 Axon Framework 4.0 已经发布将近一年多了。 Axon 3 不再 积极开发。