轴突未来发展 [英] Axon & CompletableFuture

查看:103
本文介绍了轴突未来发展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试在Axon上使用CompletableFuture时遇到了问题。
例如:

I've faced with problems when i try to use CompletableFuture with Axon. For example:

CompletableFuture future = CompletableFuture.supplyAsync(() -> {

            log.info("Start processing target: {}", target.toString());
            return new Event();

        }, threadPool);

future.thenAcceptAsync(event -> {
            log.info("Send Event");
            AggregateLifecycle.apply(event);
}, currentExecutor);

那么thenAcceptAsync-AggregateLifecycle.apply(event)具有意外行为。我的某些@EventSourcingHandler处理程序开始两次处理事件。有人知道如何解决吗?

in thenAcceptAsync - AggregateLifecycle.apply(event) has unexpected behavior. Some of my @EventSourcingHandler handlers start handling event twice. Does anybody know how to fix it?

我一直在阅读文档,而我得到的一切都是:

I have been reading docs and everything that i got is:


在大多数情况下,DefaultUnitOfWork将为您提供所需的
功能。它期望处理在
单线程内进行。

In most cases, the DefaultUnitOfWork will provide you with the functionality you need. It expects processing to happen within a single thread.

因此,似乎我应该以某种方式使用CurrentUnitOfWork.get / set方法,但仍然无法理解Axon API。

so, it seems i should use somehow CurrentUnitOfWork.get/set methods but still can't understand Axon API.

推荐答案

您不应 apply()事件异步。 apply()方法将调用聚合的内部@EventSourcingHandler方法,并在工作单元完成(成功)后安排发布事件的时间。
Axon与工作单元一起工作(协调单个消息处理程序调用的活动)的方式,必须在管理该工作单元的线程中调用apply()方法。

You should not apply() events asynchronously. The apply() method will call the aggregate's internal @EventSourcingHandler methods and schedule the event for publication when the unit of work completes (successfully). The way Axon works with the Unit of Work (which coordinates activity of a single message handler invocation), the apply() method must be invoked in the thread that manages that Unit of Work.

如果要异步发布事件,请使用使用异步传输的事件总线,并使用跟踪处理器。

If you want asynchronous publication of Events, use an Event Bus that uses an Async Transport, and use Tracking Processors.

这篇关于轴突未来发展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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