Skip to content

exploratory project to see how to consume Apache Cassandra / AWS Keyspaces from spring-boot-kotlin project

Notifications You must be signed in to change notification settings

sombriks/sample-cassandra

Repository files navigation

Sample Cassandra

CI with Gradle

Sampling minimal configuration to work with Apache Cassandra

Requirements

  • java 17
  • gradle 8.5
  • docker 20 or newer
  • a modern ide (intellij ultimate)

How to run

First spin up a cassandra server with docker compose:

docker compose -f src/infrastructure/docker-compose.yml up

Then start the project either using the ide or using gradle wrapper

./gradlew bootRun

Note: if this error occurs:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cassandraSession' defined in class path resource [org/springframework/boot/autoconfigure/cassandra/CassandraAutoConfiguration.class]: Failed to instantiate [com.datastax.oss.driver.api.core.CqlSession]: Factory method 'cassandraSession' threw exception with message: Invalid keyspace spring_cassandra

You will need to manually create the cassandra keyspace. there is a test script that you can use to prepare cassandra database.

Testing

There are a few test samples using testcontainers, so you don't need to manually create and run cassandra:

./gradlew test

It also allows CI to run with no external dependencies, which is the correct way to do CI runs. See gradle.yml for details.

AWS Keyspaces

One thing is regular cassandra. Another beast is AWS Keyspaces.

Using the sample project as reference, this configuration was made for better reuse in future.

In order to proper get this working, you must provide the following environment variables:

AWS_ACCESS_KEY_ID=<aws account id>
AWS_SECRET_ACCESS_KEY=<aws account key>
CASSANDRA_KEYSPACE_NAME=<cassandra keyspace>
CASSANDRA_USERNAME=<service account user>
CASSANDRA_PASSWORD=<service account password>

Then you can configure the IDE to run with the aws profile. Or try this command line:

./gradlew bootRun --args="--spring.profiles.active=aws"

Reference Documentation

For further reference, please consider the following sections:

Guides

The following guides illustrate how to use some features concretely:

Additional Links

These additional references should also help you:

Testcontainers support

This project uses Testcontainers at development time.

Testcontainers has been configured to use the following Docker images:

Please review the tags of the used images and set them to the same as you're running in production.

About

exploratory project to see how to consume Apache Cassandra / AWS Keyspaces from spring-boot-kotlin project

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages