An open API service indexing awesome lists of open source software.

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

This repository contains multiple projects using Apache Cassandra.
https://github.com/bruce-mig/spring-apache-cassandra

apache-cassandra cassandra cql cqlsh reactive-programming sstable

Last synced: about 2 months ago
JSON representation

This repository contains multiple projects using Apache Cassandra.

Awesome Lists containing this project

README

          

# spring-apache-cassandra

## Overview
This repository contains multiple projects using Apache Cassandra.

![cassandra](logo.png)

---

## 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](https://www.docker.com/) & [Docker Compose](https://docs.docker.com/compose/)
- Java 17+ and Maven (for Spring Boot app)
- Optional: Astra DB, for a cloud based Cassandra cluster

---

## Getting Started

### 1. Clone the repository

```bash
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.

```bash
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](https://github.com/bruce-mig/spring-apache-cassandra/tree/main/user-management-cassandra) project as below.

```bash
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](https://github.com/bruce-mig/spring-apache-cassandra/tree/main/reactive-user-management) project as below.

```bash
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

```bash
cd
./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](https://cassandra.apache.org/doc/latest/)
[Spring Data for Apache Cassandra](https://spring.io/projects/spring-data-cassandra)

## License
This project is licensed under the [MIT License](LICENCE).

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