我正在使用axon 2.3.1,我有一个聚合类
public class MyAggregate extends AbstractAnnotatedAggregateRoot<MBAggregate> {
@AggregateIdentifier
private MyId Id;
private Circle circle;
EventDispatcher a=new EventDispatcher();
public MyAggregate() {
}
@CommandHandler
public MyAggregate(NewCommand command ) {
apply(new SmallEvent(command.getId(), command.getCircle()));
}
@CommandHandler
public MyAggregate( StoreDestinationsCommand command ) {
apply(new BigEvent(command.getId(), command.getCircle()));
}
//And some event handlers like
@EventHandler
public void onSmallEvent(SmallEvent event)
{
//Some logic here
}
@EventHandler
public void onBigEvent(BigEvent event)
{
//Some logic here
}
Run Code Online (Sandbox Code Playgroud)
现在我希望这些事件处理程序包含在其他类中,并在触发该事件时调用
public class EventContainer {
private static final long serialVersionUID = -6640657879730853388L; …Run Code Online (Sandbox Code Playgroud) 我有一个轴突聚合体。它处理命令并且在应用事件之前必须调用第三方服务来验证一些参数,根据这个验证我是否应用事件。这是好的做法吗?或者我在发送命令之前已经进行了验证?
@Aggregate
public class SomeAggregate {
[...]
@CommandHandler
public void someHandler() {
if(thirdPartyService.invoke) {
apply(...)
}
}
}
Run Code Online (Sandbox Code Playgroud) 我尝试使用axon 配置cqrs和事件源. SeatReseveCreateCommand工作正常.但SeatReserveUpadateCommand无法正常工作.
这是我的SeatReserve 聚合
@Aggregate
public class SeatReserve {
@AggregateIdentifier
private String id;
private String seatid;
private Date date;
@SuppressWarnings("unused")
private SeatReserve() {
}
@CommandHandler
public SeatReserve(SeatReseveCreateCommand seatReseveCreateCommand) {
apply(new SeatReseveCreateEvent(seatReseveCreateCommand.getMyid(), seatReseveCreateCommand.getSeatId(),
seatReseveCreateCommand.getDate()));
}
@CommandHandler
public SeatReserve(SeatReserveUpadateCommand upadateCommand) {
apply(new SeatReserveUpadateEvent(id, upadateCommand.getSeatId()));
}
@EventSourcingHandler
public void on(SeatReseveCreateEvent seatReseveCreateEvent) {
this.id = seatReseveCreateEvent.getId();
this.seatid = seatReseveCreateEvent.getSeatId();
this.date = seatReseveCreateEvent.getDate();
}
@EventSourcingHandler
public void on(SeatReserveChangeEvent upadateEvent) {
seatid = upadateEvent.getSeatId();
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的控制器
@RestController …Run Code Online (Sandbox Code Playgroud) 我们正在将单片机迁移到更分散的分区,我们决定使用AxonFramework.
在Axon中,由于消息是一等公民,因此您可以将它们建模为POJO.
现在我想知道,因为一个服务可以调度一个事件并监听任何其他服务,我们应该如何处理事件分发.
我的第一个冲动是将它们作为JAR文件打包在一个单独的项目中,但这违反了微服务的规则,它们不应该共享实现.
任何建议都是受欢迎的.
我正在尝试使用 CQRS 框架 AXON 添加数据。但是在点击 API 时(用于添加订单)。我收到以下错误:-
Command 'com.cqrs.order.commands.CreateOrderCommand' resulted in org.axonframework.modelling.command.AggregateNotFoundException(The aggregate was not found in the event store)
Run Code Online (Sandbox Code Playgroud)
但我的代码中已经有一个聚合(OrderAggregate.Java)。
完整代码可以在 - https://github.com/iftekharkhan09/OrderManagementSystem找到
添加订单的 API - http://localhost:8080/confirmOrder
请求正文:-
{
"studentName":"Sunny Khan"
}
Run Code Online (Sandbox Code Playgroud)
谁能告诉我我哪里做错了?任何帮助表示赞赏!
我正在研究一个 PoC,我们将 CQRS 与事件溯源结合使用。我们使用 Axon 框架和 Axon 服务器作为工具集。
我们有一些带有一些业务逻辑的微服务(Maven 包)。
应用流程的简单概述:
我们向服务 1 发布一条 xml 消息(使用 REST),这将导致一个事件(使用聚合)。服务 2 处理由服务 1“触发”的事件并启动一个 saga 流。例如,Sage 流程的一部分是发送邮件消息。
我可以用 Axon Test 做一些测试来测试来自服务 1 的聚合或来自服务 2 的传奇。但是有没有一个好的选择来做一个真正的集成测试,我们从向 REST 接口发布消息开始并检查所有操作在聚合和saga中(包括发送邮件等)
也许这种集成测试有点过头了,最好单独测试每个组件。我怀疑测试这种类型的系统需要什么/最好的解决方案。
我正在运行三个不同的服务(A、B 和 C),并且所有服务都连接到 axonserver 4.3.3。除此之外,我还有一个 api 服务,其中包含所有事件,以便可以在所有服务之间共享。当一个事件被触发时(假设由服务 A 触发),其他服务(B 和 C)正在监听该事件,并且它们会做出相应的反应。
现在我也想共享查询,这样当一个服务(比如说A)想要一些属于另一个服务(比如说B)的信息时,它可以直接触发相应的查询,该查询将由服务B侦听并返回信息。
更新
我只是将查询添加到 common-api 服务并从服务 A 中触发它,如下所示:
queryGateway.query( findCourierByIdQuery, responseType):我得到了 queryhandler not found 异常queryGateway.subscriptionQuery( findCourierByIdQuery, initialResponseType, updateResponseType):我什么也没得到queryGateway.scatterGather( findCourierByIdQuery, responseType, timeout, timeUnit):我有一个空流当我从服务 B 本身触发 findCourierByIdQuery 时,查询处理程序被调用并且我得到了正确的响应。
我的观察是,只有当查询从同一组件(本例中为服务 B)触发时,查询处理程序才会被调用,如果我从其他组件(服务 A)触发查询,则不会被调用。
请注意,所有服务都独立运行在不同的主机和端口上,但连接到同一个 axonserver,并且 queryhandler 编写在服务 B 中。
所以基本上实现是这样的:
显然,Axon TrackingEventProcessors默认使用。我想SubscribingEventProcessors改用。该文档说,后者已经是默认的,但他们似乎已经过时。
默认情况下,Axon将使用订阅事件处理器。使用Configuration API的EventHandlingConfiguration类可以更改处理程序的分配方式以及处理器的配置方式。
例如,建议执行如下配置:
@Autowired
public void configure(EventHandlingConfiguration config) {
config.usingTrackingProcessors(); // default all processors to tracking mode.
}
Run Code Online (Sandbox Code Playgroud)
但是,EventHandlingConfigurationv4中没有(v3中有)。
我需要使用SubscribingEventProcessors来在与命令处理相同的事务中执行读取模型更新。如何在4.0中进行配置?
我是 axon 服务器的新手。我在 Spring Boot 中使用 axon 服务器作为远程服务器。不在本地主机中。但是当 Spring Boot 应用程序连接到服务器时,它会失败并显示以下错误。
Connecting to AxonServer node [174.298.31.***:8024] failed: UNAVAILABLE: Network closed for unknown reason
Failed to get connection to AxonServer. Scheduling a reconnect in 2000ms
Run Code Online (Sandbox Code Playgroud)
我的财产文件如下所示,
Connecting to AxonServer node [174.298.31.***:8024] failed: UNAVAILABLE: Network closed for unknown reason
Failed to get connection to AxonServer. Scheduling a reconnect in 2000ms
Run Code Online (Sandbox Code Playgroud)