Hi,
I just have a question about the difference of behavior when using Dispatch and Handler interceptors with a FutureCallback.
Let’s take a concrete example :
I setup a BeanValidationInterceptor as a MessageDispatchInterceptor on the SimpleCommandBus, and use the DefaultCommandGateway in front of the SimpleCommandBus, using the
*<R> CompletableFuture<R> send(Object command)* method (so I can easily switch to an **AsynchronousCommandBus** in the future if needed).
I can see that in that case, a FutureCallback is indeed created in the background so that we are able to get the result of the command execution asynchronously.
This makes it possible to handle errors on the client side, as following for example :
if(commandGateway.send(
new DoSomethingCommand(id))
.isCompletedExceptionally()) { //do something }
But I also notice that the FutureCallback is not passed to the dispatch interceptors chain, meaning that this condition will never be true even in case of validation errors (as *completeExceptionnally* won't be called on the FutureCallback instance).
On the other hand, if I setup the **BeanValidationInterceptor** as a **MessageHandlerInterceptor**, the FutureCallback is correctly called as it's passed to the message handler interceptors chain.
Is it designed like this on purpose ? I understand that the MessageDispatchInterceptor is always executed on the thread that dispatches the Command but wouldn't it be more consistent to notify the callback in that case as well ?
Thank you,
Best Regards,
Jerome