Hi,
I’m new to axon. I’m building a spring boot application using the framework and I’m having a hard time understanding the responses to the send* methods of CommandGateway. In the simplest case where I execute a command to create a new aggregate I get the aggregate’s id as a response. However, I can’t find any documentation that helps me understand how or why this is the response.
The application I’m building is analogous to an e-commerce shopping cart where you have a Cart with many LineItem instances. As for the CQRS parts, everything is working well. I send commands via the gateway and the aggregates are located and the commands are processed and all the events emitted are delivered to the query side event listeners… The only problem I’m having so far is trying to figure out the the gateway’s send method will return. Like I said above, the simple case is fine. Where this starts to break down for me is when I introduce I command to add multiple LineItems to my Cart (I’m not really working with a Cart, but it’s analogous). The command succeeds and all the views get updated correctly, but the send() method doesn’t return anything.
Below is a snipped of code from my REST controller. At the very bottom you can see where I’m adding a new CompletionStage to the CompletableFuture (with .thenApply()) and printing out the response, which is null:
`
// @formatter:off
@PostMapping(path = “/{id}/items”,
consumes = {MediaType.APPLICATION_JSON_VALUE})
public CompletableFuture<?> describeItems(
@PathVariable String id,
@RequestBody List request) {
// @formatter:on
Assert.hasText(id, “null PackageId String”);
Assert.notEmpty(request, “null Item descriptions”);
String[] lineIdArray = new String[request.size()];
Item[] item = new Item[request.size()];
String[][] serialNumbers = new String[request.size()][];
int i = 0;
for (ItemDescriptionDTO description : request) {
lineIdArray[i] = IdentifierFactory.getInstance().generateIdentifier();
Assert.notEmpty(description.getItemAttributes(), "null/empty item attributes: " + description);
Assert.notEmpty(description.getSerialNumbers(), "null/empty serial numbers: " + description);
Item.Builder itemBuilder = Item.builder();
description.getItemAttributes().forEach((k, v) -> {
itemBuilder.addAttribute(k, v);
});
item[i] = itemBuilder.build();
serialNumbers[i] = description.getSerialNumbers();
i++;
}
RecordItemsCommand.Builder commandBuilder =
RecordItemsCommand.builder(id, CallingAgentContext.agentId(), lineIdArray);
for (i = 0; i < lineIdArray.length; i++) {
commandBuilder.attachItem(lineIdArray[i], item[i], serialNumbers[i]);
}
return commandGateway.send(commandBuilder.build()).thenApply(l->{
System.out.println("----------------------------------------------: " + l);
return l;
});
}
`
What am I missing? How can you determine what the result of the command sent through the gateway will be?
Thanks!