我有一个mule流程,它是一个SOAP Web服务客户端(Mule Flow - A)。此客户端调用将每30分钟执行一次,以从第三方检索唯一的会话密钥。我有其他mule流(作为单独的mule应用程序运行),需要在它们的流中引用此会话变量。我的问题是 - 有没有办法将Mule Flow A检索到的会话密钥保存在mule服务器内存中,以便其他mule应用程序可以在运行时访问它? 可以将数据保存在文件或数据库中的某个位置并检索它,但我想在结束解决方案之前检查是否可以这样做。
谢谢!
更新了共享对象存储的示例骡流:
流程1:
<?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>
骡流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流程的一部分?
答案 0 :(得分:2)
是的,你可以用Mule完成所有这些。
您将使用Quartz scheduler endpoint来呼叫您的第三方,可能是通过http SOAP或REST。
您可以使用mule JDBC endpoint将新获取的密钥放在您选择的几乎任何数据库中,或者您可以使用mule-module-objectstore将密钥保存在内存中或由文件持久性支持。
然后,您可以为依赖服务设计检索方法,以使用(JDBC或objectstore)从所选位置获取密钥。在这种情况下,我没有看到使用会话变量的令人信服的理由,因为它听起来只有一个密钥,而不是每个会话一个。
答案 1 :(得分:0)
您可以使用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
答案 2 :(得分:0)
实现解决方案的另一种方法。
如果流程在同一个应用程序中,那么您可以在两个流程中使用相同的对象库。
如果流程在不同的应用程序中,那么您可以在域项目级别定义对象存储,例如<spring:beans>
<spring:bean id="myobjectstore" class="org.mule.util.store.SimpleMemoryObjectStore"/>
</spring:beans>
然后,您可以在两个应用程序中引用对象存储,如下所示<objectstore:config name="ObjectStore__Connector" entryTtl="0" expirationInterval="0" maxEntries="0" doc:name="ObjectStore: Connector" objectStore-ref="myobjectstore"/>
这将确保应用程序都可以访问objectstore。
答案 3 :(得分:0)
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"/>