How execute new commands automatically

Hello,

If you would like to execute new commands automatically, from the result of the execution of a command; In what part of the Axon framework should it be done?

Hi Luis,

Without knowing the exact use case around your question, what I suggest to be the best approach is to use the CommandGateway#send(Object) function.

This mode of publishing commands will return you a CompletableFuture, upon which you can do chaining calls for certain results of publishing the command.

For example, if the initial send() call is successful, you can do something like:

commandGateway.send(myCommand)
.thenApply(commandResult -> commandGateway.send(mySecondCommand));

For the scenario the publishing of myCommand failed, you can use the CompletableFuture#exceptionally(Function<Trowable, ? extends T>) call to perform some task if you’d want.

Hope this helps!

Cheers,

Steven

Hi Steven,

I would like to do the following with Axon Framework.

https://docs.spring.io/spring-integration/reference/htmlsingle/#samples-cafe

You have a system that receives N of coffee orders, if in the preparation there is an error due to lack of water, sugar, coffee or some ingredient; the system should be able to retry its preparation of said beverage 5 minutes later; I can´t imagine how it could be done with the Axon Framework.

Hi Luis,

one way is to use a RetryScheduler. You can configure it in a CommandGateway.
Another way would be to use a SchedulingExecutor to schedule a task when a command fails. That task would be to send the command again.

Hope this helps.
Cheers,

Allard