Search code examples
cadence-workflowuber-cadence

Understanding Signal and Query in cadence


Query - Query is to expose this internal state to the external world. A query is exposed as an asynchronous callback that is invoked by external entities.

What do you mean by asynchronous callback?

And Doc says, Query has two limitations 1). Should not mutate the state of a Workflow 2). There won't be any blocking operation.

@Override
    public String queryGreeting() {
      greeting = "val";
      return greeting;
    }

But I did mutate the variable in the query method and It is changing the value.

Is it just a conviction that we should not write mutable or blocking code inside query method?

I didn't see any difference between query and signal. A query method will be called even after the completion of a workflow where as Signal won't?

Is my understanding correct?


Solution

  • The query should not mutate workflow variables. This is going to break workflow recovery.

    The signal can mutate any workflow data as well as invoke blocking operations like activities.