Interface NexusServiceClient<T>
- Type Parameters:
T- the Nexus service interface this client is bound to
- All Superinterfaces:
UntypedNexusServiceClient
Typed client for invoking standalone Nexus operations on a specific service interface
T.
Operations are dispatched via method references on T (or equivalent Functions.Func2 / Functions.Func1 lambdas); the client extracts the operation name from
the invocation and delegates to NexusClient. For visibility queries (list/count) across
operations, use NexusClient directly.
Usage
Given a Nexus service interface:
@Service
public interface GreeterService {
@Operation String greet(String name); // input + output
@Operation String now(); // no input, output
@Operation Void log(String message); // input, no output
}
Build a client and dispatch by method reference:
NexusClient nexusClient = NexusClient.newInstance(workflowServiceStubs);
NexusServiceClient<GreeterService> client =
nexusClient.newNexusServiceClient(GreeterService.class, "greeter-endpoint");
StartNexusOperationOptions options = StartNexusOperationOptions.newBuilder()
.setId(UUID.randomUUID().toString())
.build();
// Operation that takes an input (Func2 overload):
String hi = client.execute(GreeterService::greet, options, "Ada");
// Operation with no input (Func1 overload):
String t = client.execute(GreeterService::now, options);
// Operation that returns Void: the same overloads work, R is just Void.
client.execute(GreeterService::log, options, "hello");
// Get a handle instead of blocking:
NexusOperationHandle<String> handle = client.start(GreeterService::greet, options, "Ada");
String result = handle.getResult();
// Run asynchronously:
CompletableFuture<String> future =
client.executeAsync(GreeterService::greet, options, "Ada");
- See Also:
-
Method Summary
Modifier and TypeMethodDescription<R> Rexecute(Functions.Func1<T, R> operation, StartNexusOperationOptions options) Executes a no-input operation synchronously with per-call options.<U,R> R execute(Functions.Func2<T, U, R> operation, StartNexusOperationOptions options, U input) Executes an operation synchronously with per-call options.<R> CompletableFuture<R> executeAsync(Functions.Func1<T, R> operation, StartNexusOperationOptions options) Async variant ofexecute(Functions.Func1, StartNexusOperationOptions)for no-input operations.<U,R> CompletableFuture <R> executeAsync(Functions.Func2<T, U, R> operation, StartNexusOperationOptions options, U input) Async variant ofexecute(Functions.Func2, StartNexusOperationOptions, Object).<R> NexusOperationHandle<R> start(Functions.Func1<T, R> operation, StartNexusOperationOptions options) Starts a no-input operation with per-call options and returns a typed handle.<U,R> NexusOperationHandle <R> start(Functions.Func2<T, U, R> operation, StartNexusOperationOptions options, U input) Starts an operation with per-call options and returns a typed handle.Methods inherited from interface io.temporal.client.UntypedNexusServiceClient
execute, execute, start
-
Method Details
-
execute
Executes an operation synchronously with per-call options.- Parameters:
operation- a method reference onTidentifying the operationoptions- per-call options controlling timeouts, search attributes, etc.input- the operation input- Returns:
- the operation result
- Throws:
NexusOperationException- if the operation failed, timed out, or was cancelled
-
start
<U,R> NexusOperationHandle<R> start(Functions.Func2<T, U, R> operation, StartNexusOperationOptions options, U input) Starts an operation with per-call options and returns a typed handle.- Parameters:
operation- a method reference onTidentifying the operationoptions- per-call options controlling timeouts, search attributes, etc.input- the operation input- Returns:
- a typed handle bound to the started operation
-
executeAsync
<U,R> CompletableFuture<R> executeAsync(Functions.Func2<T, U, R> operation, StartNexusOperationOptions options, U input) Async variant ofexecute(Functions.Func2, StartNexusOperationOptions, Object). Returns aCompletableFuturethat completes with the typed result, or completes exceptionally if the operation fails.- Parameters:
operation- a method reference onTidentifying the operationoptions- per-call options controlling timeouts, search attributes, etc.input- the operation input
-
execute
Executes a no-input operation synchronously with per-call options. Use this overload for Nexus operations declared without an input parameter onT(e.g.R operation()).- Parameters:
operation- a method reference onTidentifying the no-input operationoptions- per-call options controlling timeouts, search attributes, etc.- Returns:
- the operation result
- Throws:
NexusOperationException- if the operation failed, timed out, or was cancelled
-
start
<R> NexusOperationHandle<R> start(Functions.Func1<T, R> operation, StartNexusOperationOptions options) Starts a no-input operation with per-call options and returns a typed handle. Use this overload for Nexus operations declared without an input parameter onT.- Parameters:
operation- a method reference onTidentifying the no-input operationoptions- per-call options controlling timeouts, search attributes, etc.- Returns:
- a typed handle bound to the started operation
-
executeAsync
<R> CompletableFuture<R> executeAsync(Functions.Func1<T, R> operation, StartNexusOperationOptions options) Async variant ofexecute(Functions.Func1, StartNexusOperationOptions)for no-input operations. Returns aCompletableFuturethat completes with the typed result, or completes exceptionally if the operation fails.- Parameters:
operation- a method reference onTidentifying the no-input operationoptions- per-call options controlling timeouts, search attributes, etc.
-