What is the recommended way to send a signal from a Workflow?

I have written workflow A with a signal and query. I want to send a signal from workflow B and workflow C.

On signal calling an external API will take 10 min to complete. once API complete I am adding result to map with key, using query reading the result from the map

looks working but while query getting DEADLINE_EXCEEDED error message with retry is working.

What is the recommended way to send a signal and query from a Workflow?

Java

From workflow code:

      WorkflowToSignal stub =
          Workflow.newExternalWorkflowStub(WorkflowToSignal.class, workflowId);
      stub.signalMethod(arg);

Go

From workflow code:

	SignalExternalWorkflow(ctx, workflowId, "", signalName, arg).Get(ctx, nil)

Thanks, On the same who to query from a workflow?

No, query from a workflow is not supported. In the majority of cases it is a bad idea. Use a reply signal instead.

Any example on reply signal, Will be help full

It uses the same APIs. Include the originator workflowId and runId into the request signal and let the receiver workflow reply using the passed Ids.

1 Like

Thank you for the clarification it worked!

In workflow code how can we use this? When I started implementing the workflow I couldn’t found the suggestion for this class. Need I to create the separate class for the WorkflowToSignal? In the Java sdk

WorkflowToSignal stub =
Workflow.newExternalWorkflowStub(WorkflowToSignal.class, workflowId);
stub.signalMethod(arg);

On the receiving workflow side, you can either add the signal method to the receiving workflow interface or create a separate interface and register it through Workflow.registerListener.

How can I call from one Workflow to another workflow?

Consider a case if I have Workflow A and Workflow B. How can I call Workflow B from Workflow A?

Use an external stub:

B b = Workflow.newExternalWorkflowStub(B.class, "BId");
b.signalMethod(...);

where to use the external stub in Workflow A or Workflow B?

From the calling workflow which is A in your case.

How can be the signal passed from Workflow B to workflow A?

B b = Workflow.newExternalWorkflowStub(B.class, “BId”);
b.signalMethod(…);

If I implemented, the b.signalMethod( ) cannot be invoked.

During the running process, the error has come stating that called from non Workflow or Workflow callback thread.

How can be the signal passed from Workflow B to workflow A?

A A = Workflow.newExternalWorkflowStub(A.class, “AId”);
a.signalMethodOfA(…);

What is the use of the signalMethod( ) in temporal?
Can you give me the explanation for it?
Because I am new to temporal. So I need to understand about it.

Signals can be used to deliver external data/messages to running workflows. One common use case is when a workflow needs to wait for an external event (for example a human decision) in order to proceed execution. Another use case is when you want to start a workflow execution upon arrival of an external signal/message/event.
Check out this sample in our samples-java repo.

Can you demonstrate with a complete example, that the Signal passing from one workflow to another.

You can see this in action in the polyglot sample app.

The app shows how to send signals with different Temporal SDKs (Java, Go, PHP, and NodeJS).

Here is the specific code of the workflow written in Java sending signals to a workflow written in Go, but the same code can be used to signal a workflow that is written using any of the Temporal SDKs.

Hope this helps.