How to share data between mule apps don't use database(using object store)

£可爱£侵袭症+ 提交于 2019-12-01 12:35:59

问题


I have a problem when using Object store in mule. It cannot share datas with another apps on the same mule server. I have set same as below but cannot using in another app(same server).

<spring:beans>
    <spring:bean id="myListableObjectStore"
        class="org.mule.util.store.SimpleMemoryObjectStore" />
</spring:beans>
<objectstore:config name="ObjectStore"
    objectStore-ref="myListableObjectStore" doc:name="ObjectStore" />

Who have any solution about this, please help me.

Thank you so much!


回答1:


With the introduction of Mule 3.5 there is the concept of domains which can be used to share resources between applications (although there are some limitations as described in the mule documentation). In this case you want to share the object store spring bean.

In order to do this in Mule 3.5 you should create a domain to do so:

  1. Create a folder under $MULE_HOME/domains (e.g. $MULE/domains/mydomain)
  2. Create a file named mule-domain-config.xml, this should contain the domain configuration in your case it should look like:
<?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>

Then you need to create an application which uses the domain. To do so:

  1. In studio create a new project
  2. Edit the domain property in mule-deploy.properties this should be set to the domain name (e.g. mydomain)
  3. Also make sure that in the object store config is referring to the correct object store bean (in this case myListableObjectStore)

The code for the application should look something like:

<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>

This app can be deployed both to the usual $MULE_HOME/apps directory or else you can deploy it under the domain folder.

To test this deploy another app that reads the retrieves from the object store such as :

<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>

Then hit http://localhost:8085/mypayload and when you hit http://localhost:8081 you should see /mypayload in your browser.



来源:https://stackoverflow.com/questions/26056997/how-to-share-data-between-mule-apps-dont-use-databaseusing-object-store

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!