简体   繁体   中英

SWF: How can I signal the parent workflow from the child workflow?

I'm trying to signal my parent workflow to update its state variable. The parent workflow id is passed to the child workflow's execute method.

@Autowired
private AmazonSimpleWorkflowClient swfClient;
@Autowired
private String swfDomain;

private ParentWorkflowClientExternalFactory clientExternalFactory = new ParentWorkflowClientExternalFactoryImpl(swfClient, swfDomain);

@Override
public Promise<String> childActivityMethod(String parentWorkflowId) {
    ParentWorkflowClientExternal clientExternal = clientExternalFactory.getClient(parentWorkflowId);
    clientExternal.updateState(...);
}

However, this throws a NullPointerException in SWF code (AmazonSimpleWorkflow is null):

["java.lang.NullPointerException",{"cause":null,"stackTrace":[{"methodName":"signalWorkflowExecution","fileName":"GenericWorkflowClientExternalImpl.java","lineNumber":87,"className":"com.amazonaws.services.simpleworkflow.flow.worker.GenericWorkflowClientExternalImpl","nativeMethod":false},{"methodName":"signalWorkflowExecution","fileName":"DynamicWorkflowClientExternalImpl.java","lineNumber":167,"className":"com.amazonaws.services.simpleworkflow.flow.DynamicWorkflowClientExternalImpl","nativeMethod":false},...

When I initialize the ClientExternalFactory without the parameters:

private ParentWorkflowClientExternalFactory clientExternalFactory = new ParentWorkflowClientExternalFactoryImpl();

The exception thrown is: The required property genericClient is null. It could be caused by instantiating the factory through the default constructor instead of the one that takes service and domain arguments. The required property genericClient is null. It could be caused by instantiating the factory through the default constructor instead of the one that takes service and domain arguments.

ParentWorkflow#updateState does this:

private MyWorkflowState state;

// This method has @Signal in the interface.
@Override
public void updateState(MyWorkflowState newState) {
    state = newState;
}

Any advice?

There are two types of clients generated from the workflow interfaces. The internal and external ones. Internal are expected to be used from within a workflow code and external ones to be used outside of a workflow (for example from a web server). You are trying to use an external client inside a workflow which is not supported. Use the internal client (created using ParentWorkflowClientFactory) instead. See Flow Development Guide for more info.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM