Single-Node Cassandra Cluster and NodeJS client — demo setup on Ubuntu 14.04 (AWS)

Cassandra + NodeJS

Introduction

Configuring the EC2-Instance

Installing Cassandra

Authentification Setup

sudo vim /etc/cassandra/cassandra.yaml
authenticator: PasswordAuthenticator
cqlsh -u cassandra -p cassandra
CREATE USER 'admin' WITH PASSWORD 'adminpassword' SUPERUSER;
CREATE USER 'developer' WITH PASSWORD 'devpassword' NOSUPERUSER

Database configuration

Description of EC2-Instance — Private IP
listen_address: <yourPrivateIP>
seeds: "127.0.0.1,<yourPrivateIP>"
rpc_address: <yourPrivateIP>
sudo service cassandra restart

NodeJS client example

const cassandra = require(‘cassandra-driver’);const client = new cassandra.Client({
contactPoints: [ ‘your-public-api’ ],
authProvider: new cassandra.auth
.PlainTextAuthProvider(‘developer’, ‘devpassword’)
});
client.execute(`CREATE KEYSPACE IF NOT EXISTS vq_ai_tracking WITH REPLICATION = { ‘class’ : ‘SimpleStrategy’, ‘replication_factor’ : 1 };`)
.then(() =>
client.execute(`CREATE TABLE IF NOT EXISTS vq_ai_tracking.actions(userId uuid primary key);`,
(err, result) => {
console.log(err, result);
}));

Further reading

Hi, I’m Adrian. This is my private blog and you’ll find here from time to time updates about my travels, works and investments.

Hi, I’m Adrian. This is my private blog and you’ll find here from time to time updates about my travels, works and investments.