使用MongoDB的Mule缓存策略

时间:2015-12-02 11:00:54

标签: mongodb caching mule

我试图在mule中为特定请求实现缓存策略,与MongoDB一起使用。

名称空间 - xmlns:mongo="http://www.mulesoft.org/schema/mule/mongo"

schemalocation - http://www.mulesoft.org/schema/mule/mongo http://www.mulesoft.org/schema/mule/mongo/current/mule-mongo.xsd

尝试两种方式:

1)我配置了MongoDB连接器。

连接器 - <mongo:config name="Mongo_DB" doc:name="Mongo DB" database="test" username="test"/>

缓存的对象库 -

<ee:object-store-caching-strategy name="Mongo_DB_Caching_Strategy" doc:name="Caching Strategy"> <spring-object-store ref="Mongo_DB" /> </ee:object-store-caching-strategy>

但我收到了错误:

java.lang.IllegalStateException:无法将类型[org.mule.module.mongo.connectivity.MongoCloudConnectorConnectionManager]的值转换为属性&#39; store&#39所需的类型[org.mule.api.store.ObjectStore] ;:找不到匹配的编辑器或转换策略。

2)缓存的对象存储 - (其他方式):

像这样 - Mule Caching Strategy using Mongo DB

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

但是我得到同样的错误。

1 个答案:

答案 0 :(得分:1)

此配置对我有用,并使用Spring实例化操作系统。

<spring:beans>
        <spring:bean id="mongoObjectStore" class="org.mule.module.mongo.MongoObjectStore" 
            init-method="initialize" scope="singleton">
            <spring:property name="host" value="localhost"/>
            <spring:property name="port" value="27017"/>
            <spring:property name="database" value="test"/>
            <spring:property name="username" value=""/>
            <spring:property name="password" value=""/>
            <spring:property name="writeConcern" value="DATABASE_DEFAULT"/>
        </spring:bean>
    </spring:beans>

    <ee:object-store-caching-strategy
        name="mongoCachingStrategy">
        <spring-object-store ref="mongoObjectStore" />
    </ee:object-store-caching-strategy>