Package io.dapr.workflows.client
Class DaprWorkflowClient
java.lang.Object
io.dapr.workflows.client.DaprWorkflowClient
- All Implemented Interfaces:
AutoCloseable
Defines client operations for managing Dapr Workflow instances.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes the inner DurableTask client and shutdown the GRPC channel.void
createTaskHub
(boolean recreateIfExists) void
getInstanceState
(String instanceId, boolean getInputsAndOutputs) Fetches workflow instance metadata from the configured durable store.boolean
purgeInstance
(String workflowInstanceId) Purges workflow instance state from the workflow state store.void
raiseEvent
(String workflowInstanceId, String eventName, Object eventPayload) Sends an event notification message to awaiting workflow instance.scheduleNewWorkflow
(Class<T> clazz) Schedules a new workflow using DurableTask client.scheduleNewWorkflow
(Class<T> clazz, NewWorkflowOption 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.void
terminateWorkflow
(String workflowInstanceId, Object output) Terminates the workflow associated with the provided instance id.waitForInstanceCompletion
(String instanceId, Duration timeout, boolean getInputsAndOutputs) Waits for an workflow to complete and returns anWorkflowInstanceStatus
object that contains metadata about the completed instance.waitForInstanceStart
(String instanceId, Duration timeout, boolean getInputsAndOutputs) Waits for an workflow to start running and returns anWorkflowInstanceStatus
object that contains metadata about the started instance and optionally its input, output, and custom status payloads.
-
Constructor Details
-
DaprWorkflowClient
public DaprWorkflowClient()Public constructor for DaprWorkflowClient. This layer constructs the GRPC Channel.
-
-
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:
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
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
instanceId
parameter value.
-
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
instanceId
parameter value.
-
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.
-
getInstanceState
@Nullable public WorkflowInstanceStatus getInstanceState(String instanceId, boolean getInputsAndOutputs) Fetches workflow instance metadata from the configured durable store.- Parameters:
instanceId
- the unique ID of the workflow instance to fetchgetInputsAndOutputs
-true
to fetch the workflow instance's inputs, outputs, and custom status, orfalse
to omit them- Returns:
- a metadata record that describes the workflow instance and it execution status, or a default instance
-
waitForInstanceStart
@Nullable public WorkflowInstanceStatus waitForInstanceStart(String instanceId, Duration timeout, boolean getInputsAndOutputs) throws TimeoutException Waits for an workflow to start running and returns anWorkflowInstanceStatus
object 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
-
waitForInstanceCompletion
@Nullable public WorkflowInstanceStatus waitForInstanceCompletion(String instanceId, Duration timeout, boolean getInputsAndOutputs) throws TimeoutException Waits for an workflow to complete and returns anWorkflowInstanceStatus
object 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
-
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.
-
purgeInstance
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.
-
createTaskHub
public void createTaskHub(boolean recreateIfExists) -
deleteTaskHub
public void deleteTaskHub() -
close
Closes the inner DurableTask client and shutdown the GRPC channel.- Specified by:
close
in interfaceAutoCloseable
- Throws:
InterruptedException
-