Interface ExtensionsClient
ExtensionsClient is a simple interface for executing extension operations programmatically.
The operation to execute is referenced through its name and the name of the extension in which it's defined. Notice that the extension is referenced by name and not GAV, which means that the extension is assumed to be present and activated on the current execution context.
Once the operation is located, the operation execution is parameterized by not only providing parameter values, but also config reference, reconnection and streaming strategies, etc.
Note that this client will be reachable through the mule registry, and you will be able to inject it in any class with lifecycle.
A usage example for an operation with this signature public String getName(@UseConfig config, int account) could be:
{@code
public class UsingExtensionsClient {
@Inject ExtensionsClient client;
...
public void executeWithClient() {
client.<String, Object>executeAsync("myExtensionName", "getName", params ->
params.withConfigRef("conf").withParameter("account", 12)
).whenComplete((result, e) -> {
if (e != null) {
logError(e);
} else {
processResult(result);
}
});
}
</pre>
@since 1.0-
Method Summary
Modifier and TypeMethodDescription<T,A> SourceHandler createSource(String extension, String sourceName, Consumer<SourceResultHandler<T, A>> handler, Consumer<SourceParameterizer> parameters) Creates and initialises aSourceusing a given parameterization.<T,A> CompletableFuture<Result<T, A>> execute(String extension, String operation, Consumer<OperationParameterizer> parameters) Executes an operation asynchronously by returning aCompletableFutureinstance that will complete into aResultwith the corresponding payload and attributes after the operation execution finished.<T,A> Result<T, A> execute(String extension, String operation, OperationParameters parameters) Deprecated.since 4.5.0.<T,A> CompletableFuture<Result<T, A>> executeAsync(String extension, String operation, OperationParameters parameters) Deprecated.since 4.5.0.
-
Method Details
-
execute
@MinMuleVersion("4.5.0") <T,A> CompletableFuture<Result<T,A>> execute(String extension, String operation, Consumer<OperationParameterizer> parameters) Executes an operation asynchronously by returning aCompletableFutureinstance that will complete into aResultwith the corresponding payload and attributes after the operation execution finished.If the executed operation is not asynchronous in nature, the client might choose to actually execute in a synchronous manner.
- Type Parameters:
T- The generic type of the result's payloadA- The generic type of the result's attribute- Parameters:
extension- the name of the extension that contains the operation to be executed.operation- the name of the operation to be executed.parameters- consumers anOperationParameterizerused to configure the operation- Returns:
- a
CompletableFutureinstance that completes into aResultwith the payload content and the corresponding attributes. - Since:
- 4.5.0
-
createSource
@MinMuleVersion("4.5.0") @Experimental <T,A> SourceHandler createSource(String extension, String sourceName, Consumer<SourceResultHandler<T, A>> handler, Consumer<SourceParameterizer> parameters) Creates and initialises aSourceusing a given parameterization.The generated messages will be passed back to the caller through a
Consumerpassed in thecallbackargument. The providedSourceResultHandlerhas a pretty strict contract around how it should be consumed. Follow that contract thoroughly in order to avoid resource leaks or protocol issues with the remote system.The created source is returned in the form of a
SourceHandler. The main purpose of it is to control the lifecycle of the underlying source. When returned, the source is already is initialised (as defined inInitialisable.initialise()) but not started, which means it isn't producing any messages. The source will be started whenSourceHandler.start()is invoked.SourceHandler.stop()can be called for the source to stop producing messages, andSourceHandler.dispose()when the source is no longer needed. Stopped sources can be restarted, but disposed sources are not recoverable, they need to be created again through another call to this method.When {
thisExtensionsClientis disposed, all activeSourceHandlerwill be stopped and disposed as well.NOTE: Experimental feature. Backwards compatibility not guaranteed.
- Type Parameters:
T- the generic type of the result output values produced by the sourceA- the generic type of the result attribute values produced by the source- Parameters:
extension- the name of the extension in which the source is definedsourceName- the name of the source to be created (as it appears in theExtensionModelhandler- aConsumerthat will be invoked each time the source produces a new message, in the form of aSourceResultHandlerparameters- consumers anOperationParameterizerused to configure the source. This is for the source main parameters, not it's callbacks- Returns:
- a
SourceHandler - Since:
- 1.5.0
- See Also:
-
executeAsync
@Deprecated <T,A> CompletableFuture<Result<T,A>> executeAsync(String extension, String operation, OperationParameters parameters) Deprecated.since 4.5.0. Useexecute(String, String, Consumer)insteadExecutes an operation asynchronously by returning aCompletableFutureinstance that will complete into aResultwith the corresponding payload and attributes after the operation execution finished.If the executed operation is not asynchronous in nature, the client might choose to actually execute in a synchronous manner.
- Parameters:
extension- the name of the extension that contains the operation to be executed.operation- the name of the operation to be executed.parameters- anOperationParametersinstance with all the parameters required to execute the operation.- Returns:
- a
CompletableFutureinstance that completes into aResultwith the payload content and the corresponding attributes.
-
execute
@Deprecated <T,A> Result<T,A> execute(String extension, String operation, OperationParameters parameters) throws org.mule.runtime.api.exception.MuleException Deprecated.since 4.5.0. Useexecute(String, String, Consumer)insteadExecutes an operation synchronously and returns aResultwith the operation's output and attributes if available.Take in mind that if the executed operation is asynchronous in nature, this method will automatically wait for it to complete before returning the value
- Parameters:
extension- the name of the extension that contains the operation to be executed.operation- the name of the operation to be executed.parameters- anOperationParametersinstance with all the parameters required to execute the operation.- Returns:
- a
Resultinstance with the payload content and the corresponding attributes after the operation execution. - Throws:
org.mule.runtime.api.exception.MuleException- if any error occurred while executing the operation.
-