【问题标题】:Camel and Cache LifeCycle骆驼和缓存生命周期
【发布时间】:2014-03-13 00:05:12
【问题描述】:

我在 Camel 中管理 ehCache 生命周期时遇到了麻烦。我有在 Spring DSL 中定义的路由。我可以通过我的应用程序动态加载它们。在骆驼上下文的初始加载中,缓存工作得非常好。然而,如果我停止骆驼上下文并尝试重新启动它,ehCache 不会重新启动。我没有 EhCache 自定义配置。这意味着整个生命周期实际上是由骆驼缓存管理的。

这是我在重新启动骆驼上下文后尝试访问 ehcache 时遇到的异常:

java.lang.IllegalStateException: The demo Cache is not alive (STATUS_SHUTDOWN)
        at net.sf.ehcache.Cache$CacheStatus.checkAlive(Cache.java:4009) ~[ehcache2.8.0.jar:2.8.0]
at net.sf.ehcache.Cache.checkStatus(Cache.java:2717) ~[ehcache-2.8.0.jar:2.8.0]

有没有办法更好地控制 EhCache 生命周期管理,以便在重新启动路由时可以重新启动缓存?

按照这些思路,有没有一种方法可以设置缓存,使其在 JVM 中全局可见,而不是绑定到一个骆驼上下文?换句话说,是否可以设置 ehCache 以便我可以在不关闭 EhC​​ache 的情况下重新启动骆驼上下文?

【问题讨论】:

    标签: java spring apache-camel ehcache


    【解决方案1】:

    考虑使用 spring 对EHCache 的支持,这将消除 Camel 管理 EHCache 的依赖。我的意思是使用 Spring 来管理 EHCache 而不是 Camel,以便启动/停止 camelContext/routes 不会影响 EHCache。检查 EHCache 提供的 JMX 支持,以了解您对全局可见性的其他要求。要启用 JMX 支持,您需要使用 EHCache 管理服务,如下所示:

    <bean id="ehCacheManagementService" class="net.sf.ehcache.management.ManagementService" init-method="init" lazy-init="false">
      <constructor-arg>
        <bean class="net.sf.ehcache.CacheManager" factory-method="getInstance"/>
      </constructor-arg>
      <constructor-arg>
        <bean class="org.springframework.jmx.support.JmxUtils" factory-method="locateMBeanServer"/>
      </constructor-arg>
      <constructor-arg value="true"/>
      <constructor-arg value="true"/>
      <constructor-arg value="true"/>
      <constructor-arg value="true"/>
    </bean>
    

    【讨论】:

      猜你喜欢
      • 2018-07-28
      • 2012-08-27
      • 2023-04-02
      • 1970-01-01
      • 1970-01-01
      • 2015-05-05
      • 1970-01-01
      • 2011-05-29
      • 1970-01-01
      相关资源
      最近更新 更多