What is
A Query is used to access the state of a Workflow without impacting its execution.
Query Interface
@WorkflowInterface
public interface MyWorkflow {
@WorkflowMethod
String workflow(String input);
@QueryMethod
String queryStatus(/arguments/);
}
Define a method that will declare the Query Type and its return value. Annotate the method with @QueryMethod
Query Handler
Implementation of the method annotated with @QueryMethod
public class MyWorkflowImpl implements MyWorkflow {
private String status;
// Workflow code omitted for brevity
public String queryStatus(/arguments/) {
return this.status;
}
}
This example sets up a handler for the queryStatus() method we defined earlier. When this Query is invoked, it retrieves the value of the status which is stored in an instance variable.
Query Constraints
Query cannot include any logic that causes Command generation (such as executing Activities). Queries are intended to be read-only operations that do not alter the Workflow’s state. Including such logic causes unexpected behavior.