2016-08-22 27 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。