@NoImplement
public interface FlowListener
Operation can declare an argument of this type and the runtime will automatically inject an implementation which the operation can use.
An example use case is an operation which needs to await for the owning flow to finish in order to execute some clean-up, or wants to know the final outcome in order to log it or audit it.
For example, let's see a very simple logging case
public void listeningOperation(FlowListener listener) {
listener.onSuccess(message -> LOGGER.debug("Response obtained", message.getPayload().getValue()));
listener.onError(exception -> LOGGER.debug("Flow failed", exception));
listener.onComplete(() -> doCleanUp());
}
}
Instances are not reusable and should not be cached. Instances are also not thread-safe. No instance should be used in a thread different from the one executing the operation.
| Modifier and Type | Method and Description |
|---|---|
void |
onComplete(Runnable handler)
Executes the given
handler when the Event on which the operation was executed is terminated. |
void |
onError(Consumer<Exception> handler)
Executes the given
handler when the flow that owns the listening operation fails. |
void |
onSuccess(Consumer<org.mule.runtime.api.message.Message> handler)
Executes the given
handler when the flow that owns the listening operation finishes. |
void onSuccess(Consumer<org.mule.runtime.api.message.Message> handler)
handler when the flow that owns the listening operation finishes.
If the method is invoked several times on the same instance, the last handler wins and the prior ones get discarded.
The handler should be written in a way in which it doesn't fail. If it does fail, the runtime will
log and discard the error. Be a good citizen, do not put the runtime into that situation.
handler - a Message Consumervoid onError(Consumer<Exception> handler)
handler when the flow that owns the listening operation fails.
If the method is invoked several times on the same instance, the last handler wins and the prior ones get discarded.
The handler should be written in a way in which it doesn't fail. If it does fail, the runtime will
log and discard the error. Be a good citizen, do not put the runtime into that situation.
void onComplete(Runnable handler)
handler when the Event on which the operation was executed is terminated.
Unlike onSuccess(Consumer) and onError(Consumer), this one doesn't depend on the flow's response but in
the completion of the event. This includes all other asynchronous tasks, flow-ref invocations, etc.
Since this method is equivalent to a java finally block, it is ideal for
performing cleanup and resource deallocation tasks.
The handler should be written in a way in which it doesn't fail. If it does fail, the runtime will
log and discard the error. Be a good citizen, do not put the runtime into that situation.
handler - Copyright © 2019 MuleSoft, Inc.. All rights reserved.