Illustration Image

Cassandra.Link

The best knowledge base on Apache Cassandra®

Helping platform leaders, architects, engineers, and operators build scalable real time data platforms.

10/23/2020

Reading time:2 min

DataStax-Examples/cassandra-reactive-demo-java

by DataStax-Examples

Full demo application that interacts with Apache Cassandra using the Java DataStax driver 4.4+, reactive programming and the Spring Framework.This was used as part of a presentation at DataStax Accelerate 2019, the video is available below and walks you through taking an application from synchronous to asynchronous to reactive.Contributor(s): Alexandre Dutra, Cedrick LunvenObjectivesDemonstrate how to build synchronous, asynchronous, and reactive API services using the Java DataStax DriverProject Layout0_common folder - Contains files shared across all three version of the application such as data models, DSE connection files, spring configuration files, and prepared statements for use with DSE1_sync folder - Contains the repository and controller for the synchronous version of the application2_async folder - Contains the repository and controller for the asynchronous version of the application3_reactive folder - Contains the repository and controller for the reactive version of the applicationdocker_compose.yml - A docker compose file which will create a local single node cluster of DSE 6.7 and a DataStax Studio instance.schema.cql - The CQL schema for the keyspace that needs to be createdapplication.yml - The configuration file where you can set your parameters for connecting to the DSE cluster.How this WorksThis sample contains 3 separate Spring Boot applications and a module that contains shared code between them. The first application showshow to develop a synchronous api endpoint against the Stock data model schema found in schema.cql. The second application extendsthat first application to show how to perform the same tasks asynchronously. The third application takes that asynchronous applicationand modifies it to build it using the reactive programming methods available in the Java DataStax Driver.For details on how the code works we recommend watching the presentation video from DataStax Accelerate 2019 above.Setup and RunningPrerequisitesJava 11MavenEither a running DSE 6.7 Cluster or you may start one up using the docker-compose.ymlA keyspace created with the schema from schema.cql installedRunningNote: When running the commands below be sure that you have Java 11 set as your Java version. If you are not sure you can use java -versionon the command line to check the currently configured version.To build the application:mvn clean compileNote: For the next 4 commands you must have a version of DSE running, the schema.cql configured and all the appropriate parameters configured in the application.yml file.To run the associated unit tests:mvn testIntelliJ will automatically detect the 3 Spring Boot applications included as part of this repo and create three run configurations, one for each.To run the synchronous version of the application run the SyncApplication ConfigurationTo run the asynchronous version of the application run the AsyncApplication ConfigurationTo run the reactive version of the application run the ReactiveApplication Configuration

Illustration Image

Full demo application that interacts with Apache Cassandra using the Java DataStax driver 4.4+, reactive programming and the Spring Framework.

This was used as part of a presentation at DataStax Accelerate 2019, the video is available below and walks you through taking an application from synchronous to asynchronous to reactive.

YouTube Video Link

Contributor(s): Alexandre Dutra, Cedrick Lunven

Objectives

  • Demonstrate how to build synchronous, asynchronous, and reactive API services using the Java DataStax Driver

Project Layout

  • 0_common folder - Contains files shared across all three version of the application such as data models, DSE connection files, spring configuration files, and prepared statements for use with DSE
  • 1_sync folder - Contains the repository and controller for the synchronous version of the application
  • 2_async folder - Contains the repository and controller for the asynchronous version of the application
  • 3_reactive folder - Contains the repository and controller for the reactive version of the application
  • docker_compose.yml - A docker compose file which will create a local single node cluster of DSE 6.7 and a DataStax Studio instance.
  • schema.cql - The CQL schema for the keyspace that needs to be created
  • application.yml - The configuration file where you can set your parameters for connecting to the DSE cluster.

How this Works

This sample contains 3 separate Spring Boot applications and a module that contains shared code between them. The first application shows how to develop a synchronous api endpoint against the Stock data model schema found in schema.cql. The second application extends that first application to show how to perform the same tasks asynchronously. The third application takes that asynchronous application and modifies it to build it using the reactive programming methods available in the Java DataStax Driver.

For details on how the code works we recommend watching the presentation video from DataStax Accelerate 2019 above.

Setup and Running

Prerequisites

  • Java 11
  • Maven
  • Either a running DSE 6.7 Cluster or you may start one up using the docker-compose.yml
  • A keyspace created with the schema from schema.cql installed

Running

Note: When running the commands below be sure that you have Java 11 set as your Java version. If you are not sure you can use java -version on the command line to check the currently configured version.

To build the application:

mvn clean compile

Note: For the next 4 commands you must have a version of DSE running, the schema.cql configured and all the appropriate parameters configured in the application.yml file. To run the associated unit tests:

mvn test

IntelliJ will automatically detect the 3 Spring Boot applications included as part of this repo and create three run configurations, one for each.

To run the synchronous version of the application run the SyncApplication Configuration

To run the asynchronous version of the application run the AsyncApplication Configuration

To run the reactive version of the application run the ReactiveApplication Configuration

Related Articles

spring
rest
api

GitHub - DataStax-Examples/spring-data-starter: ⚡️ A sample Spring Data Cassandra REST API

John Doe

2/14/2024

Checkout Planet Cassandra

Claim Your Free Planet Cassandra Contributor T-shirt!

Make your contribution and score a FREE Planet Cassandra Contributor T-Shirt! 
We value our incredible Cassandra community, and we want to express our gratitude by sending an exclusive Planet Cassandra Contributor T-Shirt you can wear with pride.

Join Our Newsletter!

Sign up below to receive email updates and see what's going on with our company

Explore Related Topics

AllKafkaSparkScyllaSStableKubernetesApiGithubGraphQl

Explore Further

java

reactive

cassandra
reactive