Class DaprWorkflowClient
- All Implemented Interfaces:
AutoCloseable
- Direct Known Subclasses:
ObservationDaprWorkflowClient
-
Constructor Summary
ConstructorsModifierConstructorDescriptionPublic constructor for DaprWorkflowClient.DaprWorkflowClient(Properties properties) Public constructor for DaprWorkflowClient.protectedDaprWorkflowClient(Properties properties, io.grpc.ClientInterceptor... additionalInterceptors) Protected constructor for DaprWorkflowClient that allows subclasses to inject additional gRPCClientInterceptors onto the channel (e.g.DaprWorkflowClient(Properties properties, io.opentelemetry.api.trace.Tracer tracer) Public constructor for DaprWorkflowClient. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the inner DurableTask client and shutdown the GRPC channel.getInstanceHistory(String instanceId) Gets the full execution history of a workflow instance.getInstanceState(String instanceId, boolean getInputsAndOutputs) Deprecated, for removal: This API element is subject to removal in a future version.getWorkflowState(String instanceId, boolean getInputsAndOutputs) Fetches workflow instance metadata from the configured durable store.getWorkflowState(String instanceId, boolean getInputsAndOutputs, String appId) Fetches workflow instance metadata from the durable store of another app.Lists workflow instance IDs.listInstanceIds(String continuationToken, Integer pageSize) Lists workflow instance IDs with pagination.booleanpurgeInstance(String workflowInstanceId) Deprecated, for removal: This API element is subject to removal in a future version.UsepurgeWorkflow(String)instead.booleanpurgeWorkflow(String workflowInstanceId) Purges workflow instance state from the workflow state store.booleanpurgeWorkflow(String workflowInstanceId, String appId) Purges workflow instance state from the workflow state store of another app.voidraiseEvent(String workflowInstanceId, String eventName, Object eventPayload) Sends an event notification message to awaiting workflow instance.voidraiseEvent(String workflowInstanceId, String eventName, Object eventPayload, String appId) Sends an event notification message to a waiting workflow instance owned by another app.rerunWorkflowFromEvent(String sourceInstanceId, int eventId) Reruns a workflow from a history event, creating a new workflow instance.rerunWorkflowFromEvent(String sourceInstanceId, int eventId, RerunWorkflowFromEventOptions options) Reruns a workflow from a history event with options, creating a new workflow instance.voidresumeWorkflow(String workflowInstanceId, String reason) Resume the workflow associated with the provided instance id.voidresumeWorkflow(String workflowInstanceId, String reason, String appId) Resume the workflow associated with the provided instance id, owned by another app.scheduleNewWorkflow(Class<T> clazz) Schedules a new workflow using DurableTask client.scheduleNewWorkflow(Class<T> clazz, NewWorkflowOptions options) Schedules a new workflow with a specified set of options for execution.scheduleNewWorkflow(Class<T> clazz, Object input) Schedules a new workflow using DurableTask client.scheduleNewWorkflow(Class<T> clazz, Object input, String instanceId) Schedules a new workflow using DurableTask client.scheduleNewWorkflow(String name) Schedules a new workflow using DurableTask client.scheduleNewWorkflow(String name, NewWorkflowOptions options) Schedules a new workflow with a specified set of options for execution.scheduleNewWorkflow(String name, Object input) Schedules a new workflow using DurableTask client.scheduleNewWorkflow(String name, Object input, String instanceId) Schedules a new workflow using DurableTask client.voidsuspendWorkflow(String workflowInstanceId, String reason) Suspend the workflow associated with the provided instance id.voidsuspendWorkflow(String workflowInstanceId, String reason, String appId) Suspend the workflow associated with the provided instance id, owned by another app.voidterminateWorkflow(String workflowInstanceId, Object output) Terminates the workflow associated with the provided instance id.voidterminateWorkflow(String workflowInstanceId, Object output, String appId) Terminates the workflow associated with the provided instance id, owned by another app.waitForInstanceCompletion(String instanceId, Duration timeout, boolean getInputsAndOutputs) Deprecated, for removal: This API element is subject to removal in a future version.UsewaitForWorkflowCompletion(String, Duration, boolean)instead.waitForInstanceStart(String instanceId, Duration timeout, boolean getInputsAndOutputs) Deprecated, for removal: This API element is subject to removal in a future version.UsewaitForWorkflowStart(String, Duration, boolean)instead.waitForWorkflowCompletion(String instanceId, Duration timeout, boolean getInputsAndOutputs) Waits for an workflow to complete and returns anWorkflowStateobject that contains metadata about the completed instance.waitForWorkflowCompletion(String instanceId, Duration timeout, boolean getInputsAndOutputs, String appId) Waits for a workflow owned by another app to complete.waitForWorkflowStart(String instanceId, Duration timeout, boolean getInputsAndOutputs) Waits for a workflow to start running and returns anWorkflowStateobject that contains metadata about the started instance and optionally its input, output, and custom status payloads.waitForWorkflowStart(String instanceId, Duration timeout, boolean getInputsAndOutputs, String appId) Waits for a workflow owned by another app to start running.
-
Constructor Details
-
DaprWorkflowClient
public DaprWorkflowClient()Public constructor for DaprWorkflowClient. This layer constructs the GRPC Channel. -
DaprWorkflowClient
Public constructor for DaprWorkflowClient. This layer constructs the GRPC Channel.- Parameters:
properties- Properties for the GRPC Channel.
-
DaprWorkflowClient
public DaprWorkflowClient(Properties properties, @Nullable io.opentelemetry.api.trace.Tracer tracer) Public constructor for DaprWorkflowClient. This layer constructs the GRPC Channel.When a
Traceris provided, scheduling a workflow emits a client span as a child of the caller's current OpenTelemetry context and propagates that trace context to the Dapr sidecar, so the workflow execution is recorded as part of the caller's trace.- Parameters:
properties- Properties for the GRPC Channel.tracer- OpenTelemetry Tracer used to emit and propagate trace context when scheduling workflows. May be null, in which case tracing is disabled and this constructor behaves exactly likeDaprWorkflowClient(Properties).
-
DaprWorkflowClient
protected DaprWorkflowClient(Properties properties, io.grpc.ClientInterceptor... additionalInterceptors) Protected constructor for DaprWorkflowClient that allows subclasses to inject additional gRPCClientInterceptors onto the channel (e.g. for tracing). TheApiTokenClientInterceptoris always prepended before the additional ones.- Parameters:
properties- Properties for the GRPC Channel.additionalInterceptors- extra interceptors appended after the API-token interceptor.
-
-
Method Details
-
scheduleNewWorkflow
Schedules a new workflow using DurableTask client.- Type Parameters:
T- any Workflow type- Parameters:
clazz- Class extending Workflow to start an instance of.- Returns:
- the randomly-generated instance ID for new Workflow instance.
-
scheduleNewWorkflow
Schedules a new workflow using DurableTask client.- Type Parameters:
T- any Workflow type- Parameters:
name- Workflow name- Returns:
- the randomly-generated instance ID for new Workflow instance.
-
scheduleNewWorkflow
Schedules a new workflow using DurableTask client.- Type Parameters:
T- any Workflow type- Parameters:
clazz- Class extending Workflow to start an instance of.input- the input to pass to the scheduled orchestration instance. Must be serializable.- Returns:
- the randomly-generated instance ID for new Workflow instance.
-
scheduleNewWorkflow
Schedules a new workflow using DurableTask client.- Type Parameters:
T- any Workflow type- Parameters:
name- Workflow nameinput- the input to pass to the scheduled orchestration instance. Must be serializable.- Returns:
- the randomly-generated instance ID for new Workflow instance.
-
scheduleNewWorkflow
public <T extends Workflow> String scheduleNewWorkflow(Class<T> clazz, Object input, String instanceId) Schedules a new workflow using DurableTask client.- Type Parameters:
T- any Workflow type- Parameters:
clazz- Class extending Workflow to start an instance of.input- the input to pass to the scheduled orchestration instance. Must be serializable.instanceId- the unique ID of the orchestration instance to schedule- Returns:
- the
instanceIdparameter value. - Throws:
WorkflowInstanceAlreadyExistsException- if an active workflow withinstanceIdalready exists.
-
scheduleNewWorkflow
public <T extends Workflow> String scheduleNewWorkflow(String name, Object input, String instanceId) Schedules a new workflow using DurableTask client.- Type Parameters:
T- any Workflow type- Parameters:
name- Workflow nameinput- the input to pass to the scheduled orchestration instance. Must be serializable.instanceId- the unique ID of the orchestration instance to schedule- Returns:
- the
instanceIdparameter value. - Throws:
WorkflowInstanceAlreadyExistsException- if an active workflow withinstanceIdalready exists.
-
scheduleNewWorkflow
Schedules a new workflow with a specified set of options for execution.- Type Parameters:
T- any Workflow type- Parameters:
clazz- Class extending Workflow to start an instance of.options- the options for the new workflow, including input, instance ID, etc.- Returns:
- the
instanceIdparameter value. - Throws:
WorkflowInstanceAlreadyExistsException- if an active workflow with the requested instance ID already exists.
-
scheduleNewWorkflow
Schedules a new workflow with a specified set of options for execution.- Type Parameters:
T- any Workflow type- Parameters:
name- name of the workflow to scheduleoptions- the options for the new workflow, including input, instance ID, etc.- Returns:
- the
instanceIdparameter value. - Throws:
WorkflowInstanceAlreadyExistsException- if an active workflow with the requested instance ID already exists.
-
suspendWorkflow
Suspend the workflow associated with the provided instance id.- Parameters:
workflowInstanceId- Workflow instance id to suspend.reason- reason for suspending the workflow instance.
-
suspendWorkflow
public void suspendWorkflow(String workflowInstanceId, @Nullable String reason, @Nullable String appId) Suspend the workflow associated with the provided instance id, owned by another app.Permission to operate on workflows owned by another app is governed by the target app's WorkflowAccessPolicy.
Requires a Dapr runtime with cross-app workflow support; against an older runtime the target app ID is ignored and the operation applies to the local app instead.
- Parameters:
workflowInstanceId- Workflow instance id to suspend.reason- reason for suspending the workflow instance.appId- ID of the app that owns the workflow instance. May be null to target the local app.
-
resumeWorkflow
Resume the workflow associated with the provided instance id.- Parameters:
workflowInstanceId- Workflow instance id to resume.reason- reason for resuming the workflow instance.
-
resumeWorkflow
public void resumeWorkflow(String workflowInstanceId, @Nullable String reason, @Nullable String appId) Resume the workflow associated with the provided instance id, owned by another app.Permission to operate on workflows owned by another app is governed by the target app's WorkflowAccessPolicy.
Requires a Dapr runtime with cross-app workflow support; against an older runtime the target app ID is ignored and the operation applies to the local app instead.
- Parameters:
workflowInstanceId- Workflow instance id to resume.reason- reason for resuming the workflow instance.appId- ID of the app that owns the workflow instance. May be null to target the local app.
-
terminateWorkflow
Terminates the workflow associated with the provided instance id.- Parameters:
workflowInstanceId- Workflow instance id to terminate.output- the optional output to set for the terminated orchestration instance.
-
terminateWorkflow
public void terminateWorkflow(String workflowInstanceId, @Nullable Object output, @Nullable String appId) Terminates the workflow associated with the provided instance id, owned by another app.Permission to operate on workflows owned by another app is governed by the target app's WorkflowAccessPolicy.
Requires a Dapr runtime with cross-app workflow support; against an older runtime the target app ID is ignored and the operation applies to the local app instead.
- Parameters:
workflowInstanceId- Workflow instance id to terminate.output- the optional output to set for the terminated orchestration instance.appId- ID of the app that owns the workflow instance. May be null to target the local app.
-
getInstanceState
@Nullable @Deprecated(forRemoval=true) public WorkflowInstanceStatus getInstanceState(String instanceId, boolean getInputsAndOutputs) Deprecated, for removal: This API element is subject to removal in a future version.UsegetWorkflowState(String, boolean)instead.Fetches workflow instance metadata from the configured durable store.- Parameters:
instanceId- the unique ID of the workflow instance to fetchgetInputsAndOutputs-trueto fetch the workflow instance's inputs, outputs, and custom status, orfalseto omit them- Returns:
- a metadata record that describes the workflow instance and it execution status, or a default instance
-
getWorkflowState
Fetches workflow instance metadata from the configured durable store.- Parameters:
instanceId- the unique ID of the workflow instance to fetchgetInputsAndOutputs-trueto fetch the workflow instance's inputs, outputs, and custom status, orfalseto omit them- Returns:
- a metadata record that describes the workflow instance and it execution status, or a default instance
-
getWorkflowState
@Nullable public WorkflowState getWorkflowState(String instanceId, boolean getInputsAndOutputs, @Nullable String appId) Fetches workflow instance metadata from the durable store of another app.Permission to operate on workflows owned by another app is governed by the target app's WorkflowAccessPolicy.
Requires a Dapr runtime with cross-app workflow support; against an older runtime the target app ID is ignored and the operation applies to the local app instead.
- Parameters:
instanceId- the unique ID of the workflow instance to fetchgetInputsAndOutputs-trueto fetch the workflow instance's inputs, outputs, and custom status, orfalseto omit themappId- ID of the app that owns the workflow instance. May be null to target the local app.- Returns:
- a metadata record that describes the workflow instance and its execution status, or a default instance
when no such instance is found, matching
getWorkflowState(String, boolean). Null only when the underlying client returns no metadata at all.
-
waitForInstanceStart
@Deprecated(forRemoval=true) @Nullable public WorkflowInstanceStatus waitForInstanceStart(String instanceId, Duration timeout, boolean getInputsAndOutputs) throws TimeoutException Deprecated, for removal: This API element is subject to removal in a future version.UsewaitForWorkflowStart(String, Duration, boolean)instead.Waits for an workflow to start running and returns anWorkflowInstanceStatusobject that contains metadata about the started instance and optionally its input, output, and custom status payloads.A "started" workflow instance is any instance not in the Pending state.
If an workflow instance is already running when this method is called, the method will return immediately.
- Parameters:
instanceId- the unique ID of the workflow instance to wait fortimeout- the amount of time to wait for the workflow instance to startgetInputsAndOutputs- true to fetch the workflow instance's inputs, outputs, and custom status, or false to omit them- Returns:
- the workflow instance metadata or null if no such instance is found
- Throws:
TimeoutException- when the workflow instance is not started within the specified amount of time
-
waitForWorkflowStart
@Nullable public WorkflowState waitForWorkflowStart(String instanceId, Duration timeout, boolean getInputsAndOutputs) throws TimeoutException Waits for a workflow to start running and returns anWorkflowStateobject that contains metadata about the started instance and optionally its input, output, and custom status payloads.A "started" workflow instance is any instance not in the Pending state.
If an workflow instance is already running when this method is called, the method will return immediately.
- Parameters:
instanceId- the unique ID of the workflow instance to wait fortimeout- the amount of time to wait for the workflow instance to startgetInputsAndOutputs- true to fetch the workflow instance's inputs, outputs, and custom status, or false to omit them- Returns:
- the workflow instance metadata or null if no such instance is found
- Throws:
TimeoutException- when the workflow instance is not started within the specified amount of time
-
waitForWorkflowStart
@Nullable public WorkflowState waitForWorkflowStart(String instanceId, Duration timeout, boolean getInputsAndOutputs, @Nullable String appId) throws TimeoutException Waits for a workflow owned by another app to start running.See
waitForWorkflowStart(String, Duration, boolean)for the wait semantics. Permission to operate on workflows owned by another app is governed by the target app's WorkflowAccessPolicy.Requires a Dapr runtime with cross-app workflow support; against an older runtime the target app ID is ignored and the operation applies to the local app instead.
- Parameters:
instanceId- the unique ID of the workflow instance to wait fortimeout- the amount of time to wait for the workflow instance to startgetInputsAndOutputs- true to fetch the workflow instance's inputs, outputs, and custom status, or false to omit themappId- ID of the app that owns the workflow instance. May be null to target the local app.- Returns:
- the workflow instance metadata or null if no such instance is found
- Throws:
TimeoutException- when the workflow instance is not started within the specified amount of time
-
waitForInstanceCompletion
@Nullable @Deprecated(forRemoval=true) public WorkflowInstanceStatus waitForInstanceCompletion(String instanceId, Duration timeout, boolean getInputsAndOutputs) throws TimeoutException Deprecated, for removal: This API element is subject to removal in a future version.UsewaitForWorkflowCompletion(String, Duration, boolean)instead.Waits for an workflow to complete and returns anWorkflowInstanceStatusobject that contains metadata about the completed instance.A "completed" workflow instance is any instance in one of the terminal states. For example, the Completed, Failed, or Terminated states.
Workflows are long-running and could take hours, days, or months before completing. Workflows can also be eternal, in which case they'll never complete unless terminated. In such cases, this call may block indefinitely, so care must be taken to ensure appropriate timeouts are used. If an workflow instance is already complete when this method is called, the method will return immediately.
- Parameters:
instanceId- the unique ID of the workflow instance to wait fortimeout- the amount of time to wait for the workflow instance to completegetInputsAndOutputs- true to fetch the workflow instance's inputs, outputs, and custom status, or false to omit them- Returns:
- the workflow instance metadata or null if no such instance is found
- Throws:
TimeoutException- when the workflow instance is not completed within the specified amount of time
-
waitForWorkflowCompletion
@Nullable public WorkflowState waitForWorkflowCompletion(String instanceId, Duration timeout, boolean getInputsAndOutputs) throws TimeoutException Waits for an workflow to complete and returns anWorkflowStateobject that contains metadata about the completed instance.A "completed" workflow instance is any instance in one of the terminal states. For example, the Completed, Failed, or Terminated states.
Workflows are long-running and could take hours, days, or months before completing. Workflows can also be eternal, in which case they'll never complete unless terminated. In such cases, this call may block indefinitely, so care must be taken to ensure appropriate timeouts are used. If an workflow instance is already complete when this method is called, the method will return immediately.
- Parameters:
instanceId- the unique ID of the workflow instance to wait fortimeout- the amount of time to wait for the workflow instance to completegetInputsAndOutputs- true to fetch the workflow instance's inputs, outputs, and custom status, or false to omit them- Returns:
- the workflow instance metadata or null if no such instance is found
- Throws:
TimeoutException- when the workflow instance is not completed within the specified amount of time
-
waitForWorkflowCompletion
@Nullable public WorkflowState waitForWorkflowCompletion(String instanceId, Duration timeout, boolean getInputsAndOutputs, @Nullable String appId) throws TimeoutException Waits for a workflow owned by another app to complete.See
waitForWorkflowCompletion(String, Duration, boolean)for the wait semantics. Permission to operate on workflows owned by another app is governed by the target app's WorkflowAccessPolicy.Requires a Dapr runtime with cross-app workflow support; against an older runtime the target app ID is ignored and the operation applies to the local app instead.
- Parameters:
instanceId- the unique ID of the workflow instance to wait fortimeout- the amount of time to wait for the workflow instance to completegetInputsAndOutputs- true to fetch the workflow instance's inputs, outputs, and custom status, or false to omit themappId- ID of the app that owns the workflow instance. May be null to target the local app.- Returns:
- the workflow instance metadata or null if no such instance is found
- Throws:
TimeoutException- when the workflow instance is not completed within the specified amount of time
-
raiseEvent
Sends an event notification message to awaiting workflow instance.- Parameters:
workflowInstanceId- The ID of the workflow instance that will handle the event.eventName- The name of the event. Event names are case-insensitive.eventPayload- The serializable data payload to include with the event.
-
raiseEvent
public void raiseEvent(String workflowInstanceId, String eventName, Object eventPayload, @Nullable String appId) Sends an event notification message to a waiting workflow instance owned by another app.Permission to operate on workflows owned by another app is governed by the target app's WorkflowAccessPolicy.
Requires a Dapr runtime with cross-app workflow support; against an older runtime the target app ID is ignored and the operation applies to the local app instead.
- Parameters:
workflowInstanceId- The ID of the workflow instance that will handle the event.eventName- The name of the event. Event names are case-insensitive.eventPayload- The serializable data payload to include with the event.appId- ID of the app that owns the workflow instance. May be null to target the local app.
-
purgeInstance
Deprecated, for removal: This API element is subject to removal in a future version.UsepurgeWorkflow(String)instead.Purges workflow instance state from the workflow state store.- Parameters:
workflowInstanceId- The unique ID of the workflow instance to purge.- Returns:
- Return true if the workflow state was found and purged successfully otherwise false.
-
listInstanceIds
Lists workflow instance IDs. Returns the first page with no size limit.- Returns:
- a page of workflow instance IDs
-
listInstanceIds
public WorkflowInstancePage listInstanceIds(@Nullable String continuationToken, @Nullable Integer pageSize) Lists workflow instance IDs with pagination.- Parameters:
continuationToken- the continuation token from a previous call, or null for the first pagepageSize- the maximum number of instance IDs to return, or null for no limit; must be greater than zero when set- Returns:
- a page of workflow instance IDs and an optional continuation token for the next page
-
getInstanceHistory
Gets the full execution history of a workflow instance.- Parameters:
instanceId- the unique ID of the workflow instance to get history for- Returns:
- the list of history events for the workflow instance
-
rerunWorkflowFromEvent
Reruns a workflow from a history event, creating a new workflow instance.- Parameters:
sourceInstanceId- the ID of the source workflow instance to rerun fromeventId- the history event ID to rerun from; must not be negative- Returns:
- the instance ID of the new workflow instance
- Throws:
IllegalArgumentException- if sourceInstanceId is null or empty, or eventId is negative
-
rerunWorkflowFromEvent
public String rerunWorkflowFromEvent(String sourceInstanceId, int eventId, @Nullable RerunWorkflowFromEventOptions options) Reruns a workflow from a history event with options, creating a new workflow instance.- Parameters:
sourceInstanceId- the ID of the source workflow instance to rerun fromeventId- the history event ID to rerun from; must not be negativeoptions- optional rerun configuration; may be null- Returns:
- the instance ID of the new workflow instance
- Throws:
IllegalArgumentException- if sourceInstanceId is null or empty, if eventId is negative, or if input is set on options without overwriteInput being true
-
purgeWorkflow
Purges workflow instance state from the workflow state store of another app.Permission to operate on workflows owned by another app is governed by the target app's WorkflowAccessPolicy.
Requires a Dapr runtime with cross-app workflow support; against an older runtime the target app ID is ignored and the operation applies to the local app instead.
- Parameters:
workflowInstanceId- The unique ID of the workflow instance to purge.appId- ID of the app that owns the workflow instance. May be null to target the local app.- Returns:
- Return true if the workflow state was found and purged successfully otherwise false.
-
purgeWorkflow
Purges workflow instance state from the workflow state store.- Parameters:
workflowInstanceId- The unique ID of the workflow instance to purge.- Returns:
- Return true if the workflow state was found and purged successfully otherwise false.
-
close
Closes the inner DurableTask client and shutdown the GRPC channel.- Specified by:
closein interfaceAutoCloseable- Throws:
InterruptedException
-
getWorkflowState(String, boolean)instead.