从Java组件访问MuleMessage和流变量 [英] Accessing MuleMessage and a flow variable from Java component
问题描述
我有一个接收有效负载(JsonData)的Java组件,如下所示:
I have a Java component that receives a payload (JsonData), like this:
public String myMethod(JsonData payload) throws IOException {
// do things with payload.
}
这个工作正常,但我还需要访问一个流变量方法。我明白,为此,我需要运行myMessage.getInvocationProperty(my-variable-name);
但是,由于我只传递了有效负载,因此我无法访问MuleMessage。如何更改方法以便我可以访问我的消息/属性?
This is working fine, but I also need to access a flow variable within the method. I understand that, to do so, I need to run myMessage.getInvocationProperty("my-variable-name"); However, since I'm only passing the payload, I don't have access to the MuleMessage. How can I change my method so I can get access to my message/property?
我试过:
org.mule.RequestContext.getEvent().getMessage()
但它已被弃用。
此外,我已经阅读了有关此问题的各种答案,但从未找到完整答案。
Also, I've read all sorts of answers on this issue but never found a complete answer.
谢谢,
推荐答案
将流量变量作为第二个参数传递给 myMethod
通过调用
消息处理器。
Pass the flow variable as a second argument to myMethod
via the invoke
message processor.
因此,假设<$ c的新签名$ c> myMethod 是:
public String myMethod(JsonData payload, String myVariable) throws IOException {
// do things with payload.
}
你会这样做:
<invoke object-ref="myComponent"
method="myMethod"
methodArguments="#[message.payload],#[flowVars['my-variable-name']]" />
这篇关于从Java组件访问MuleMessage和流变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!