Can Java activity be invoked by typescript workflow?

Hi,
I saw this repo with some good examples about polyglot:
temporalio/temporal-polyglot (github.com)
But didn’t find my answer there.

I’m using a typescript-sdk and other team is using java-sdk,
I need somehow to call theirs activity.
is it a valid approach?
Can it be done?

Thanks :slight_smile:

Hello @Artur

You need to create an interface in your ts project that contains the activity/ies, and use proxyActivity to set up your activity.

interface MyActivities {
  greet(name: string): Promise<string>;
}

const { greet } = proxyActivities<MyActivities>({
  taskQueue: "java-taskQueue"
});

export async function example(name: string): Promise<string> {
  return await greet(name); 
}

Then from Java, create the activity interface and implementation and register it in the worker listening in the appropriate taskqueue (“java-taskQueue” for this example)

  @ActivityInterface
  public interface GreetingActivities {
    @ActivityMethod(name = "greet") //you may need to set the activity name to be the same as your ts activity 
    String composeGreeting(String greeting);
  }

Let me know if it works.

2 Likes

@antonio.perez
Wanted to say - thank you, it works!