How to Direct Signals to Specific Workflow Execution?

Given that I initiated a workflow execution with workflowId 111, and later I started another workflow execution with workflowId 222 (workflow 111 is still running). Now, when I attempt to send a signal to workflow 111, the signal gets sent to the latest workflow execution, which is workflow 222. How can I address this issue? In other words, how can I specify the workflow ID to which I intend to send a signal?
I am using Temporal with Spring Boot.

Update: I have discovered a potential solution to this issue. Here is the code:

DemoWorkflow workflow = workflowClient.newWorkflowStub(DemoWorkflow.class, workflowId); // workflowClient is an injected spring bean
workflow.sendSignal();

I’m curious to know if this approach is recommended. Additionally, when using the newWorkflowStub method, does it create a new instance of the workflow stub object each time, or is it like getWorkflowStub in terms of object creation?

Hi @MedGr

newWorkflowStub creates a proxy that allows you to interact with the workflow execution

Is signaling the workflow execution working for you now?

Antonio

Hi @antonio.perez,

Thank you for your prompt response.

Yes, the signal is functioning as expected now. However, I’m still curious to know if this approach is the recommended method or if there’s a simpler way to achieve the same outcome.

Regarding the newWorkflowStub function, I’m wondering if it generates a new proxy instance or simply retrieves an existing one. If it creates new instances, I’m wondering if this could have any implications for memory performance.

Your insights are greatly appreciated!