Apache Cassandra Operator Sample

Sample Overview

This topic describes how to run the TIBCO StreamBase® for Apache Cassandra operator sample application, which illustrates how to use the operators with a Cassandra database cluster. For more information on this operator, see Using the Apache Cassandra Operators.

This sample includes a number of Cassandra operators, which by default connect to a Cassandra cluster named Test Cluster, which is assumed to already be running on localhost. This sample also includes a table called myks.users. Once connected, use the sample to read and write to the table using the various operators.

This Sample's Files

This sample contains the following files:

  • The sample EventFlow application, cassandra.sbapp.

  • A corresponding sbd.sbconf, which the StreamBase Server uses to configure the Java environment to locate the Cassandra libraries and the Cassandra cluster.

Running This Sample in StreamBase Studio

The steps to run this sample in Studio are as follows:

  1. Before running you must configure the project to locate and load the Cassandra libraries. In the Package Explorer, right-click on the top-level node of your project and select Build PathConfigure Build Path. On the Libraries tab of the dialog box that appears, make sure the following JAR files are added from your machine's Cassandra installation's lib directory:

    • apache-cassandra-*.jar

    • cassandra-driver-core-*.jar

    • guava-*.jar

    • metrics-core-*.jar

  2. In the Package Explorer, double-click to open the cassandra.sbapp application.

  3. Make sure the application is the currently active tab in the EventFlow editor, then click the Run button. This opens the SB Test/Debug perspective and starts the application.

  4. In the Manual Input view, select the QueryIn input stream.

  5. Enter the following values:

    • query: CREATE KEYSPACE myks WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 1}

    Click Send Data (which will trigger the tuple to be sent to the Cassandra cluster as the specified query).

  6. Again in the QueryIn stream, enter the following values and click Send Data to create the table:

    • query: CREATE TABLE myks.users (user_id int PRIMARY KEY, balance double, fname text, lname text, memberSince timestamp)

  7. In the Manual Input view, select the InsertIn input stream.

  8. Enter the following values:

    • user_id: 1

    • balance: 1000.0

    • fname: John

    • lname: Doe

    • membersince: 2001-01-01

    Click Send Data to add the row to the table, and observe that the InsertOut output stream received a tuple indicating that the operation has succeeded.

  9. You may similarly Delete rows and issue SELECT queries using the DeleteIn and SelectIn input streams respectively.

  10. When done, press F9 or click the Stop Running Application button.

Importing This Sample into StreamBase Studio

In StreamBase Studio, import this sample with the following steps:

  • From the top-level menu, select FileLoad StreamBase Sample.

  • Type cassandra to narrow the list of options.

  • elect Apache Cassandra Operators from the Extending StreamBase category.

  • Click OK.

StreamBase Studio creates a single project for the Cassandra Operator samples in your current Studio workspace.

Sample Location

When you load the sample into StreamBase Studio, Studio copies the sample project's files to your Studio workspace, which is normally part of your home directory, with full access rights.

Important

Load this sample in StreamBase Studio, and thereafter use the Studio workspace copy of the sample to run and test it, even when running from the command prompt.

Using the workspace copy of the sample avoids the permission problems that can occur when trying to work with the initially installed location of the sample. The default workspace location for this sample is:

studio-workspace/sample_cassandra

See Default Installation Directories for the location of studio-workspace on your system.

In the default TIBCO StreamBase installation, this sample's files are initially installed in:

streambase-install-dir/sample/adapter/embedded/cassandra

See Default Installation Directories for the default location of studio-workspace on your system.