Cancel Workflow Via API

Hi all, I’m new to Temporal and working with the Java SDK to implement signals and querying into our existing workflows. To put it simply, I am looking for a way to use a string to query a workflow ID and then use that workflow object to send signals/queries/etc. Is there any way to do this using the Java SDK? The docs don’t seem to mention anything about working with workflows in the SDK after they are instantiated.

I would recommend using your business identifier as a workflow ID. Then you don’t need to perform any lookups to perform operations on the workflows by their business id. In Java SDK you assign workflow id through WorkflowOptions:

    WorkflowOptions workflowOptions =
        WorkflowOptions.newBuilder().setTaskQueue(TASK_QUEUE).setWorkflowId("BusinessId").build();
    GreetingWorkflow workflow = client.newWorkflowStub(GreetingWorkflow.class, workflowOptions);

Thanks for the reply, this could possibly help but I am wondering how one would look up a workflow from within the SDK. Is it only possible to send signals/queries from the command line? Or is there a way to use the SDK to get existing workflows?

Both UI and CLI use the same gRPC API SDKs use. So everything is possible through them is possible through SDKs.

Here are signal and query Java samples.

I am wondering how one would look up a workflow from within the SDK.

As I mentioned the best way is by using the workflow id that you assigned. The other option is to use list APIs:

WorkflowServiceStubs service = WorkflowServiceStubs.newInstance(options);
service.blockingStub().listWorkflowExecutions(...);

Thanks for your help! This should be perfect