bruce-mig / spring-apache-cassandra

This repository contains multiple projects using Apache Cassandra.

Repository from Github https://github.combruce-mig/spring-apache-cassandraRepository from Github https://github.combruce-mig/spring-apache-cassandra

spring-apache-cassandra

Overview

This repository contains multiple projects using Apache Cassandra.

cassandra


Features

  • 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

Prerequisites

  • Docker & Docker Compose
  • Java 17+ and Maven (for Spring Boot app)
  • Optional: Astra DB, for a cloud based Cassandra cluster

Getting Started

1. Clone the repository

git clone https://github.com/bruce-mig/spring-apache-cassandra.git
cd spring-apache-cassandra

2. Set up Cassandra cluster

Start multi-node Pulsar cluster:

docker compose up -d

Or, for standalone mode:

docker compose up cassandra-1 -d


Configure apache cassandra

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'};

user-management-cassandra

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;

reactive-user-management

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;

Application Usage

1. Build & Run Spring Boot App

cd <project-name>
./mvnw spring-boot:run

Api Docs http://localhost:8080/swagger-ui/index.html#/


Project Structure

  • 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

References

Apache Cassandra Documentation
Spring Data for Apache Cassandra

License

This project is licensed under the MIT License.

Contributing

Contributions are welcome! Please open issues or submit pull requests for improvements or bug fixes.

About

This repository contains multiple projects using Apache Cassandra.

License:MIT License


Languages

Language:Java 100.0%