简体   繁体   English

将Apache Cassandra与Apache Ignite集成

[英]Integrating Apache Cassandra with Apache Ignite

I'm trying to integrate Apache Ignite with Apache Cassandra(3.11.2) as I want to use Ignite to cache the data present in my already existing Cassandra database. 我想将Apache Ignite与Apache Cassandra(3.11.2)集成在一起,因为我想使用Ignite来缓存已经存在的Cassandra数据库中的数据。

After going through the online resources, I've done the following till now: 浏览完在线资源后,到目前为止,我已经完成了以下操作:

  1. Downloaded Apache Ignite . 下载了Apache Ignite
  2. Copied all the folders present in "libs/optional/" to "libs/"(I don't know which ones will be required for Cassandra). 将“ libs / optional /”中存在的所有文件夹复制到“ libs /”中(我不知道Cassandra需要哪些文件夹)。
  3. Created 3 xmls in the config folder ie "cassandra-config.xml", "connection-settings.xml" and "persistance-settings.xml". 在config文件夹中创建了3个xml,即“ cassandra-config.xml”,“ connection-settings.xml”和“ persistance-settings.xml”。 Currently I'm using the same node(172.16.129.68) for both Cassandra and Ignite. 目前,我对Cassandra和Ignite使用相同的节点(172.16.129.68)。

cassandra-config.xml cassandra-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd">
<!-- Cassandra connection settings -->
<import resource="connection-settings.xml" />

<!-- Persistence settings for 'cache1' -->
<bean id="cache1_persistence_settings" class="org.apache.ignite.cache.store.cassandra.persistence.KeyValuePersistenceSettings">
        <constructor-arg type="org.springframework.core.io.Resource" value="file:/home/cass/apache_ignite/apache-ignite-fabric-2.4.0-bin/config/persistance-settings.xml" />
</bean>
<!-- Ignite configuration -->
<bean id="ignite.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
    <property name="cacheConfiguration">
        <list>
            <!-- Configuring persistence for "cache1" cache -->
            <bean class="org.apache.ignite.configuration.CacheConfiguration">
                <property name="name" value="cache1"/>
                <property name="readThrough" value="true"/>
                <property name="writeThrough" value="true"/>
                <property name="writeBehindEnabled" value="true"/>
                <property name="cacheStoreFactory">
                    <bean class="org.apache.ignite.cache.store.cassandra.CassandraCacheStoreFactory">
                        <property name="dataSourceBean" value="cassandraAdminDataSource"/>
                        <property name="persistenceSettingsBean" value="cache1_persistence_settings"/>
                    </bean>
                </property>
            </bean>
        </list>
    </property>
    <!-- Explicitly configure TCP discovery SPI to provide list of initial nodes. -->
    <property name="discoverySpi">
        <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
            <property name="ipFinder">
                <!--
                    Ignite provides several options for automatic discovery that can be used
                    instead os static IP based discovery. For information on all options refer
                    to our documentation: http://apacheignite.readme.io/docs/cluster-config
                -->
                <!-- Uncomment static IP finder to enable static-based discovery of initial nodes. -->
                <!--<bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder">-->
                <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.TcpDiscoveryMulticastIpFinder">
                    <property name="addresses">
                        <list>
                            <!-- In distributed environment, replace with actual host IP address. -->
                            <value>172.16.129.68:47500..47509</value>
                        </list>
                    </property>
                </bean>
            </property>
        </bean>
    </property>
</bean>

connection-settings.xml connection-settings.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd">

<bean id="loadBalancingPolicy" class="com.datastax.driver.core.policies.TokenAwarePolicy">
    <constructor-arg type="com.datastax.driver.core.policies.LoadBalancingPolicy">
        <bean class="com.datastax.driver.core.policies.RoundRobinPolicy"/>
    </constructor-arg>
</bean>

<bean id="cassandraAdminDataSource" class="org.apache.ignite.cache.store.cassandra.datasource.DataSource">
    <property name="port" value="9042"/>
    <property name="contactPoints" value="172.16.129.68"/>
    <property name="readConsistency" value="ONE"/>
    <property name="writeConsistency" value="ONE"/>
    <property name="loadBalancingPolicy" ref="loadBalancingPolicy"/>
</bean>

persistance-settings.xml persistance-settings.xml

<persistence keyspace="test" table="epc_table">
    <keyPersistence class="java.lang.String" strategy="PRIMITIVE" column="imsi"/>
    <valuePersistence strategy="BLOB"/>
</persistence>
  1. I run the following command to start Ignite from bin folder. 我运行以下命令从bin文件夹启动Ignite。

    ignite.sh ../config/cassandra-config.xml ignite.sh ../config/cassandra-config.xml

Now, I want to take a look at the cassandra table via sqlline. 现在,我想通过sqlline查看cassandra表。 I've tried the following: 我尝试了以下方法:

./sqlline.sh -u jdbc:cassandra://172.16.129.68:9042/test //(test is the name of the keyspace) ./sqlline.sh -u jdbc:cassandra://172.16.129.68:9042 / test //(测试是键空间的名称)

I get the following output: 我得到以下输出:

No known driver to handle "jdbc:cassandra://172.16.129.68:9042/test". Searching for known drivers...
java.lang.NullPointerException
sqlline version 1.3.0
0: jdbc:cassandra://172.16.129.68:9042/test>

I've also tried: 我也尝试过:

./sqlline.sh -u jdbc:ignite:thin://172.16.129.68

but when I use "!tables", I'm not able to see any table. 但是当我使用“!tables”时,我看不到任何表格。

What exactly has been missing? 到底缺少了什么? How to access/modify the tables present in Cassandra using sqlline? 如何使用sqlline访问/修改Cassandra中存在的表?

Operating System: RHEL 6.5 操作系统:RHEL 6.5

Apache Ignite is a key-value database and there are no tables created by default that you are able to view with JDBC connector. Apache Ignite是一个键值数据库,默认情况下,没有可使用JDBC连接器查看的表。 CacheStore is a way to integrate Ignite with external DB or any other storage, and it loads data as a key-value pair. CacheStore是将Ignite与外部数据库或任何其他存储集成的一种方式,并且将数据作为键值对加载。

In your config you said Ignite that you want to store and load entries in/from Cassandra, but still Ignite doesn't know entries structure (BTW Ignite really doesn't care what objects were putted into it). 在您的配置中,您说过Ignite您想在Cassandra中存储和加载条目,但Ignite仍然不知道条目结构(BTW Ignite确实不在乎将什么对象放入其中)。

To be able to list tables and do queries on it, you need to create tables. 为了能够列出表并对其进行查询,您需要创建表。 For that you need to have ignite-indexing in /lib directory and set QueryEntity or indexed types if you have annotated POJOs. 为此,您需要在/ lib目录中具有ignite-indexing并设置QueryEntity索引类型(如果您已注释POJO)。 Here is example of such configuration: 这是这样的配置的示例:

<bean class="org.apache.ignite.configuration.CacheConfiguration">
<property name="name" value="mycache"/>
<!-- Configure query entities -->
<property name="queryEntities">
    <list>
        <bean class="org.apache.ignite.cache.QueryEntity">
            <property name="keyType" value="java.lang.Long"/>
            <property name="valueType" value="org.apache.ignite.examples.Person"/>

            <property name="fields">
                <map>
                    <entry key="id" value="java.lang.Long"/>
                    <entry key="orgId" value="java.lang.Long"/>
                    <entry key="firstName" value="java.lang.String"/>
                    <entry key="lastName" value="java.lang.String"/>
                    <entry key="resume" value="java.lang.String"/>
                    <entry key="salary" value="java.lang.Double"/>
                </map>
            </property>

            <property name="indexes">
                <list>
                    <bean class="org.apache.ignite.cache.QueryIndex">
                        <constructor-arg value="id"/>
                    </bean>
                    <bean class="org.apache.ignite.cache.QueryIndex">
                        <constructor-arg value="orgId"/>
                    </bean>
                    <bean class="org.apache.ignite.cache.QueryIndex">
                        <constructor-arg value="salary"/>
                    </bean>
                </list>
            </property>
        </bean>
    </list>
</property>

If you configure that, you'll get an ability to enlist and query that tables over SQLine . 如果进行了配置,您将可以通过SQLine和查询该表。 (Please note, that you cannot query data that are not loaded into Ignite. To load them, you may use IgniteCache.get() with enabled readThrough option or IgniteCache.loadCache() to load everything from Cassandra table). (请注意,您无法查询未装入点燃数据加载它们,你可以使用IgniteCache.get()启用readThrough选项或IgniteCache.loadCache()来加载一切从卡桑德拉表)。

To query Cassandra with JDBC, you need a JDBC driver for it, try, for example DBSchema . 要使用JDBC查询Cassandra,您需要一个JDBC驱动程序,例如DBSchema

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM