在Mule中使用mysql配置EHCache

时间:2015-04-16 07:19:15

标签: mule ehcache

在mule中,我将MySQL DB连接器包装在Cache范围内,并配置了自定义缓存策略,即EHCache。

因此,每当有对缓存作用域的重复请求时,它应该返回存储在其缓存中的数据。但它并没有这样做。所以,我已经完成了这篇文章 How to configure the EHCache with CXF in Mule

根据建议,我将代码分成两部分,并根据请求和缓存范围的响应使用VM和对象到字符串转换器

<spring:beans>
    <spring:bean id="cacheManager" name="cacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"/>
    <spring:bean id="cache" name="cache" class="org.springframework.cache.ehcache.EhCacheFactoryBean">
        <spring:property name="cacheManager" ref="cacheManager"/>
        <spring:property name="cacheName" value="dbCache"/>
        <spring:property name="maxElementsInMemory" value="10000"/>
        <spring:property name="eternal" value="false"/>
        <spring:property name="timeToIdle" value="120"/>
        <spring:property name="timeToLive" value="120"/>
        <spring:property name="overflowToDisk" value="true"/>
        <spring:property name="maxElementsOnDisk" value="10000000"/>
        <spring:property name="diskPersistent" value="false"/>
        <spring:property name="diskExpiryThreadIntervalSeconds" value="120"/>
        <spring:property name="memoryStoreEvictionPolicy" value="LRU"/>
    </spring:bean>
</spring:beans>

<ee:object-store-caching-strategy name="Caching_Strategy" doc:name="Caching Strategy">
    <custom-object-store class="com.lineage.cache.EhcacheObjectStore">
        <spring:property name="cache" ref="cache"/>
    </custom-object-store>
</ee:object-store-caching-strategy>

  <flow name="highjumpdummyFlow">
    <http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP"/>
    <ee:cache doc:name="Cache" cachingStrategy-ref="Caching_Strategy">
        <logger message="#['Into the Cache Block']" level="INFO" doc:name="Logger"/>
        <vm:outbound-endpoint exchange-pattern="request-response" path="DBCache" connector-ref="VM" doc:name="VM">
            <vm:transaction action="ALWAYS_BEGIN"/>
        </vm:outbound-endpoint>
       </ee:cache>
    <logger message="#[payload]" level="INFO" doc:name="Logger"/>
</flow>

  <flow name="highjump_dummyFlow1">
    <vm:inbound-endpoint exchange-pattern="one-way" path="DBCache" connector-ref="VM" doc:name="VM">
        <vm:transaction action="ALWAYS_BEGIN"/>
    </vm:inbound-endpoint>
    <db:select config-ref="MySQL_Configuration" doc:name="Database">
        <db:dynamic-query><![CDATA[select * from HIGHJUMP_INVOICE_CHARGE_STAGING;]]></db:dynamic-query>
    </db:select>
    <data-mapper:transform config-ref="Map_To_XML" doc:name="Map To XML"/>
    <byte-array-to-object-transformer doc:name="Byte Array to Object"/>
    <object-to-string-transformer doc:name="Object to String"/>
</flow>

但现在,我遇到了一个新问题。在DB连接器的第二次流动中,骡子流失败了 org.mule.api.MessagingException:无法绑定到当前事务的连接:org.mule.transport.vm.VMTransaction@90b65fe0-e408-11e4-ae24-d43d7e1497b8 [status = STATUS_ACTIVE,key = null,resource = null](org .mule.module.db.internal.domain.connection.ConnectionBindingException)。消息有效内容的类型为:String

控制台消息: 根异常堆栈跟踪: org.mule.transaction.IllegalTransactionStateException:只能绑定“QueueManager / QueueSession”类型资源     在org.mule.transport.vm.VMTransaction.bindResource(VMTransaction.java:41)     at org.mule.module.db.internal.domain.connection.TransactionalDbConnectionFactory.getConnectionFromTransaction(TransactionalDbConnectionFactory.java:110)     at org.mule.module.db.internal.domain.connection.TransactionalDbConnectionFactory.createConnection(TransactionalDbConnectionFactory.java:72)     + 3个以上(设置调试级别日志记录或'-Dmule.verbose.exceptions = true'用于所有内容)

1 个答案:

答案 0 :(得分:0)

请删除导致此问题的 VM 中的交易部分,并按照此处给出的内容进行操作: - http://blogs.mulesoft.org/guest-post-exposing-cxf-webservice-mule-cache/ 还放了  高速缓存块之前的<object-to-string-transformer doc:name="Object to String"/>以使有效负载高速缓存

说实话,您可以直接将数据库组件直接放在缓存范围下,而不是将流分为2.它会起作用..