我有一个正在使用 Axon 开发的项目,但我的 Saga 没有正确执行。
My Saga 包含与此类似的行:
@StartSaga
@SagaEventHandler(associationProperty = "uuid")
public void handle(FirstEvent event) {
System.out.println("Processing FirstEvent for uuid=" + event.getUuid());
associateWith("uuid", event.getUuid().toString());
initialiseWorkflow(event.getUuid(), Status.CREATED) ;
}
@SagaEventHandler(associationProperty = "uuid")
public void handle(SecondEvent event) {
System.out.println("Processing SecondEvent for uuid=" + event.getUuid());
this.processStep(STEP_2,event.getUuid());
}
第一个事件正在触发一个开始 saga,并且还触发了 initialiseWorkflow 任务(它正确地创建了一组额外的步骤。)但是,当 SecondEvent 到达时(与 FirstEvent 具有相同的 UUID 关联属性值),saga 不会拿起那第二个事件。
我已经尝试专门包括以下行来增强关联,但这也不起作用:
associateWith("uuid", event.getUuid().toString());
具有讽刺意味的是,我有一个测试用例,使用正常工作的轴突测试框架,这类似于:
@Test
public void testSecondEvent() {
fixture.givenAggregate(uuid).published(new FirstEvent(uuid))
.whenAggregate(uuid).publishes(new SecondEvent(uuid))
.expectDispatchedCommandsMatching(exactSequenceOf(
new CompleteTaskCommandMatcher("SecondEvent")));
}
问题出现在我的端到端测试中,我将命令直接放入 CommandGateway,并直接在存储库中检查结果。
我已经仔细检查了 AnnotatedSagaManager 是否正在使用,并且确实如此。
有没有人对可能出现的问题有任何想法,或者我误解了 Sagas 应该如何工作?
编辑:还有一些更新:
1) 我注意到在直接关联 UUID 时需要使用 toString(),所以我尝试将值变成事件的字符串 - 没有进展。
2)我尝试打印出关联的值,发现不需要直接关联行(在start saga过程中关联了uuid)
3)我尝试将@StartSaga 放在 secondEvent 上,这达到了“Processing SecondEvent ...”的代码,但在一个新的传奇中。
更多了解,但还没有解决方案!