【问题标题】:Can I persist mule variable data in Mule Server Memory我可以在 Mule 服务器内存中保留 mule 变量数据吗
【发布时间】:2013-12-18 06:53:14
【问题描述】:

我有一个 mule 流,它是一个 SOAP Web 服务客户端 (Mule Flow - A)。此客户端调用将每 30 分钟执行一次,以从第 3 方检索唯一的会话密钥。我有其他 mule 流(作为单独的 mule 应用程序运行)需要在其流中引用此会话变量。我的问题是 - 有没有办法将 Mule Flow A 检索到的会话密钥保存在 mule 服务器内存中,以便其他 mule 应用程序可以在运行时访问它? 可以将数据保存在文件或数据库中的某处并检索它,但我想在得出解决方案之前检查是否可以这样做。

谢谢!

更新了共享对象存储的示例 Mule 流程:

流程一:

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:objectstore="http://www.mulesoft.org/schema/mule/objectstore" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/objectstore http://www.mulesoft.org/schema/mule/objectstore/1.0/mule-objectstore.xsd">

    <spring:beans>
        <spring:bean id="myListableObjectStore" class="org.mule.util.store.SimpleMemoryObjectStore"/>
    </spring:beans>
    <objectstore:config name="ObjectStore" objectStore-ref="myListableObjectStore" doc:name="ObjectStore"/>
    <flow name="objectstoreFlow1" doc:name="objectstoreFlow1">
        <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8083" doc:name="HTTP"/>
        <message-filter doc:name="Filter favicon">
        <not-filter>
            <wildcard-filter pattern="/favicon.ico" caseSensitive="true"/>
        </not-filter>
        </message-filter>
        <logger message="#[message.InboundProperties.key]" level="INFO" doc:name="Logger"/>
        <objectstore:store config-ref="ObjectStore" key="#[message.inboundProperties.key]" value-ref="#[message.inboundProperties.value]" doc:name="ObjectStore"/>

    </flow>
</mule>

Mule Flow 2 - 检索值

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:objectstore="http://www.mulesoft.org/schema/mule/objectstore" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/objectstore http://www.mulesoft.org/schema/mule/objectstore/1.0/mule-objectstore.xsd">

    <spring:beans>
        <spring:bean id="myListableObjectStore" class="org.mule.util.store.SimpleMemoryObjectStore"/>
    </spring:beans>
    <objectstore:config name="ObjectStore" objectStore-ref="myListableObjectStore" doc:name="ObjectStore"/>
    <flow name="MemoryTest2Flow1" doc:name="MemoryTest2Flow1">
        <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8084" doc:name="HTTP"/>
                <message-filter doc:name="Filter favicon">
        <not-filter>
            <wildcard-filter pattern="/favicon.ico" caseSensitive="true"/>
        </not-filter>
        </message-filter>
        <objectstore:retrieve config-ref="ObjectStore" key="#[message.inboundProperties.key]" doc:name="ObjectStore"/>
  <logger level="ERROR" doc:name="Logger"/>
    </flow>
</mule>

我能否使用相同的键检索第一个流中存储的对象作为第二个 mule 流的一部分?

【问题讨论】:

    标签: mule


    【解决方案1】:

    是的,您可以使用 Mule 完成所有这些操作。

    您将使用Quartz scheduler endpoint 呼叫您的第 3 方,可能是通过 http SOAP 或 REST。

    您可以使用 mule JDBC endpoint 将新获取的密钥放入您选择的几乎任何数据库中,或者您可以使用 mule-module-objectstore 将您的密钥保存在内存中或由文件持久性支持。

    然后,您可以为您的依赖服务设计一种检索方法,以使用(JDBC 或对象存储)从您选择的位置获取它们的密钥。在这种情况下,我没有看到使用会话变量的令人信服的理由,因为听起来好像只有一个键,而不是每个会话一个键。

    【讨论】:

    • 感谢您的回复。我刚刚对 mule-module-object-store 做了一些研究。这可能对我有帮助。你知道我是否可以在两个 mule 应用程序之间共享对象存储吗?请在我的问题中找到我的示例 Mule 应用程序:
    • 如果它们是在同一个 mule 服务器上运行的两个应用程序,我相信它们都可以访问同一个对象存储,但我还没有尝试过。如果它们是单独的 mule 服务器,那么您将需要使用 Mule EE 并对服务器进行集群,使用 cultered-objectstore 将跨集群复制对象存储。
    • 它们不在单独的 mule 服务器中。两个应用程序都在同一个 mule 服务器上运行。我已经用我的骡流样本更新了我的问题。我在服务器上部署了这两个应用程序,但我得到了一个异常 --- null (org.mule.api.store.ObjectAlreadyExistsException)。我在这里是否缺少一些东西来为两个应用程序全局指定对象存储?
    • 似乎您还没有在该键上设置任何内容并获得空值。您可能需要结合使用 并将 overwrite 属性设置为 true 来获得所需的内容。
    • 鉴于每个应用程序似乎都在 mem 对象存储中使其成为自己的,因此它们似乎彼此隔离。您可以尝试使用文件对象存储并查看它们是否都可以访问。或者使用 JDBC。或者重新思考为什么需要在同一台服务器上运行两个应用程序。如果它们是同一个应用但不同的流程和端点,你应该仍然能够得到你需要的东西。
    【解决方案2】:

    你可以使用 mule 注册表

    设置值

    <scripting:script engine="Groovy">
    <![CDATA[muleContext.getRegistry().registerObject("${Key}", new String(flowVars.value))]]>
                </scripting:script>
    </scripting:component>
    

    读取值

     <scripting:script engine="Groovy"><![CDATA[payload = muleContext.getRegistry().get("${Key}")]]></scripting:script>
    

    参考:https://docs.mulesoft.com/mule-user-guide/v/3.6/storing-objects-in-the-registry https://gist.github.com/vejaay/44545f738d511b6d6b9e591c8784d677

    【讨论】:

      【解决方案3】:

      实现解决方案的另一种方法。

      如果流在同一个应用程序中,那么您可以在两个流中使用相同的对象存储。

      如果流程在不同的应用程序中,那么您可以在域项目级别定义对象存储,例如<spring:beans> <spring:bean id="myobjectstore" class="org.mule.util.store.SimpleMemoryObjectStore"/> </spring:beans>

      然后您可以参考以下两个应用程序中的对象存储&lt;objectstore:config name="ObjectStore__Connector" entryTtl="0" expirationInterval="0" maxEntries="0" doc:name="ObjectStore: Connector" objectStore-ref="myobjectstore"/&gt;

      这将确保两个应用程序都可以访问对象存储。

      【讨论】:

        【解决方案4】:
        For this case, choose to use default object store is simpler 
        
        Each Mule runtime includes these three spring bean instances:
        _defaultInMemoryObjectStore
        _defaultUserObjectStore     // if you want to use persistent option
        _defaultTransientUserObjectStore
        
        for example:
        <objectstore:config name="ObjectStore" objectStore-ref="myListableObjectStore" doc:name="ObjectStore"/>
        
        <objectstore:config name="ObjectStore" objectStore-ref="_defaultInMemoryObjectStore" doc:name="ObjectStore"/>
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-04-07
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多