可以将持久的一个缓存Ignite到多个商店吗?

时间:2017-10-19 02:04:54

标签: ignite

我希望使用ignite将记录同步到多个mysql db。例如,当某些记录进入 cacheA 时,记录可以持久保存到 db1 db2 。< / p>

有可能吗?

我做的是:

  1. 编写一个PersonStore类并将其构建为jar并将其放在libs \
  2. first sample1.xml configure as
  3. 块引用

    <bean class="org.springframework.jdbc.datasource.DriverManagerDataSource" id="dataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
        <property name="url" value="jdbc:mysql://111.xxx.xxx:3306/test"></property>
        <property name="username" value="root"></property>
        <property name="password" value="xxxx"></property>
    </bean>
    <bean id="ignite.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
        <property name="peerClassLoadingEnabled" value="true"/>
        <property name="cacheConfiguration">
            <list>
                <bean class="org.apache.ignite.configuration.CacheConfiguration">
                    <property name="name" value="personCache"></property>
                    <!-- Enable readThrough-->
                    <property name="readThrough" value="true"></property>
                    <property name="writeThrough" value="true"></property>
                    <!-- Set cacheStoreFactory-->
                    <property name="cacheStoreFactory">
                        <bean class="javax.cache.configuration.FactoryBuilder" factory-method="factoryOf">
                            <constructor-arg value="com.jguo.ignitepersistentstoredemo.PersonStore"></constructor-arg>
                        </bean>
                    </property>
                    <property name="queryEntities">
                        <list>
                            <bean class="org.apache.ignite.cache.QueryEntity">
                                <property name="keyType" value="java.lang.Long"></property>
                                <property name="valueType" value="com.jguo.ignitepersistentstoredemo.model.Person"></property>
                                <property name="fields">
                                    <map>
                                        <entry key="id" value="java.lang.Long"></entry>
                                        <entry key="name" value="java.lang.String"></entry>
                                        <entry key="orgId" value="java.lang.Long"></entry>
                                        <entry key="salary" value="java.lang.Integer"></entry>
                                    </map>
                                </property>
                            </bean>
                        </list>
                    </property>
                </bean>
            </list>
        </property>
    </bean>
    
    1. 启动一个Ignite节点 bin / ignite.sh config / sample1.xml

    2. 创建另一个xml文件sample2.xml并仅修改数据源部分

    3. 块引用

      <bean class="org.springframework.jdbc.datasource.DriverManagerDataSource" id="dataSource">
          <property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
          <property name="url" value="jdbc:mysql://222.xxx.xxx:3306/test"></property>
          <property name="username" value="root"></property>
          <property name="password" value="xxxx"></property>
      </bean>
      
      1. 启动第二个Ignite节点 bin / ignite.sh config / sample2.xml

      2. 启动客户端并将一些记录放入缓存 personCache

      3. 但只有一个数据库获得了数据。

1 个答案:

答案 0 :(得分:1)

CacheConfiguration应该在所有节点之间统一。这就是为什么只有一个配置生效的原因。

如果您需要一个CacheStore来对多个DB进行操作,您需要创建一个自定义CacheStore,它将有多个数据源引用不同的DB并以适当的方式实现方法。

相关问题