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

时间:2018-04-26 19:44:49

标签: java amazon-web-services amazon-swf

我试图通知我的父工作流更新其状态变量。父工作流程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为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},...

初始化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;
}

有什么建议吗?

1 个答案:

答案 0 :(得分:2)

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