我正在尝试将OSS Ehcache与terracotta集群一起使用,但未能从ehcache客户端实现故障转移。
我在文档here
中找到了此配置<ehcache:service>
<terracotta:cluster>
<terracotta:connection url="terracotta://localhost:9510/clustered"/>
<terracotta:server-side-config auto-create="true">
<terracotta:default-resource from="default-resource"/>
</terracotta:server-side-config>
</terracotta:cluster>
</ehcache:service>
但此连接只接受一个URL。如果群集中有两个兵马俑服务器,我希望HA具有故障转移功能。 像ActiveMQ故障转移网址:
failover:(server1:port,server2:port)
我的问题:这是否可以在opensource ehcache中使用,或者我需要拥有企业版,如果可能的话,如何配置它。
更新
我试过了
<terracotta:connection url="terracotta://host1:9510,host2:9610/clustered1"/>
正如Louis Jacomet所提到的,但没有正确解析,给出:
org.ehcache.xml.exceptions.XmlConfigurationException: Error parsing XML configuration at file:/F:/Work/WORKSPACES/java7_ws/CachingTest/target/classes/ehcache.xml
at org.ehcache.xml.XmlConfiguration.<init>(XmlConfiguration.java:167)
at org.ehcache.xml.XmlConfiguration.<init>(XmlConfiguration.java:131)
at org.ehcache.jsr107.EhcacheCachingProvider$ConfigSupplier.getConfiguration(EhcacheCachingProvider.java:324)
... 4 more
Caused by: org.xml.sax.SAXParseException; systemId: file:/F:/Work/WORKSPACES/java7_ws/CachingTest/target/classes/ehcache.xml; lineNumber: 12; columnNumber: 91; cvc-pattern-valid: Value 'terracotta://host1:9510,host2:9610/clustered1' is not facet-valid with respect to pattern '\w+://([^\]\[/?#@]+@)?[^:?#/]+(:[1-9][0-9]{0,4})?(/[^\?#]*)?(\?[^#]*)?(#.*)?' for type 'connectionUrl'.
如果我尝试编译良好的<terracotta:connection url="terracotta://host1:9510/clustered1,host2:9610/clustered1"/>
,但如果 host1 发生故障,客户端会给出:
Exception in thread "main" org.ehcache.StateTransitionException: org.terracotta.connection.ConnectionException: java.util.concurrent.TimeoutException
at org.ehcache.core.StatusTransitioner$Transition.failed(StatusTransitioner.java:235)
at org.ehcache.core.EhcacheManager.init(EhcacheManager.java:588)
at org.ehcache.jsr107.EhcacheCachingProvider.createCacheManager(EhcacheCachingProvider.java:148)
at org.ehcache.jsr107.EhcacheCachingProvider.getCacheManager(EhcacheCachingProvider.java:128)
at org.ehcache.jsr107.EhcacheCachingProvider.getCacheManager(EhcacheCachingProvider.java:79)
at org.ehcache.jsr107.EhcacheCachingProvider.getCacheManager(EhcacheCachingProvider.java:183)
at dev.ams.poc.CacheApp.main(CacheApp.java:15)
Caused by: java.lang.RuntimeException: org.terracotta.connection.ConnectionException: java.util.concurrent.TimeoutException
at org.ehcache.clustered.client.internal.service.DefaultClusteringService.initClusterConnection(DefaultClusteringService.java:189)
at org.ehcache.clustered.client.internal.service.DefaultClusteringService.start(DefaultClusteringService.java:140)
at org.ehcache.core.internal.service.ServiceLocator.startAllServices(ServiceLocator.java:118)
at org.ehcache.core.EhcacheManager.init(EhcacheManager.java:560)
... 5 more
Ehcache版本:Ehcache-clustered-3.2
答案 0 :(得分:1)
此功能是开源产品的一部分,没有问题。
您需要在其中列出多个server:port
,如:
<ehcache:service>
<terracotta:cluster>
<terracotta:connection url="terracotta://localhost:9510,otherhost:9510/clustered"/>
<terracotta:server-side-config auto-create="true">
<terracotta:default-resource from="default-resource"/>
</terracotta:server-side-config>
</terracotta:cluster>
</ehcache:service>
建议列出所有服务器,否则您需要非常准确地了解故障转移逻辑。