Hello everyone,
My goal is to provide the user with a REST interface where he can send an Upload, that will trigger events across several different aggregates in the backend, and then block the request until I know the upload processing is finished and a projection is updated.
So, in my controller I send the command and block on a confirmation SubscriptionQuery:
private Upload handleUpload(Upload upload) { SubscriptionQueryResult<Boolean, Boolean> blockingQuery = queryGateway.subscriptionQuery(new IsUploadFinished(upload.getId()), Boolean.class, Boolean.class); commandGateway.sendAndWait(...); blockingQuery.updates().blockFirst(); return productUpload; }
And then I have a Saga that listens to an event for the Upload, dispatches commands to different aggregates and collects the resulting events.
Once the Saga knows the processing is finished it sends an Event to signal the processing of the Upload is finished:
@SagaEventHandler(associationProperty = "id")
public void handle(...) {
[...]
if (isSagaFinished()) {
commandGateway.send(ConfirmUpload());
}
}
And then in my projection I emit an update to the "IsUploadFinished" query once the projection has processed the event: