Cassandra Sample

This sample demonstrates how to use cassandra database form a webapplication which is deployed on Liberty. This sample assumes that Apache Cassandra database is running on localhost with default settings. Both cassandra database as well as liberty are running on Java 7 runtime.

This sample can be installed onto runtime versions 8.5.5.0 and later.

Installation Instructions

Online installation (requires 8.5.5.6 or later):

  1. Install the sample by running the command below from the bin directory of your server installation:
    installUtility install cassandraDBSample

Any missing features required by the server will be installed for you.

Offline installation:

  1. Download the cassandraDBSample.jar using the download button at the top of the page and place it in the root of your server installation.
  2. Extract the sample into the Liberty installation by running the command below from the root of your server installation:
    java -jar cassandraDBSample.jar

Any missing features required by the server will need to be installed separately.

Running The Application

To run the CassandraDB application:

  1. Ensure that the Cassandra Database instance is running on localhost with default settings and it should be running on Java 7 runtime.
  2. Start the cassandraDBSample server by running the command below from the bin directory in the Liberty profile installation:
    server run cassandraDBSample
  3. Confirm the application started by looking for the following message in the log: wlp/usr/servers/cassandraDBSample/logs/messages.log
    CWWKZ0001I: Application cassandraDBApp started in XX.XX seconds.
  4. In your browser, enter the URL for the application: http://localhost:9141/cassandraDBApp (where port 9141 assumes the httpEndpoint provided in the sample server.xml has not been modified).
  5. Item Management web page will be shown with Item and Price textboxes. Try entering Item and Price, then submit. This entered values will be stored in cassandra database and displays all the data in the table below the submit button in a tablular format.

Notes

The cassandraDBApp.war file contains the source and binaries for the application, and can be used to import it to Eclipse.

The application is automatically installed because it is located in the server dropins directory. Any number of applications can be installed from this location.

Sample Structure

  • wlp
    • usr
      • servers
        • cassandraDBSample
          • Copyright.txt
          • apps
            • cassandraDBApp.war
          • lafiles
            • LA_en
            • LI_en
          • readme.html
          • server.xml
      • shared
        • resources
          • CassandraDBSampleLibs
            • cassandra-driver-core-2.0.4.jar
            • guava-16.0.1.jar
            • metrics-core-3.0.2.jar
            • netty-3.9.0.Final.jar
            • slf4j-api-1.7.2.jar