Class DaprWorkflowClient

java.lang.Object
io.dapr.workflows.client.DaprWorkflowClient
All Implemented Interfaces:
AutoCloseable

public class DaprWorkflowClient extends Object implements AutoCloseable
Defines client operations for managing Dapr Workflow instances.
  • Constructor Details

    • DaprWorkflowClient

      public DaprWorkflowClient()
      Public constructor for DaprWorkflowClient. This layer constructs the GRPC Channel.
  • Method Details

    • scheduleNewWorkflow

      public <T extends Workflow> String scheduleNewWorkflow(Class<T> clazz)
      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

      public <T extends Workflow> String scheduleNewWorkflow(Class<T> clazz, Object input)
      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

      public <T extends Workflow> String scheduleNewWorkflow(Class<T> clazz, NewWorkflowOption options)
      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

      public void terminateWorkflow(String workflowInstanceId, @Nullable Object output)
      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 fetch
      getInputsAndOutputs - true to fetch the workflow instance's inputs, outputs, and custom status, or false 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 an WorkflowInstanceStatus 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 for
      timeout - the amount of time to wait for the workflow instance to start
      getInputsAndOutputs - 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 an WorkflowInstanceStatus 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 for
      timeout - the amount of time to wait for the workflow instance to complete
      getInputsAndOutputs - 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

      public void raiseEvent(String workflowInstanceId, String eventName, Object eventPayload)
      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

      public boolean purgeInstance(String workflowInstanceId)
      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

      public void close() throws InterruptedException
      Closes the inner DurableTask client and shutdown the GRPC channel.
      Specified by:
      close in interface AutoCloseable
      Throws:
      InterruptedException