I am sending a command and expecting a result via CommandGateway.sendAndWait(Object command, long timeout, TimeUnit unit) method :
Greeting greeting = commandGateway.sendAndWait(new GenericCommandMessage<GetGreetingCommand>(cmd), 1000, TimeUnit.MILLISECONDS);
There are 3 possible outcomes of the above call:
1) Return a non null object.
2) Return a null object (via business logic from my @CommandHandler that queries a DB and doesn't find what I was looking for)
3) Return a null object (returned by Axon framework in case timeout is reached)
I need to implement a way to differentiate between points 2) and 3) so that I can return NOT_FOUND or REQUEST_TIMEOUT statuses accordingly. Do you have any recommendations on how to model this ?
One way that I though of was to add a status field in Greeting (my model object) and in case the @CommandHandler receives nothing from DB I would return a dummy Greeting object with status = -1 (meaning NOT_FOUND), but this solution would mean adding flags to model objects only to differentiate between framework flows and I don't think this is recommended.