Configuring Apache Cassandra

In the previous chapter we discussed  the fundamentals of Apache Cassandra.There we discussed the architecture details , Cassandra data model etc. In this chapter we are discussing  Apache Cassandra configuration  in local Windows machine. Also in our coming sections we will be discussing example programs using Apache Cassandra as database. So we need to configure a work space for that with all the needed dependencies.That also we are discussing in this chapter.

Configuring Apache Cassandra

Step1)Download  & Start Apache Cassandra

As we discussed in the previous chapter  Cassandra database was developed by facebook for their storage purpose . Then they handed over  Cassandra project to Apache Foundation .Now the development and distribution is done by the Apache Software Foundation.We can download Apache Cassandra from Apache Download page. In our case , we are discussing the entire tutorial of  Apache Cassandra with  version 1.1.2.

Step2)Extract  the downloaded archive to a suitable folder.

For example I extracted the archive to D:\javaworks\.

Step3)Start the  Cassandra database instance on local machine.

For that open a command prompt and go to the bin of Cassandra folder by using cd command.

(In my case it is : cd Javaworks\apache-cassandra-1.1.12\bin )

Step 4)Start Apache Cassandra by simply typing the command ‘cassandra’.

The console will show the messages . Please note  the instance name port name etc .

Step 5)Start the command line client for Apache Cassandra.

Open another command line . Go to the bin of cassandra folder by using cd command.Then simply type cassandra-cli’  command.

Now our Cassandra database is ready . Also our client is ready we can create key space , column family etc using the  command line client

Step 6)Create a keyspace

As we discussed in the previous chapter, a keyspace is the container in Cassandra .Once the command line client is completely up  just run the following query  in the second command prompt.

create keyspace USERKEYSPACE with placement_strategy = ‘org.apache.cassandra.locator.SimpleStrategy’

    and strategy_options = {replication_factor:1};

When the  keyspace created , appropriate message will be displayed and command line  will be ready to accept  next query.

So from step 1 to step6 , we created a new Apache Cassandra instance and started it. Also we created a key space with name ‘USERKEYSPACE’.

We will be doing data manipulation with Cassandra database using Java. For that we need to make a work space with all necessaries.

Configuring Workspace for Apache Cassandra

1)Start a project (Java Project or Dynamic Web Project) in eclipse.

2)As we discussed earlier in this section , we should have a client to interact with Cassandra data base.Apache Hector is such a client API. It is available for download.We can download it from Download Page. I will be using version 1.1.2 in the coming examples.

Extract  the archived file  and include the so obtained jar files to the project created in step1.

3) The hector API is a high Cassandra client API.Apache Thrift is a low level client API. Hector API internally uses Thrift . We need to download the thrift libraries to satisfy all dependencies. Thrift  libraries can be downloaded from here.We need to extract and build  the downloaded file . Alternately we can download the built  thrift libraries from here. I downloaded version 0.9.0. Include this jar file also to the workspace as dependency.

So the jar files we added as dependance are :

Thrift libraries

1)libthrift-0.9.0.jar

Hector libraries

1)cassandra-thrift-1.1.0.jar

2)commons-lang-2.4.jar

3)commons-pool-1.5.3.jar

4)FastInfoset-1.2.2.jar

5)guava-r09.jar

6)hector-core-1.1-2.jar

7)hector-core-sources-1.1-2.jar

8)slf4j-api-1.6.1.jar

9)speed4j-0.9.jar

10)uuid-3.2.0.jar

Now Cassandra set up is ready .Workspace is also ready . We will be explaining Java sample codes involving data manipulation with Apache Cassandra in coming chapters. There we will be using the set up we made here.We will be using the same keyspace ‘USERKEYSPACE‘ also.

See Related Topics:

Apache Cassandra Introduction

Inserting data into Apache Cassandra database using Java

Reading data from Apache Cassandra database

Listing columns in a column family using Java

Deleting column from Apache Cassandra using Java

Inserting objects into Apache Cassandra using Hector API

Reading object data from Apache Cassandra using Hector API

Leave a Reply

Your email address will not be published. Required fields are marked *