使用apache Camel缓存http请求

Joe*_*wyn 2 memcached apache-camel

我正在使用apache camel 2.12.2为http请求构建负载平衡器。为此,我使用了camel-servlet,camel-http组件,并且我的路由定义如下:

<from uri="servlet:///my/path?matchOnUriPrefix=true" />
<loadBalance inheritErrorHandler="false">
    <failover roundRobin="true" maximumFailoverAttempts="2">
        <exception>java.io.IOException</exception>
    </failover>
    <to uri="http://server1:9090?bridgeEndpoint=true&amp;throwExceptionOnFailure=false" />
    <to uri="http://server2:9090?bridgeEndpoint=true&amp;throwExceptionOnFailure=false" />
    <to uri="http://server3:9090?bridgeEndpoint=true&amp;throwExceptionOnFailure=false" />
</loadBalance>
Run Code Online (Sandbox Code Playgroud)

现在,我正在尝试使用Memcached为http请求实现缓存。为此,我正在尝试使用RoutePolicy。是否有可能在发生缓存命中时中断交换并从onExchangeBegin返回,而不会达到http端点?还是有更好的方法使用Memcached为http请求实现缓存?

我尝试了骆驼缓存组件,但是我们不能使用EHCache,因为我们已经在项目中使用了Memcached。

Cla*_*sen 5

您可以通过设置此属性将交换标记为停止

exchange.setProperty(Exchange.ROUTE_STOP, true);
Run Code Online (Sandbox Code Playgroud)

(如果您在路线中使用它,这就是<stop />的工作方式)

...则路由引擎将不会继续路由交换,而使用者将能够尽快使用交换作为响应。