Hello,
I’m attempting to create a proof-of-concept saga that creates two different aggregate types in response to an event. Unfortunately whenever I run this with both commands being sent, the CreateAccountAttemptCommand fails with the following message:
Command ‘com.x.y.command.CreateAccountAttemptCommand’ resulted in org.axonframework.commandhandling.CommandExecutionException(No such field com.x.y.command.CreateAccountAttemptCommand.attemptId
If I only send one or the other they go through successfully, and this issue only occurs with the Account command, not Customer. The CreateAccountAttemptCommand has no associated aggregate, as it is handled by an external CommandHandler which then emits AccountCreationSuccessful. In theory, in the saga event handler we’d then actually create the aggregate, but for clarity I’ve taken that out. Here are a few snippets to hopefully inform the issue.
@Data
public class CreateAccountAttemptCommand {
@RoutingKey
private final String attemptId;
private final String userId;
private final String name;
private final String lastName;
public CreateAccountAttemptCommand(String userId, String attemptId) {
this.userId = userId;
this.name = "Test";
this.lastName = "User";
this.attemptId = attemptId;
}
}
@Data
@AllArgsConstructor
public class CreateCustomerCommand {
@TargetAggregateIdentifier
private String customerId;
private String firstName;
private String lastName;
}
@Saga
public class CreateAccountSaga {
private boolean accountCreated = false;
private boolean customerCreated = false;
@Autowired
transient CommandGateway commandGateway;
@StartSaga
@SagaEventHandler(associationProperty = "userId")
public void handle(AccountRequestedEvent event) {
setup();
String customerId = UUID.randomUUID().toString();
String attemptId = UUID.randomUUID().toString();
SagaLifecycle.associateWith("customerId", customerId);
SagaLifecycle.associateWith("attemptId", attemptId);
commandGateway.send(new CreateAccountAttemptCommand(event.getUserId(), attemptId));
commandGateway.send(new CreateCustomerCommand(customerId, "Tom", "A"));
}
@SagaEventHandler(associationProperty = "attemptId")
public void handle(AccountCreationAttemptSuccessfulEvent event) {
accountCreated = true;
if (customerCreated) { SagaLifecycle.end(); }
}
@SagaEventHandler(associationProperty = "customerId")
public void handle(CustomerCreatedEvent event) {
customerCreated = true;
if (accountCreated) { SagaLifecycle.end(); }
}
public void setup() {
commandGateway.registerDispatchInterceptor(new CommandDispatchInterceptor());
}
}