This repository contains multiple projects using Apache Cassandra.
- Local Apache Cassandra Cluster setup with Docker Compose (both standalone and multi-node options)
- Spring Boot integration for CRUD operations with Apache Cassandra
- Swagger UI for testing API endpoints
- Docker & Docker Compose
- Java 17+ and Maven (for Spring Boot app)
- Optional: Astra DB, for a cloud based Cassandra cluster
git clone https://github.com/bruce-mig/spring-apache-cassandra.git
cd spring-apache-cassandra
Start multi-node Pulsar cluster:
docker compose up -d
Or, for standalone mode:
docker compose up cassandra-1 -d
The Cassandra Query Language (CQL) is very similar to SQL but suited for the JOINless structure of Cassandra. The CQL shell, or cqlsh, is one tool to use in interacting with the database. We’ll use it to configure the database.
docker exec -it cassandra-1 bin/bash
cqlsh
describe keyspaces;
CREATE KEYSPACE IF NOT EXISTS migeri WITH REPLICATION ={ 'class' : 'SimpleStrategy','replication_factor' : '1'};
Configure the cluster for the user-management-cassandra project as below.
use migeri;
CREATE TABLE IF NOT EXISTS users (id int PRIMARY KEY,name text,address text,age int);
# add index on columns to be filtered
create index on users(age);
select * from users;
Configure the cluster for the reactive-user-management project as below.
use migeri;
CREATE TABLE IF NOT EXISTS users (id int PRIMARY KEY,name text,address text,age int);
# add index on columns to be filtered
create index on users(age);
create index on users(address);
# insert
INSERT INTO migeri.users (id ,name ,address ,age ) VALUES (6347, 'User1', 'City1', 25);
INSERT INTO migeri.users (id ,name ,address ,age ) VALUES (6348, 'User2', 'City2', 28);
INSERT INTO migeri.users (id ,name ,address ,age ) VALUES (6349, 'User3', 'City3', 27);
INSERT INTO migeri.users (id ,name ,address ,age ) VALUES (6350, 'User4', 'City4', 22);
select * from users;
cd <project-name>
./mvnw spring-boot:run
Api Docs http://localhost:8080/swagger-ui/index.html#/
- user-management-cassandra: Spring Boot project
- reactive-user-management: Spring Boot project using Reactive Cassandra Repositories and Reactive web
- scripts: CQL Scripts
- docker-compose.yaml: Docker Compose configurations
Apache Cassandra Documentation
Spring Data for Apache Cassandra
This project is licensed under the MIT License.
Contributions are welcome! Please open issues or submit pull requests for improvements or bug fixes.