@NoImplement @MinMuleVersion(value="4.5.0") public interface RouterCompletionCallback extends CompletionCallback<Object,Object>
Routes notify their outcome.
In order to implement a Router (that is, an operation that receives one or more Routes), the method needs to:
Route typeRouterCompletionCallback type
When the execution of the Router has finished, it has to notify the Result either by invoking the
CompletionCallback.success(Result) or CompletionCallback.error(Throwable) methods. Only then will the execution of the Router be considered as
completed and the next processor in the pipeline will be executed. If the CompletionCallback.success(Result) or
CompletionCallback.error(Throwable) methods are invoked before any of the nested Routes is completed, the Result of the
nested execution will be lost and never propagated.
For example, a Router can be declared as:
public void twoRoutesRouter(WhenRoute when, @Optional OtherwiseRoute other, RouterCompletionCallback callback) {
if (when.shouldExecute()) {
when.getChain().process(routeResult -> callback.success(routeResult), (e, r) -> callback.error(e));
} else if (other != null && other.shouldExecute()) {
other.getChain().process(callback::success, (e, r) -> callback.error(e));
} else {
callback.error(new IllegalArgumentException("No route could be executed"));
}
}
error, successCopyright © 2023. All rights reserved.