Executing workflows remotely

Hello,

I am new to using Temporal, so my apologies if I have a fundamental misunderstanding here.

I have a workflow written using the Java SDK which performs some orchestration between APIs A, B & C. I have a need for this workflow to be executed on schedule, which Temporal clearly supports. However I also need to execute this workflow on demand when API D receives a particular HTTP request. Ideally my Temporal workflow / worker would be completely decoupled from these APIs. Assuming API D is also written in Java, could you advise on how would I invoke this workflow remotely (Ideally decoupling API D from Temporal as much as possible)?

I found the following example in the documentation https://github.com/tsurdilo/temporal-polyglot, but this appears to require a parent workflow to be constructed before another workflow can be executed.

Many thanks

Workflow can be started/signaled/queried from any process using WorkflowClient. See TransferRequester sample.

Hi Maxim,

Thanks for the quick response.

In the code example you linked, the process that executes the workflow is able to resolve the object AccountTransferWorkflow. In my above example, API D would not have a copy of this object. I suppose fundamentally my question is: is it possible for workflows to be centrally stored and remotely executed, or does every process that wishes to start the workflow need a copy of the workflow code?

It’s not a requirement. You can use the “newUntypedWorkflowStub” methods for either a new or existing execution → WorkflowClient - temporal-sdk 1.0.9 javadoc

I’m finding it difficult to piece this functionality together from the JavaDocs alone, is there an existing code example that you could point me to? The WorkflowClient’s start method requires a function call as a mandatory parameter, but in my case that function cannot be resolved. Is there another object or method which I should be using to invoke this?

For examples you can look at:

This code uses “newUntypedWorkflowStub” to query an existing workflow execution by its workflowid and optional runtid. Once you have the WorkflowStub you can also call the “start” and “signalWithStart” methods instead of the “query” one shown in the example.

Another example you could look at is here: temporal-polyglot/SimpleWorkflowImpl.java at main · tsurdilo/temporal-polyglot · GitHub
There you can see the use of “newUntypedExternalWorkflowStub” where you need only the workflow type (string) to signal and/or cancel an external workflow, as well as the use of “newUntypedActivityStub” to invoke external activities.

Another good place to look for examples are the numerous unit tests in our Java SDK - GitHub - temporalio/sdk-java: Temporal Java SDK

Hope this helps.

That’s very helpful, thanks :slightly_smiling_face: