0

Is it possible to use the org.mule.module.mongo.MongoObjectStore as a cache strategy within a flow?

I have attempted with the following but I get the error

null (java.lang.NullPointerException)
org.mule.module.mongo.MongoObjectStore:382 (null).

<mule xmlns:jdbc-ee="http://www.mulesoft.org/schema/mule/ee/jdbc" xmlns:mongo="http://www.mulesoft.org/schema/mule/mongo" xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:core="http://www.mulesoft.org/schema/mule/core" version="EE-3.4.0" 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.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/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd
http://www.mulesoft.org/schema/mule/ee/jdbc http://www.mulesoft.org/schema/mule/ee/jdbc/current/mule-jdbc-ee.xsd
http://www.mulesoft.org/schema/mule/mongo http://www.mulesoft.org/schema/mule/mongo/2.0/mule-mongo.xsd">

    <ee:object-store-caching-strategy name="Mongo_Caching_Strategy" doc:name="Caching Strategy">
        <custom-object-store class="org.mule.module.mongo.MongoObjectStore">
            <spring:property name="host" value="localhost"/>
            <spring:property name="port" value="27017"/>
            <spring:property name="database" value="test"/>
        </custom-object-store>
    </ee:object-store-caching-strategy>

    <flow name="htmlCacheFlow" doc:name="htmlCacheFlow">
        <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8084" path="cache" doc:name="HTTP"/>
        <expression-transformer expression="#[payload.substring(payload.lastIndexOf('/') + 1)]" doc:name="Expression"/>
        <ee:cache doc:name="Cache" cachingStrategy-ref="Mongo_Caching_Strategy" >
            <logger message="getting item from db for key #[payload]" level="INFO" doc:name="Logger"/>
            <expression-transformer expression="#[payload + 'asd']" doc:name="Expression"/>
        </ee:cache>
</flow>
</mule>

Could anyone provide an example on how to configure it?

Stuart
  • 1,227
  • 17
  • 21

1 Answers1

3

Try this:

    <mule xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:mos="http://www.mulesoft.org/schema/mule/mongo-object-store"
        xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:script="http://www.mulesoft.org/schema/mule/scripting"
        xmlns:test="http://www.mulesoft.org/schema/mule/test" xmlns:spring="http://www.springframework.org/schema/beans"
        xmlns:util="http://www.springframework.org/schema/util" xmlns:p="http://www.springframework.org/schema/p"
xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core"
        xsi:schemaLocation="
              http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
              http://www.mulesoft.org/schema/mule/mongo-object-store http://www.mulesoft.org/schema/mule/mongo-object-store/current/mule-mongo-object-store.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/scripting http://www.mulesoft.org/schema/mule/scripting/current/mule-scripting.xsd
              http://www.mulesoft.org/schema/mule/test http://www.mulesoft.org/schema/mule/test/current/mule-test.xsd
              http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
              http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">

      <mos:config name="mos" database="test" />

      <ee:object-store-caching-strategy name="Mongo_Caching_Strategy">
           <spring-object-store ref="mos" />
        </ee:object-store-caching-strategy> 
    </mule>

Notice the specific namespaces for mos.

Ryan Carter
  • 11,441
  • 2
  • 20
  • 27
  • Thanks for the reply but unfortunately that errors as it attempts to set the store property to a MongoCloudConnectorConnectionManager instead of MongoObjectStore. – Stuart Oct 03 '13 at 08:02
  • Apologies, I was thinking of the Redis connector where the connector is also an object store - Mongo as you rightly say has a separate class for the objectstore. I have amended the answer. – Ryan Carter Oct 03 '13 at 08:16
  • Thanks again, this looks good but I cant get the namespace to recognise for mos as mule-mongo-object-store.xsd location as it is not included within the referenced mule.module.mongo-3.4.0.jar META-INF spring.schemas file and does not exist at the specified address. Sorry if I am missing something obvious. – Stuart Oct 03 '13 at 09:59
  • 2
    Hmm, theres a bug... @Module was commented out and then removed so now it can't be referenced - https://github.com/mulesoft/mongo-connector/commit/4855839d7a90caad6f813b618d1a8d426fc2ea0a. i'll raise a bug and a pull request. – Ryan Carter Oct 03 '13 at 10:10
  • Ryan from your previous answer you mentioned Redis which I am now looking at. Could you help in this question? http://stackoverflow.com/questions/19221828/mule-caching-strategy-using-redit – Stuart Oct 07 '13 at 10:02
  • @RyanCarter has this issue being resolved I am facing the same issue, looks like the fix was reverted not sure why ... – Sudarshan Jul 09 '15 at 03:10
  • I'm not sure why my PR was reverted. However, there is a workaround i documented here:http://ryandcarter.blogspot.co.uk/2014/06/synchronizing-data-across-mule.html – Ryan Carter Jul 09 '15 at 10:10