如何在Mule中使用CXF配置EHCache [英] How to configure the EHCache with CXF in Mule

查看:145
本文介绍了如何在Mule中使用CXF配置EHCache的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个SOAP Web服务,如下所示:-

I have a SOAP webservice as follow :-

<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="${timeToIdle}"/>
            <spring:property name="timeToLive" value="${timeToLive}"/>
            <spring:property name="overflowToDisk" value="true"/>
            <spring:property name="maxElementsOnDisk" value="10000000"/>
            <spring:property name="diskPersistent" value="false"/>
            <spring:property name="diskExpiryThreadIntervalSeconds" value="5"/>
            <spring:property name="memoryStoreEvictionPolicy" value="LRU"/>
            <!-- Cache Expiry -->
        </spring:bean>  
    </spring:beans>


<ee:object-store-caching-strategy name="cachingStrategy" doc:name="cachingStrategy">
    <custom-object-store class="com.anirban.EHCatche.EhcacheObjectStore">
        <spring:property name="cache" ref="cache"/>
    </custom-object-store>
</ee:object-store-caching-strategy>

<!-- Catch Strategy ends -->    



<flow name="ServiceFlow" doc:name="ServiceFlow">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8082" path="mainData" doc:name="HTTP" />

<ee:cache doc:name="Cache" cachingStrategy-ref="cachingStrategy">
 <cxf:jaxws-service  serviceClass="com.test.services.schema.maindata.v1.MainData"  doc:name="SOAP"/>
 <component class="com.test.services.schema.maindata.v1.Impl.MainDataImpl" doc:name="JavaMain_ServiceImpl"/>
</ee:cache>

</flow>

现在您可以看到..我已经将cxf:jaxws-servicecomponent class包裹在ee:cache块下..

Now as you can see .. I have wrapped the cxf:jaxws-service and component class under ee:cache block ..

Web服务从数据库中获取一组数据

The Webservice fetch a set of Data from DB

我的主要目的是,如果我触发Web服务,它将在第一次从DB中获取数据,然后对于相同的请求,它将在特定的时间内从缓存中获取数据.不同的请求,它将再次针对该请求首次从数据库中获取数据,然后从缓存中检索到后续的相同请求..

My main intention is if I trigger the webservice ,it will fetch the Data from DB from the first time and then for the same request it will fetch from cache for a particular time ... In between if I trigger the service with different request it will again fetch data from DB for the first time for that request and then retrieve from the cache for the subsequent same request ..

它将在特定时间将数据保存在缓存中..

It will hold the data in cache for a particular time ..

现在的问题是,如果我触发该服务..它总是从数据库中获取数据,并且对于同一请求它没有在缓存中保存任何数据.. 每次我访问服务时,它都会直接访问数据库,并且不会为同一请求从缓存中获取数据. 请帮助..如何在Mule中使用CXF配置缓存

Now the issue is If I trigger the service .. it's always fetching the Data from DB and it's not holding any data in cache for the same request .. Every time I hit the service it hits the Database directly and the data is not fetched from cache for the same request .. Please help .. how to configure the cache with CXF in Mule

推荐答案

使用VM端点并将请求和响应序列化为字符串,从而将服务流分成两部分.这将使事件可缓存.

Break your service flow in two, using a VM endpoint and serializing both the request and response to string. This will make the event cacheable.

<flow name="ServiceFlow" doc:name="ServiceFlow">
  <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8082" path="mainData" doc:name="HTTP" />
  <object-to-string-transformer />
  <ee:cache doc:name="Cache" cachingStrategy-ref="cachingStrategy">
    <vm:outbound-endpoint path="cxf.service" exchange-pattern="request-response" />
    <object-to-string-transformer />
  </ee:cache>
</flow>

<flow name="CXFFlow" doc:name="CXFFlow">
  <vm:inbound-endpoint path="cxf.service" exchange-pattern="request-response" />
  <cxf:jaxws-service  serviceClass="com.test.services.schema.maindata.v1.MainData"  doc:name="SOAP"/>
  <component class="com.test.services.schema.maindata.v1.Impl.MainDataImpl" doc:name="JavaMain_ServiceImpl"/>
</flow>

这篇关于如何在Mule中使用CXF配置EHCache的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆