The parent workflow has a @QueryMethod and when start the child workflow, pass it the id
public static class ParentWorkflowImpl implements ParentWorkflow {
@Override
public void start() {
ChildWorkflow child1 = Workflow.newChildWorkflowStub(ChildWorkflow.class);
Async.procedure(child1::start, Workflow.getInfo().getWorkflowId());
Workflow.sleep(Duration.ofHours(1));
}
@Override
public int query() {
return 30;
}
}
When try to use the @QueryMethod from the child workflow like this
public static class ChildWorkflowImpl implements ChildWorkflow {
@Override
public void start(String parentWorkflowId) {
ParentWorkflow parentWorkflow = Workflow.newExternalWorkflowStub(ParentWorkflow.class, parentWorkflowId);
System.out.println(parentWorkflow.query());
}
}
I got error: Query is not supported from workflow to workflow. Use activity that perform the query instead.
So I tried this
public static class QueryActivityImpl implements QueryActivity {
@Override
public int query(String parentWorkflowId) {
ParentWorkflow parentWorkflow = Workflow.newExternalWorkflowStub(ParentWorkflow.class, parentWorkflowId);
return parentWorkflow.query();
}
}
public static class ChildWorkflowImpl implements ChildWorkflow {
private final ActivityOptions options = ActivityOptions.newBuilder().setStartToCloseTimeout(Duration.ofSeconds(120)).build();
private final QueryActivity act = Workflow.newActivityStub(QueryActivity.class, options);
@Override
public void start(String parentWorkflowId) {
System.out.println(act.query(parentWorkflowId));
}
}
Then I got the error: Called from non workflow or workflow callback thread
So is it not allowed to query parent workflow from child? If it is allowed, how do I do that?
Thank you very much!