简体   繁体   English

从Mule ESB上的Java会话中读取变量

[英]Read variable from session in java on mule ESB

im developping a bookstore in Mule ESB and i need how can i read a session variable in java. 我正在用Mule ESB开发一家书店,我需要如何在Java中读取会话变量。 My case is i query on my MYSQL the price of the book. 我的情况是我在MYSQL上查询这本书的价格。 I save this result in a session variable. 我将此结果保存在会话变量中。 To print the bill, i show the list of books with quantity and the price. 要打印账单,我会显示带有数量和价格的书籍清单。 I need recover the value of price. 我需要收回价格的价值。

Any solution? 有什么办法吗? Thanks. 谢谢。

In order to access any variables, you need to first have access to the message. 为了访问任何变量,您首先需要访问消息。 This can be done by either using a transformer which extends AbstractMessageTransformer or using a component which implements Callable. 这可以通过使用扩展AbstractMessageTransformer的转换器或使用实现Callable的组件来完成。 Once you have that in place, you can use something similar to the one below: 设置好之后,您可以使用与以下类似的方法:

public class TestComponent implements Callable {

    @Override
    public Object onCall(MuleEventContext eventContext) throws Exception {

         MuleMessage message = eventContext.getMessage();
         String sessionProperty = message.getProperty("mySessionProperty", PropertyScope.SESSION);
         ....
    }
}

Note that session properties may affect the memory, therefore you should only use them when necessary. 请注意,会话属性可能会影响内存,因此,仅应在必要时使用它们。

What you will need is to implement a component that implements the callable interface. 您将需要实现一个实现可调用接口的组件。 From the event context you can do a get message and then get session property . 您可以从事件上下文中获取消息,然后获取会话属性

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM