gpt4 book ai didi

java - 在 camunda 中发送变量和消息

转载 作者:行者123 更新时间:2023-12-03 08:14:03 24 4
gpt4 key购买 nike

我有一个接收进程,它有一个等待发送进程发送的消息的中间消息事件。

我已经能够在发送过程中通过以下委托(delegate)代码触发中间消息事件:

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

我读到这可能是由于同步/异步行为导致的问题?

感谢任何帮助。

最佳答案

您已经使用 MessageCorrelationBuilder#setVariable 在 MessageCorrelationBuilder 上设置了一个变量。有关详细信息,请参阅 JavaDoc 或 MessageCorrelationBuilder

正如您所提到的,您希望将消息关联到与给定变量匹配的进程。为此,您必须使用 #processInstanceVariableEquals 方法。

关于java - 在 camunda 中发送变量和消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44901995/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com