随着 Mule 3.5 的引入,域的概念可用于在应用程序之间共享资源(尽管 mule 文档中描述了一些限制)。在这种情况下,您希望共享对象存储 spring bean。
为了在 Mule 3.5 中执行此操作,您应该创建一个域来执行此操作:
- 在 $MULE_HOME/domains 下创建一个文件夹(例如 $MULE/domains/mydomain)
- 创建一个名为 mule-domain-config.xml 的文件,它应该包含您的域配置,它应该如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<mule-domain xmlns="http://www.mulesoft.org/schema/mule/domain" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/domain http://www.mulesoft.org/schema/mule/domain/current/mule-domain.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd">
<spring:beans>
<spring:bean id="myListableObjectStore" class="org.mule.util.store.SimpleMemoryObjectStore" />
</spring:beans>
</mule-domain>
然后您需要创建一个使用该域的应用程序。为此:
- 在工作室创建一个新项目
- 编辑 mule-deploy.properties 中的域属性,这应该设置为域名(例如 mydomain)
- 还要确保在对象存储配置中引用了正确的对象存储 bean(在本例中为 myListableObjectStore)
应用程序的代码应类似于:
<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.5.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="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/current/mule-objectstore.xsd
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">
<objectstore:config name="ObjectStore"
objectStore-ref="myListableObjectStore"
/>
<flow name="store" doc:name="store">
<http:inbound-endpoint address="http://localhost:8085" doc:name="HTTP"/>
<objectstore:store config-ref="ObjectStore" key="abc" value-ref="#[payload]" doc:name="ObjectStore"/>
</flow>
<flow name="retrieve" doc:name="retrieve">
<http:inbound-endpoint address="http://localhost:8084" doc:name="HTTP"/>
<objectstore:retrieve key="abc" config-ref="ObjectStore" doc:name="ObjectStore"/>
</flow>
这个应用程序既可以部署到通常的 $MULE_HOME/apps 目录,也可以部署在域文件夹下。
为了测试这个部署另一个从对象存储读取检索的应用程序,例如:
<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.5.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="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/current/mule-objectstore.xsd
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">
<objectstore:config name="ObjectStore"
objectStore-ref="myListableObjectStore"
/>
<flow name="retrieve" doc:name="retrieve">
<http:inbound-endpoint address="http://localhost:8081" doc:name="HTTP"/>
<objectstore:retrieve key="abc" config-ref="ObjectStore" doc:name="ObjectStore"/>
</flow>
然后点击http://localhost:8085/mypayload
,当您点击时,http://localhost:8081
您应该在浏览器中看到 /mypayload。