2016-08-22 26 views
1

我有一个用例,我必须为我的ignite群集支持多个持久存储,例如,缓存A1应该从数据库db1启动,缓存B1应该从数据库db2启动。可以这样做吗?。在点燃配置XML我只能提供一个持久性存储的详细信息,用于Apache Ignite的多个持久性存储

<beans xmlns="http://www.springframework.org/schema/beans" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util" 
xsi:schemaLocation=" 
    http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans.xsd 
    http://www.springframework.org/schema/util 
    http://www.springframework.org/schema/util/spring-util.xsd"> 

<!-- Datasource for Persistence. --> 
<bean name="dataSource" 
    class="org.springframework.jdbc.datasource.DriverManagerDataSource"> 
    <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" /> 
    <property name="url" value="jdbc:oracle:thin:@localhost:1521:roc12c" /> 
    <property name="username" value="test" /> 
    <property name="password" value="test" /> 
</bean> 

在我CacheStore实现我只可以用鼠标右键访问这个数据库?

+0

你可以添加你得到那个例子的文档吗? –

+0

@Carlos这是Ignite-Config.xml的一部分,它附带有在点火站点提供的示例程序。我将这个'dataSource'bean注入到** CacheJdbcPojoStoreFactory **对象中,这个工厂将在** CacheConfiguration **对象中用** CacheConfiguration.setCacheStoreFactory **方法设置。实际上,我遵循自动持久性技术,我们可以避免每个缓存的CacheStore实现[链接] https://apacheignite.readme.io/docs/automatic-persistence。 –

回答

3

我没有试过这个,但是如果它与其他bean配置的系统类似。您应该可以使用不同的名称和配置创建另一个bean。然后在您的缓存配置中为A1B1指定不同的数据源。话虽如此,我在理论上猜测。

这可能是你已经这样做了,但是我无法从你的问题中得知。如果你选择以这种方式实现你的缓存https://apacheignite.readme.io/docs/persistent-store你可以明确地配置两个缓存有不同的数据源。这是我目前正在实现多个缓存。在我使用的缓存存储中,我具体调用了要去哪个数据库。

这是我用于我的缓存配置。

<property name="cacheConfiguration"> 
     <bean class="org.apache.ignite.configuration.CacheConfiguration"> 
      <!-- Set a cache name. --> 
      <property name="name" value="recordData"/> 
      <property name="rebalanceMode" value="ASYNC"/> 
      <property name="cacheMode" value="PARTITIONED"/> 
      <property name="backups" value="1"/> 
      <!-- Enable Off-Heap memory with max size of 10 Gigabytes (0 for unlimited). --> 
      <property name="memoryMode" value="OFFHEAP_TIERED"/> 
      <property name="offHeapMaxMemory" value="0"/> 
      <property name="swapEnabled" value="false"/> 

      <property name="cacheStoreFactory"> 
       <bean class="javax.cache.configuration.FactoryBuilder" factory-method="factoryOf"> 
        <constructor-arg value="com.company.util.MyDataStore"/> 
       </bean> 
      </property> 
      <property name="readThrough" value="true"/> 
      <property name="writeThrough" value="true"/> 

     </bean> 
    </property> 
2

缓存存储配置为每个缓存,所以你只需要注入不同的数据源到不同的商店。你展示的只是一个独立的数据源bean,它甚至不是IgniteConfiguration的一部分。您可以拥有多个具有不同ID的数据源Bean。