Hi Nicolas,
if you want to have a thread waiting for a callback before moving on, you can use the FutureCallback. It implements both Axon’s callback and Java’s Future interfaces. You would use it like this:
FutureCallback callback = new FutureCallback();
commandBus.dispatch(command, callback);
callback.get(); // this will block the thread until the callback is invoked.
The get() method is defined by the Future interface, and is quite ugly. You can also use the getResult() to avoid the try/catch hell forced by get().
If an error occurs, get() will throw an exceptoin, otherwise you get the result of the command processing.
There is also a CommandTemplate class to make sendAndWait processes a bit easier.
With this approach, the REST implementation using Spring MVC is just plain and simple.
Alternatively, you can choose to use Servlet 3.0 async support and use a callback that simply commits a response to the client. Then you don’t have a blocking thread per connection. I am not sure Spring supports Servlet 3 async, though.
Cheers,
Allard