从Java组件访问MuleMessage和流变量

编程入门 行业动态 更新时间:2024-10-19 00:28:22
本文介绍了从Java组件访问MuleMessage和流变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个接收有效负载(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.

因此,假设 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和流变量

本文发布于:2023-11-23 19:58:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1622704.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:组件   Java   MuleMessage

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!