Is it possible to write a workflow in temporal where some activities are written in Java while others in Golang?
I am initiating the workflow in Java code, workflow code itself is written using Java SDK, however workflow activities are written in Golang. Is there an example that illustrates a similar setup ?
We definitely need to write such a sample. In the meantime, you have to do it yourself.
- Make sure that both Java and Go workers share the same domain (this is not a hard requirement, but simplifies things).
- Make sure that Go and Java workers are using different task queue names to route tasks appropriately.
- You can either create Java activities interface that mirrors Go activities signatures or use non strongly typed ActivityStub interface to invoke them directly by name.
- When initializing activity stub pass Go task queue name to it as an option.
Something like:
ActivityOptions options =
ActivityOptions.newBuilder()
.setTaskQueue(GO_ACTIVITIES)
.setStartToCloseTimeout(Duration.ofSeconds(20))
.build();
ActivityStub goActivities = Workflow.newUntypedActivityStub(options);
String result = goActivities.execute("MyGoActivity1", String.class, arg1, arg2);
Is this the same if the workflow starter is in Java and the workflow itself is in Go? Suppose I have a workflow in a Go function with signature func Deploy(ctx workflow.Context, customer string)
, how should the Workflow interface look in Java? Does casing matter?
The Java uses the workflow interface short name as the workflow name. So in Java you need to have something like:
@WorkflowInterface
public interface Deploy {
// whatever
}
I’m puzzled. You map the Go function name to the Java interface name?
Then which method should be added to the interface to map the same set of arguments?
Yes, the Go function name is mapped to the Java interface name for workflows.
The method annotated with @WorkflowMethod should have the matching arguments. The name of the method doesn’t matter.
This is a pattern that we can expect to work with future releases of temporal ?
Yes, we don’t plan to do any changes that would break running workflows.