SWF:如何从子工作流向父工作流发出信号?

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

我正在尝试向我的父工作流发送信号以更新其状态变量。父工作流 ID 传递给子工作流的 execute 方法。

@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(...);
}

但是,这会在 SWF 代码中引发 NullPointerException(AmazonSimpleWorkflow 为空):

["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},...

当我在没有参数的情况下初始化ClientExternalFactory时:

private ParentWorkflowClientExternalFactory clientExternalFactory = new ParentWorkflowClientExternalFactoryImpl();

抛出的异常是: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 这样做:

private MyWorkflowState state;

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

有什么建议吗?

从工作流界面生成了两种类型的客户端。内部和外部的。预期内部代码将在工作流代码中使用,而外部代码将在工作流外部使用(例如从 Web 服务器)。 您正在尝试在不受支持的工作流中使用外部客户端。请改用内部客户端(使用 ParentWorkflowClientFactory 创建)。有关详细信息,请参阅 Flow Development Guide