我有一个接收进程,它有一个中间消息事件,等待发送进程发送的消息。
我已经能够通过发送过程中的以下委托代码触发中间消息事件:
RuntimeService runtimeService = ProcessEngines
.getDefaultProcessEngine()
.getRuntimeService();
MessageCorrelationResult result = runtimeService
.createMessageCorrelation("my-message-name")
.setVariable("customer", customer) //trigger instance where customer matches
.correlateWithResult();
我的问题是:如何将一个变量从发送过程发送到接收过程并结合消息?有没有最佳做法?
这是我到目前为止所尝试的:
// Set the variable after the correlation
runtimeService.setVariable(result.getProcessInstance().getId(),
"variableToSend", variableToSend);
我尝试在JavaDelegate
中检索变量,如下所示:
// Access the sent variable
Double sendByOtherProcess = (Double) delegate.getVariable("variableToSend");
// sendByOtherProcess == null
有趣的是,可以在接收过程中通过JavaScript检索嵌入表单中的variableToSend
。
我读到由于同步/异步行为可能是一个问题?
任何帮助表示感谢。
答案 0 :(得分:1)
您已使用MessageCorrelationBuilder#setVariable
在MessageCorrelationBuilder上设置了一个变量。有关更多信息,请参阅JavaDoc或MessageCorrelationBuilder
正如您所提到的,您希望将消息与与给定变量匹配的进程相关联。为此,您必须使用#processInstanceVariableEquals
方法。