【问题标题】:Can Ignite persistent one cache to multiple store?可以将持久的一个缓存点燃到多个存储吗?
【发布时间】:2018-03-31 00:22:46
【问题描述】:

我希望使用 ignite 将记录同步到多个 mysql 数据库。例如,当一些记录进入 cacheA 时,这些记录可以持久保存到 db1db2 两者。

可以吗?

我所做的是:

  1. 编写 PersonStore 类并将其构建为 jar 并将其放置在库中\
  2. 先将sample1.xml配置为

块引用

<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,只修改数据源部分

块引用

<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

但只有一个 db 得到了数据。

【问题讨论】:

    标签: ignite


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-08-06
      • 2016-09-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-20
      相关资源
      最近更新 更多