Reusable components

I am wanting to have some reusable components (workflows/activities) for example have a workflow to raise a request in a request system, but I want to make it available to other workflows that will not be in the same application.
so I have the following questions:

  • Can I call a child workflow that has the worker running from another application to the client?
  • Can I call an activity that is attached to a worker of another application to the client?
  • Which is better assuming I can do either, child workflow or activity?

thank you

Hello @hendryt

  • Can I call a child workflow that has the worker running from another application to the client?

Yes, if the worker is different, ensure you set a different taskqueue for the childworkflow and have a worker listening to the taskqueue with the childWorkflow implementation.

If you don’t have access to the ChildWorklfow interface, you can create a UntypedChildWorkflowStub, see this example https://github.com/tsurdilo/temporal-java-workshop/blob/b3f1d8e93238e0cb490cb24d681e482864653af5/src/main/java/io/workshop/c3s2/C3S2WorkflowImpl.java#L25

  • Can I call an activity that is attached to a worker of another application to the client?

Same as above.

If you don’t have access to the activity interface you can do


    private final ActivityStub activity =
        Workflow.newUntypedActivityStub(
            ActivityOptions.newBuilder().....build());


activity.execute(...)
//or

activity.executeAsync(...)

  • Which is better assuming I can do either, child workflow or activity?

What is your use case? what those childworkflows/activities have to do?

Just wanted to ask, i think you mean worker that polls on a separate task queues, right ? (you can have two workers each in different worker processes/apps that poll on same task queue as well, both would need to have all workflows and activities registered tho).

  • Which is better assuming I can do either, child workflow or activity?

If all the ChildWorklfow would do is invoke the activity (so no other business logic) and you dont need to set specific activity configs (so letting activity config being set in workflow is ok), then think you should invoke the activity directly.

This is a diagram of what I am trying to do.

You can implement this by using different task queue for each “system” workflow. Then when you have to specify the correct task queue name when creating the child workflow stub. For example:

      RequestSystemWorkflow requestSystem =
          Workflow.newChildWorkflowStub(
              RequestSystemWorkflow.class,
              ChildWorkflowOptions.newBuilder().setTaskQueue("request-system").build());