public interface WorkflowClient
ActivityCompletionClient
instances used to complete activities
asynchronously. Do not create this object for each request, keep it for the duration of the
process.
Given a workflow interface executing a workflow requires initializing a WorkflowClient
instance, creating a client side stub to the workflow,
and then calling a method annotated with @WorkflowMethod
.
WorkflowClient workflowClient = WorkflowClient.newClient(cadenceServiceHost, cadenceServicePort, domain);
// Create a workflow stub.
FileProcessingWorkflow workflow = workflowClient.newWorkflowStub(FileProcessingWorkflow.class);
There are two ways to start workflow execution: synchronously and asynchronously. Synchronous
invocation starts a workflow and then waits for its completion. If the process that started the
workflow crashes or stops waiting, the workflow continues executing. Because workflows are
potentially long running, and crashes of clients happen, it is not very commonly found in
production use. Asynchronous start initiates workflow execution and immediately returns to the
caller. This is the most common way to start workflows in production code.
Synchronous start:
// Start a workflow and wait for a result.
// Note that if the waiting process is killed, the workflow will continue executing.
String result = workflow.processFile(workflowArgs);
Asynchronous when the workflow result is not needed:
// Returns as soon as the workflow starts.
WorkflowExecution workflowExecution = WorkflowClient.asyncStart(workflow::processFile, workflowArgs);
System.out.println("Started process file workflow with workflowId=\"" + workflowExecution.getWorkflowId()
+ "\" and runId=\"" + workflowExecution.getRunId() + "\"");
Asynchronous when the result is needed:
CompletableFuture<String> result = WorkflowClient.execute(workflow::helloWorld, "User");
If you need to wait for a workflow completion after an asynchronous start, maybe even from a
different process, the simplest way is to call the blocking version again. If WorkflowOptions.getWorkflowIdReusePolicy()
is not AllowDuplicate
then instead of
throwing DuplicateWorkflowException
, it reconnects to an existing
workflow and waits for its completion. The following example shows how to do this from a
different process than the one that started the workflow. All this process needs is a WorkflowId
.
FileProcessingWorkflow workflow = workflowClient.newWorkflowStub(FileProcessingWorkflow.class, workflowId);
// Returns result potentially waiting for workflow to complete.
String result = workflow.processFile(workflowArgs);
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
QUERY_TYPE_STACK_TRCE
Use this constant as a query type to get a workflow stack trace.
|
Modifier and Type | Method and Description |
---|---|
static <R> java.util.concurrent.CompletableFuture<R> |
execute(Functions.Func<R> workflow)
Executes zero argument workflow.
|
static <A1,R> java.util.concurrent.CompletableFuture<R> |
execute(Functions.Func1<A1,R> workflow,
A1 arg1)
Executes one argument workflow asynchronously.
|
static <A1,A2,R> java.util.concurrent.CompletableFuture<R> |
execute(Functions.Func2<A1,A2,R> workflow,
A1 arg1,
A2 arg2)
Executes two argument workflow asynchronously.
|
static <A1,A2,A3,R> |
execute(Functions.Func3<A1,A2,A3,R> workflow,
A1 arg1,
A2 arg2,
A3 arg3)
Executes two argument workflow asynchronously.
|
static <A1,A2,A3,A4,R> |
execute(Functions.Func4<A1,A2,A3,A4,R> workflow,
A1 arg1,
A2 arg2,
A3 arg3,
A4 arg4)
Executes two argument workflow asynchronously.
|
static <A1,A2,A3,A4,A5,R> |
execute(Functions.Func5<A1,A2,A3,A4,A5,R> workflow,
A1 arg1,
A2 arg2,
A3 arg3,
A4 arg4,
A5 arg5)
Executes two argument workflow asynchronously.
|
static <A1,A2,A3,A4,A5,A6,R> |
execute(Functions.Func6<A1,A2,A3,A4,A5,A6,R> workflow,
A1 arg1,
A2 arg2,
A3 arg3,
A4 arg4,
A5 arg5,
A6 arg6)
Executes two argument workflow asynchronously.
|
static java.util.concurrent.CompletableFuture<java.lang.Void> |
execute(Functions.Proc workflow)
Executes zero argument workflow with void return type
|
static <A1> java.util.concurrent.CompletableFuture<java.lang.Void> |
execute(Functions.Proc1<A1> workflow,
A1 arg1)
Executes one argument workflow with void return type
|
static <A1,A2> java.util.concurrent.CompletableFuture<java.lang.Void> |
execute(Functions.Proc2<A1,A2> workflow,
A1 arg1,
A2 arg2)
Executes two argument workflow with void return type
|
static <A1,A2,A3> java.util.concurrent.CompletableFuture<java.lang.Void> |
execute(Functions.Proc3<A1,A2,A3> workflow,
A1 arg1,
A2 arg2,
A3 arg3)
Executes three argument workflow with void return type
|
static <A1,A2,A3,A4> |
execute(Functions.Proc4<A1,A2,A3,A4> workflow,
A1 arg1,
A2 arg2,
A3 arg3,
A4 arg4)
Executes four argument workflow with void return type
|
static <A1,A2,A3,A4,A5> |
execute(Functions.Proc5<A1,A2,A3,A4,A5> workflow,
A1 arg1,
A2 arg2,
A3 arg3,
A4 arg4,
A5 arg5)
Executes zero argument workflow with void return type
|
static <A1,A2,A3,A4,A5,A6> |
execute(Functions.Proc6<A1,A2,A3,A4,A5,A6> workflow,
A1 arg1,
A2 arg2,
A3 arg3,
A4 arg4,
A5 arg5,
A6 arg6)
Executes zero argument workflow with void return type
|
java.lang.String |
getDomain() |
ActivityCompletionClient |
newActivityCompletionClient()
Creates new
ActivityCompletionClient that can be used to complete activities
asynchronously. |
static WorkflowClient |
newInstance(IWorkflowService service,
java.lang.String domain)
Creates client that connects to an instance of the Cadence Service.
|
static WorkflowClient |
newInstance(IWorkflowService service,
java.lang.String domain,
WorkflowClientOptions options)
Creates client that connects to an instance of the Cadence Service.
|
static WorkflowClient |
newInstance(java.lang.String domain)
Creates worker that connects to the local instance of the Cadence Service that listens on a
default port (7933).
|
static WorkflowClient |
newInstance(java.lang.String host,
int port,
java.lang.String domain)
Creates client that connects to an instance of the Cadence Service.
|
static WorkflowClient |
newInstance(java.lang.String host,
int port,
java.lang.String domain,
WorkflowClientOptions options)
Creates client that connects to an instance of the Cadence Service.
|
static WorkflowClient |
newInstance(java.lang.String domain,
WorkflowClientOptions options)
Creates worker that connects to the local instance of the Cadence Service that listens on a
default port (7933).
|
WorkflowStub |
newUntypedWorkflowStub(java.lang.String workflowId,
java.util.Optional<java.lang.String> runId,
java.util.Optional<java.lang.String> workflowType)
Creates workflow untyped client stub for a known execution.
|
WorkflowStub |
newUntypedWorkflowStub(java.lang.String workflowType,
WorkflowOptions options)
Creates workflow untyped client stub that can be used to start a single workflow execution.
|
WorkflowStub |
newUntypedWorkflowStub(WorkflowExecution execution,
java.util.Optional<java.lang.String> workflowType)
Creates workflow untyped client stub for a known execution.
|
<T> T |
newWorkflowStub(java.lang.Class<T> workflowInterface)
Creates workflow client stub that can be used to start a single workflow execution.
|
<T> T |
newWorkflowStub(java.lang.Class<T> workflowInterface,
java.lang.String workflowId)
Creates workflow client stub for a known execution.
|
<T> T |
newWorkflowStub(java.lang.Class<T> workflowInterface,
java.lang.String workflowId,
java.util.Optional<java.lang.String> runId)
Creates workflow client stub for a known execution.
|
<T> T |
newWorkflowStub(java.lang.Class<T> workflowInterface,
WorkflowOptions options)
Creates workflow client stub that can be used to start a single workflow execution.
|
static <R> WorkflowExecution |
start(Functions.Func<R> workflow)
Executes zero argument workflow.
|
static <A1,R> WorkflowExecution |
start(Functions.Func1<A1,R> workflow,
A1 arg1)
Executes one argument workflow asynchronously.
|
static <A1,A2,R> WorkflowExecution |
start(Functions.Func2<A1,A2,R> workflow,
A1 arg1,
A2 arg2)
Executes two argument workflow asynchronously.
|
static <A1,A2,A3,R> |
start(Functions.Func3<A1,A2,A3,R> workflow,
A1 arg1,
A2 arg2,
A3 arg3)
Executes two argument workflow asynchronously.
|
static <A1,A2,A3,A4,R> |
start(Functions.Func4<A1,A2,A3,A4,R> workflow,
A1 arg1,
A2 arg2,
A3 arg3,
A4 arg4)
Executes two argument workflow asynchronously.
|
static <A1,A2,A3,A4,A5,R> |
start(Functions.Func5<A1,A2,A3,A4,A5,R> workflow,
A1 arg1,
A2 arg2,
A3 arg3,
A4 arg4,
A5 arg5)
Executes two argument workflow asynchronously.
|
static <A1,A2,A3,A4,A5,A6,R> |
start(Functions.Func6<A1,A2,A3,A4,A5,A6,R> workflow,
A1 arg1,
A2 arg2,
A3 arg3,
A4 arg4,
A5 arg5,
A6 arg6)
Executes two argument workflow asynchronously.
|
static WorkflowExecution |
start(Functions.Proc workflow)
Executes zero argument workflow with void return type
|
static <A1> WorkflowExecution |
start(Functions.Proc1<A1> workflow,
A1 arg1)
Executes one argument workflow with void return type
|
static <A1,A2> WorkflowExecution |
start(Functions.Proc2<A1,A2> workflow,
A1 arg1,
A2 arg2)
Executes two argument workflow with void return type
|
static <A1,A2,A3> WorkflowExecution |
start(Functions.Proc3<A1,A2,A3> workflow,
A1 arg1,
A2 arg2,
A3 arg3)
Executes three argument workflow with void return type
|
static <A1,A2,A3,A4> |
start(Functions.Proc4<A1,A2,A3,A4> workflow,
A1 arg1,
A2 arg2,
A3 arg3,
A4 arg4)
Executes four argument workflow with void return type
|
static <A1,A2,A3,A4,A5> |
start(Functions.Proc5<A1,A2,A3,A4,A5> workflow,
A1 arg1,
A2 arg2,
A3 arg3,
A4 arg4,
A5 arg5)
Executes zero argument workflow with void return type
|
static <A1,A2,A3,A4,A5,A6> |
start(Functions.Proc6<A1,A2,A3,A4,A5,A6> workflow,
A1 arg1,
A2 arg2,
A3 arg3,
A4 arg4,
A5 arg5,
A6 arg6)
Executes zero argument workflow with void return type
|
static final java.lang.String QUERY_TYPE_STACK_TRCE
static WorkflowClient newInstance(java.lang.String domain)
domain
- domain that worker uses to poll.static WorkflowClient newInstance(java.lang.String domain, WorkflowClientOptions options)
domain
- domain that worker uses to poll.options
- Options (like DataConverter
er override) for
configuring client.static WorkflowClient newInstance(java.lang.String host, int port, java.lang.String domain)
host
- of the Cadence Service endpointport
- of the Cadence Service endpointdomain
- domain that worker uses to poll.static WorkflowClient newInstance(java.lang.String host, int port, java.lang.String domain, WorkflowClientOptions options)
host
- of the Cadence Service endpointport
- of the Cadence Service endpointdomain
- domain that worker uses to poll.options
- Options (like DataConverter
er override) for
configuring client.static WorkflowClient newInstance(IWorkflowService service, java.lang.String domain)
service
- client to the Cadence Service endpoint.domain
- domain that worker uses to poll.static WorkflowClient newInstance(IWorkflowService service, java.lang.String domain, WorkflowClientOptions options)
service
- client to the Cadence Service endpoint.domain
- domain that worker uses to poll.options
- Options (like DataConverter
er override) for
configuring client.java.lang.String getDomain()
<T> T newWorkflowStub(java.lang.Class<T> workflowInterface)
workflowInterface
- interface that given workflow implements<T> T newWorkflowStub(java.lang.Class<T> workflowInterface, WorkflowOptions options)
workflowInterface
- interface that given workflow implementsoptions
- options used to start a workflow through returned stub<T> T newWorkflowStub(java.lang.Class<T> workflowInterface, java.lang.String workflowId)
workflowInterface
- interface that given workflow implements.workflowId
- Workflow id.<T> T newWorkflowStub(java.lang.Class<T> workflowInterface, java.lang.String workflowId, java.util.Optional<java.lang.String> runId)
workflowInterface
- interface that given workflow implements.workflowId
- Workflow id.runId
- Run id of the workflow execution.WorkflowStub newUntypedWorkflowStub(java.lang.String workflowType, WorkflowOptions options)
workflowType
- name of the workflow typeoptions
- options used to start a workflow through returned stubWorkflowStub newUntypedWorkflowStub(java.lang.String workflowId, java.util.Optional<java.lang.String> runId, java.util.Optional<java.lang.String> workflowType)
workflowId
- workflow id and optional run id for executionrunId
- runId of the workflow execution. If not provided the last workflow with the given
workflowId is assumed.workflowType
- type of the workflow. Optional as it is used for error reporting only.WorkflowStub newUntypedWorkflowStub(WorkflowExecution execution, java.util.Optional<java.lang.String> workflowType)
execution
- workflow id and optional run id for executionworkflowType
- type of the workflow. Optional as it is used for error reporting only.ActivityCompletionClient newActivityCompletionClient()
ActivityCompletionClient
that can be used to complete activities
asynchronously. Only relevant for activity implementations that called Activity.doNotCompleteOnReturn()
.
TODO: Activity completion options with retries and timeouts. <
static WorkflowExecution start(Functions.Proc workflow)
workflow
- The only supported value is method reference to a proxy created through newWorkflowStub(Class, WorkflowOptions)
.static <A1> WorkflowExecution start(Functions.Proc1<A1> workflow, A1 arg1)
workflow
- The only supported value is method reference to a proxy created through newWorkflowStub(Class, WorkflowOptions)
.arg1
- first workflow function parameterstatic <A1,A2> WorkflowExecution start(Functions.Proc2<A1,A2> workflow, A1 arg1, A2 arg2)
workflow
- The only supported value is method reference to a proxy created through newWorkflowStub(Class, WorkflowOptions)
.arg1
- first workflow function parameterarg2
- second workflow function parameterstatic <A1,A2,A3> WorkflowExecution start(Functions.Proc3<A1,A2,A3> workflow, A1 arg1, A2 arg2, A3 arg3)
workflow
- The only supported value is method reference to a proxy created through newWorkflowStub(Class, WorkflowOptions)
.arg1
- first workflow function parameterarg2
- second workflow function parameterarg3
- third workflow function parameterstatic <A1,A2,A3,A4> WorkflowExecution start(Functions.Proc4<A1,A2,A3,A4> workflow, A1 arg1, A2 arg2, A3 arg3, A4 arg4)
workflow
- The only supported value is method reference to a proxy created through newWorkflowStub(Class, WorkflowOptions)
.arg1
- first workflow function parameterarg2
- second workflow function parameterarg3
- third workflow function parameterarg4
- fourth workflow function parameterstatic <A1,A2,A3,A4,A5> WorkflowExecution start(Functions.Proc5<A1,A2,A3,A4,A5> workflow, A1 arg1, A2 arg2, A3 arg3, A4 arg4, A5 arg5)
workflow
- The only supported value is method reference to a proxy created through newWorkflowStub(Class, WorkflowOptions)
.arg1
- first workflow function parameterarg2
- second workflow function parameterarg3
- third workflow function parameterarg4
- fourth workflow function parameterarg5
- fifth workflow function parameterstatic <A1,A2,A3,A4,A5,A6> WorkflowExecution start(Functions.Proc6<A1,A2,A3,A4,A5,A6> workflow, A1 arg1, A2 arg2, A3 arg3, A4 arg4, A5 arg5, A6 arg6)
workflow
- The only supported value is method reference to a proxy created through newWorkflowStub(Class, WorkflowOptions)
.arg1
- first workflow function parameterarg2
- second workflow function parameterarg3
- third workflow function parameterarg4
- fourth workflow function parameterarg5
- sixth workflow function parameterarg6
- sixth workflow function parameterstatic <R> WorkflowExecution start(Functions.Func<R> workflow)
workflow
- The only supported value is method reference to a proxy created through newWorkflowStub(Class, WorkflowOptions)
.static <A1,R> WorkflowExecution start(Functions.Func1<A1,R> workflow, A1 arg1)
workflow
- The only supported value is method reference to a proxy created through newWorkflowStub(Class, WorkflowOptions)
.arg1
- first workflow argumentstatic <A1,A2,R> WorkflowExecution start(Functions.Func2<A1,A2,R> workflow, A1 arg1, A2 arg2)
workflow
- The only supported value is method reference to a proxy created through newWorkflowStub(Class, WorkflowOptions)
.arg1
- first workflow function parameterarg2
- second workflow function parameterstatic <A1,A2,A3,R> WorkflowExecution start(Functions.Func3<A1,A2,A3,R> workflow, A1 arg1, A2 arg2, A3 arg3)
workflow
- The only supported value is method reference to a proxy created through newWorkflowStub(Class, WorkflowOptions)
.arg1
- first workflow function parameterarg2
- second workflow function parameterarg3
- third workflow function parameterstatic <A1,A2,A3,A4,R> WorkflowExecution start(Functions.Func4<A1,A2,A3,A4,R> workflow, A1 arg1, A2 arg2, A3 arg3, A4 arg4)
workflow
- The only supported value is method reference to a proxy created through newWorkflowStub(Class, WorkflowOptions)
.arg1
- first workflow function parameterarg2
- second workflow function parameterarg3
- third workflow function parameterarg4
- fourth workflow function parameterstatic <A1,A2,A3,A4,A5,R> WorkflowExecution start(Functions.Func5<A1,A2,A3,A4,A5,R> workflow, A1 arg1, A2 arg2, A3 arg3, A4 arg4, A5 arg5)
workflow
- The only supported value is method reference to a proxy created through newWorkflowStub(Class, WorkflowOptions)
.arg1
- first workflow function parameterarg2
- second workflow function parameterarg3
- third workflow function parameterarg4
- fourth workflow function parameterarg5
- sixth workflow function parameterstatic <A1,A2,A3,A4,A5,A6,R> WorkflowExecution start(Functions.Func6<A1,A2,A3,A4,A5,A6,R> workflow, A1 arg1, A2 arg2, A3 arg3, A4 arg4, A5 arg5, A6 arg6)
workflow
- The only supported value is method reference to a proxy created through newWorkflowStub(Class, WorkflowOptions)
.arg1
- first workflow argumentarg2
- second workflow function parameterarg3
- third workflow function parameterarg4
- fourth workflow function parameterarg5
- sixth workflow function parameterarg6
- sixth workflow function parameterstatic java.util.concurrent.CompletableFuture<java.lang.Void> execute(Functions.Proc workflow)
workflow
- The only supported value is method reference to a proxy created through newWorkflowStub(Class, WorkflowOptions)
.static <A1> java.util.concurrent.CompletableFuture<java.lang.Void> execute(Functions.Proc1<A1> workflow, A1 arg1)
workflow
- The only supported value is method reference to a proxy created through newWorkflowStub(Class, WorkflowOptions)
.arg1
- first workflow function parameterstatic <A1,A2> java.util.concurrent.CompletableFuture<java.lang.Void> execute(Functions.Proc2<A1,A2> workflow, A1 arg1, A2 arg2)
workflow
- The only supported value is method reference to a proxy created through newWorkflowStub(Class, WorkflowOptions)
.arg1
- first workflow function parameterarg2
- second workflow function parameterstatic <A1,A2,A3> java.util.concurrent.CompletableFuture<java.lang.Void> execute(Functions.Proc3<A1,A2,A3> workflow, A1 arg1, A2 arg2, A3 arg3)
workflow
- The only supported value is method reference to a proxy created through newWorkflowStub(Class, WorkflowOptions)
.arg1
- first workflow function parameterarg2
- second workflow function parameterarg3
- third workflow function parameterstatic <A1,A2,A3,A4> java.util.concurrent.CompletableFuture<java.lang.Void> execute(Functions.Proc4<A1,A2,A3,A4> workflow, A1 arg1, A2 arg2, A3 arg3, A4 arg4)
workflow
- The only supported value is method reference to a proxy created through newWorkflowStub(Class, WorkflowOptions)
.arg1
- first workflow function parameterarg2
- second workflow function parameterarg3
- third workflow function parameterarg4
- fourth workflow function parameterstatic <A1,A2,A3,A4,A5> java.util.concurrent.CompletableFuture<java.lang.Void> execute(Functions.Proc5<A1,A2,A3,A4,A5> workflow, A1 arg1, A2 arg2, A3 arg3, A4 arg4, A5 arg5)
workflow
- The only supported value is method reference to a proxy created through newWorkflowStub(Class, WorkflowOptions)
.arg1
- first workflow function parameterarg2
- second workflow function parameterarg3
- third workflow function parameterarg4
- fourth workflow function parameterarg5
- fifth workflow function parameterstatic <A1,A2,A3,A4,A5,A6> java.util.concurrent.CompletableFuture<java.lang.Void> execute(Functions.Proc6<A1,A2,A3,A4,A5,A6> workflow, A1 arg1, A2 arg2, A3 arg3, A4 arg4, A5 arg5, A6 arg6)
workflow
- The only supported value is method reference to a proxy created through newWorkflowStub(Class, WorkflowOptions)
.arg1
- first workflow function parameterarg2
- second workflow function parameterarg3
- third workflow function parameterarg4
- fourth workflow function parameterarg5
- sixth workflow function parameterarg6
- sixth workflow function parameterstatic <R> java.util.concurrent.CompletableFuture<R> execute(Functions.Func<R> workflow)
workflow
- The only supported value is method reference to a proxy created through newWorkflowStub(Class, WorkflowOptions)
.static <A1,R> java.util.concurrent.CompletableFuture<R> execute(Functions.Func1<A1,R> workflow, A1 arg1)
workflow
- The only supported value is method reference to a proxy created through newWorkflowStub(Class, WorkflowOptions)
.arg1
- first workflow argumentstatic <A1,A2,R> java.util.concurrent.CompletableFuture<R> execute(Functions.Func2<A1,A2,R> workflow, A1 arg1, A2 arg2)
workflow
- The only supported value is method reference to a proxy created through newWorkflowStub(Class, WorkflowOptions)
.arg1
- first workflow function parameterarg2
- second workflow function parameterstatic <A1,A2,A3,R> java.util.concurrent.CompletableFuture<R> execute(Functions.Func3<A1,A2,A3,R> workflow, A1 arg1, A2 arg2, A3 arg3)
workflow
- The only supported value is method reference to a proxy created through newWorkflowStub(Class, WorkflowOptions)
.arg1
- first workflow function parameterarg2
- second workflow function parameterarg3
- third workflow function parameterstatic <A1,A2,A3,A4,R> java.util.concurrent.CompletableFuture<R> execute(Functions.Func4<A1,A2,A3,A4,R> workflow, A1 arg1, A2 arg2, A3 arg3, A4 arg4)
workflow
- The only supported value is method reference to a proxy created through newWorkflowStub(Class, WorkflowOptions)
.arg1
- first workflow function parameterarg2
- second workflow function parameterarg3
- third workflow function parameterarg4
- fourth workflow function parameterstatic <A1,A2,A3,A4,A5,R> java.util.concurrent.CompletableFuture<R> execute(Functions.Func5<A1,A2,A3,A4,A5,R> workflow, A1 arg1, A2 arg2, A3 arg3, A4 arg4, A5 arg5)
workflow
- The only supported value is method reference to a proxy created through newWorkflowStub(Class, WorkflowOptions)
.arg1
- first workflow function parameterarg2
- second workflow function parameterarg3
- third workflow function parameterarg4
- fourth workflow function parameterarg5
- sixth workflow function parameterstatic <A1,A2,A3,A4,A5,A6,R> java.util.concurrent.CompletableFuture<R> execute(Functions.Func6<A1,A2,A3,A4,A5,A6,R> workflow, A1 arg1, A2 arg2, A3 arg3, A4 arg4, A5 arg5, A6 arg6)
workflow
- The only supported value is method reference to a proxy created through newWorkflowStub(Class, WorkflowOptions)
.arg1
- first workflow argumentarg2
- second workflow function parameterarg3
- third workflow function parameterarg4
- fourth workflow function parameterarg5
- sixth workflow function parameterarg6
- sixth workflow function parameter