使用 springboot 2.3.3 和 axon 4.4.2 实现 axon 快照 [英] Implementing axon snapshot with springboot 2.3.3 and axon 4.4.2

查看:37
本文介绍了使用 springboot 2.3.3 和 axon 4.4.2 实现 axon 快照的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以推荐任何使用 springBoot 2.3.3 在 AXON 4.4.2 中实现快照的教程/示例项目.

can anyone suggest any tutorial/sample project for Implementing Snapshot in AXON 4.4.2 with springBoot 2.3.3.

我浏览了文档(https:///docs.axoniq.io/reference-guide/axon-framework/tuning/event-snapshots#snapshotting)并执行以下操作:AxonConfig.class

i went through the documentation(https://docs.axoniq.io/reference-guide/axon-framework/tuning/event-snapshots#snapshotting) and did below: The AxonConfig.class

@Configuration
public class AxonConfig {

    @Bean
    public SnapshotTriggerDefinition app1SnapshotTrigger(Snapshotter snapshotter) {
        return new EventCountSnapshotTriggerDefinition(snapshotter, 10);
    }
}

综合

@Aggregate(snapshotTriggerDefinition = "app1SnapshotTrigger")
public class MyAggregate {

    @AggregateIdentifier
    private String id;
    private String name;
    @AggregateMember
    private List<Address> addresses = new ArrayList<>();

    private  MyAggregate  () {

    }

    @CommandHandler
    private  MyAggregate  (CreateNameCommand createNameCommand) {
        -----
    }

    @EventSourcingHandler
    private void on(NameCreatedEvent nameCreatedEvent) {
       ----
    } 

我是不是遗漏了什么.它会在阈值 10 处创建快照吗?谢谢.

Am i missing something. Will it create a snapshot at the threshold value 10. Thanks.

推荐答案

很遗憾,我们没有准备好在这种情况下展示的示例演示.

unfortunately we have no sample demo ready to show in this case.

从您的代码片段看来,一切就绪.也许还有其他一些配置正在接管您的注释.

From your code snippet looks that all is in place. Maybe there is some other configuration that is taking over your annotation.

为了尝试,我将您的配置应用到我们的 https://github.com/AxonIQ/giftcard-demo/

To give a try, I applied your configuration to our https://github.com/AxonIQ/giftcard-demo/

可以引导的第一个注意事项如下

First note that can guide is the following

  • if you declared a Repository as we did in https://github.com/AxonIQ/giftcard-demo/blob/master/src/main/java/io/axoniq/demo/giftcard/command/GcCommandConfiguration.java#L17 this configuration will take over Annotation placed into your aggregate. If you prefer annotation, you can remove this Bean definition.

这里是一段代码,而是将其配置为 Bean

Here the piece of code, instead, to have this configured as a Bean

@Bean
public Repository<GiftCard> giftCardRepository(EventStore eventStore, SnapshotTriggerDefinition giftCardSnapshotTrigger) {
    return EventSourcingRepository.builder(GiftCard.class)
            .snapshotTriggerDefinition(giftCardSnapshotTrigger)
            .eventStore(eventStore)
            .build();
}

@Bean
public SpringAggregateSnapshotterFactoryBean snapshotter() {
    var springAggregateSnapshotterFactoryBean = new SpringAggregateSnapshotterFactoryBean();
    //Setting async executors
    springAggregateSnapshotterFactoryBean.setExecutor(Executors.newSingleThreadExecutor());
    return springAggregateSnapshotterFactoryBean;
}

@Bean("giftCardSnapshotTrigger")
public SnapshotTriggerDefinition giftCardSnapshotTriggerDefinition(Snapshotter snapshotter) {
    return new EventCountSnapshotTriggerDefinition(snapshotter, 10);
}

您可以通过查看客户端日志来检查您的快照是否正常工作:在同一 agggregateId 上发生 10 个事件后,您应该会找到此信息日志条目o.a.a.c.event.axon.AxonServerEventStore : 快照创建

You can check that your snapshot is working fine looking at client log : after 10 events on the same agggregateId, you should find this info log entry o.a.a.c.event.axon.AxonServerEventStore : Snapshot created

要检查您是否可以使用 REST api 从聚合中检索事件curl -X GET "http://localhost:8024/v1/events?aggregateId=A01"这将生成一个包含从最新快照开始的事件的流:您将列出九个事件,直到将处理第十个事件.之后,端点将列出快照中的事件.

To check you can use the REST api to retrieve the events from an aggregate curl -X GET "http://localhost:8024/v1/events?aggregateId=A01" This will produce a stream containing events starting from the latest Snapshot: you will have nine events listed until the tenth event will be processed. After that, the endpoint will list events from the snapshot.

您还可以检查 /actuator/health 端点:如果启用了 showDetails,它将显示最后一个快照令牌(在 EE 中默认启用,默认不启用)在东南).

You can also check /actuator/health endpoint: it will shows the last snapshot token if the showDetails is enabled (enabled by default in EE, not enabled by default in SE).

科拉多.

这篇关于使用 springboot 2.3.3 和 axon 4.4.2 实现 axon 快照的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆