Custom command gateway - how to achieve "sendAndWait" behavior

First: I cannot find docs for custom command gateways in v4.4, see my other question: Custom Command Gateway - still supported?

Assuming they still are part of the framework: When I have

public interface MyCommandGateway {
     void handleMyCommand(MyCommand cmd);

when I follow the 4.2 docs (“A void return type will cause the method to return immediately, unless there are other indications on the method that one would want to wait, such as a timeout or declared exceptions.”) this will effectively result in a call equivalent to commandGateway.send(cmd).

How do I have to define my interface method signature, to achieve a sendAndWait(cmd) behavior?

Background: I am converting kafka messages to axon commands in a Spring Kafka Handler and need to wait for success/failure to be able to do retry/errorHandling and sendAndWaitis sufficient for me, I do not want/need to define a custom error behavior. But I still would like to use a type safe, specific gateway that can explicitely handle my commands, instead of the generic one.


OK, reading one paragraph further, I found:

“Any other return type will cause the method to block until a result is available.”

But: what would be an appropriate return type? The Aggregate instance? The AggregateIdentifier?


Are you using Axon-Kafka extension?

No, my project has a custom kafka lib, not related to axon.

When it comes to return types from command handling, I’d try to stick to the following set:

  1. Identifiers of created entities. Like the aggregate root, or members within the aggregate.
  2. An OK, potentially in the form of a defined status code with several types of successful results.
  3. A NOK, either in the form of an exception or potentially in the form of defined status codes with several types of unsuccessful results.