0

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!

  • Are you on CE or EE? On CE, you could create a custom object store backed by Hazelcast. – David Dossot Sep 26 '14 at 20:14
  • @David Dossot: I have using mule Mule EE 3.4.1. I will try with your solution but are you have any sample about custom object store backed by Hazelcast. Can you shared to me? – Tran Thanh Nguyen Oct 01 '14 at 07:31
  • Sorry Tran, I don't have a ready made example. Hazelcast is super easy to use so it shouldn't be too hard to do. I'll do it myself if I had time! – David Dossot Oct 01 '14 at 13:45

1 Answers1

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.