Illustration Image

Cassandra.Link

The best knowledge base on Apache Cassandra®

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

2/18/2018

Reading time:2 min

doanduyhai/killrchat

by John Doe

README.md A hand's on exercise for Cassandra 2.1.This hands-on will make you, step by step with unit tests, create a working chat application usingApache Cassandra™AchillesSpring BootAngularJS + UI BootstrapThe hands-on will focus on the data modelling part, you need to:understand the data model (tables)implement the services to make the tests pass using AchillesAll the front-end, as well as the REST resource and all Spring configuration config and other glue code is provided as aconvenience so that participants can focus solely on the data modelling and service layer.For object mapping, we use Achilles which provides many tools to make development more effective and easier. We'lluse the JUnit rule support from Achilles to start an embedded Cassandra in memory for unit testing.Once all the exercises are done, we can have some fun using the real chat!If you're not familiar with Cassandra, please take a look at the introduction slidesFor a presentation of KillrChat, look at the slides hereWarning! You'll need a recent and decent browser (no IE8) to make the chat front-end work:IE10, Chrome, FireFox ...Warning! You should have Maven and Java (1.7+) installed and functionnal, other component will be installed automaticallyFirst clone the repository with git clone https://github.com/doanduyhai/killrchat.gitThen enter the folder cd killrchatDevelopment modeTo run the application in the development mode:killrchat> mvn clean testkillrchat> mvn spring-boot:run -PdevWhen running the application in dev mode, Achilles will start an embedded Cassandra server and createthe following data folders:/tmp/killrchat_cassandra/data/tmp/killrchat_cassandra/commitlog/tmp/killrchat_cassandra/saved_cachesYou can change those default values in the src/main/resources/config/application.properties file.Then connect to the chat by opening your browser athttp://localhost:8080/killrchat/index.html.Production modeTo run the application in the production mode:killrchat> mvn clean testkillrchat> mvn spring-boot:run -PprodWhen running the application in prod mode, Achilles will connect to an existing Cassandra server. You canconfigure the server host and port in the the src/main/resources/config/application.properties file.By default Achilles will execute the src/main/resources/cassandra/schema_creation.cql script to create thekillrchat keyspace and appropriate tables.Then connect to the chat by opening your browser athttp://localhost:8080/killrchat/index.html.To deploy the application in multiple back-end servers, you will need to reconfigure the messaging system in theChatRoomResource and MessageResource. For the hand's on, we use an in-memory messaging system but forproduction you'd probably want to plugin a distributed messaging broker like RabbitMQ.Packaging the applicationTo package KillrChat and build a stand-alone Java jar archive, type mvn package. It will generate akillrchat-1.0.war file in the target folderTo run the application in development mode:> java -jar killrchat-1.0.war --spring.profiles.active=dev -Dlogback.configurationFile=logback_dev.xmlTo run the application in production mode:> java -jar killrchat-1.0.war --spring.profiles.active=prod -Dlogback.configurationFile=logback_prod.xmlThe data model for chat room message is still not perfect because it is a wide row. Typically the partition will growover time and performance will suffer.The solution is to use bucketing techniques but it is an advanced data modelling topic, far beyond the goal ofthis hands-on.Alternatively, we can use the DateTieredCompactionStrategy to make reading recent messages faster.

Illustration Image

README.md

A hand's on exercise for Cassandra 2.1.

This hands-on will make you, step by step with unit tests, create a working chat application using

The hands-on will focus on the data modelling part, you need to:

  1. understand the data model (tables)
  2. implement the services to make the tests pass using Achilles

All the front-end, as well as the REST resource and all Spring configuration config and other glue code is provided as a convenience so that participants can focus solely on the data modelling and service layer.

For object mapping, we use Achilles which provides many tools to make development more effective and easier. We'll use the JUnit rule support from Achilles to start an embedded Cassandra in memory for unit testing.

Once all the exercises are done, we can have some fun using the real chat!

If you're not familiar with Cassandra, please take a look at the introduction slides

For a presentation of KillrChat, look at the slides here

Warning! You'll need a recent and decent browser (no IE8) to make the chat front-end work: IE10, Chrome, FireFox ...

Warning! You should have Maven and Java (1.7+) installed and functionnal, other component will be installed automatically

First clone the repository with git clone https://github.com/doanduyhai/killrchat.git Then enter the folder cd killrchat

Development mode

To run the application in the development mode:

killrchat> mvn clean test
killrchat> mvn spring-boot:run -Pdev

When running the application in dev mode, Achilles will start an embedded Cassandra server and create the following data folders:

  1. /tmp/killrchat_cassandra/data
  2. /tmp/killrchat_cassandra/commitlog
  3. /tmp/killrchat_cassandra/saved_caches

You can change those default values in the src/main/resources/config/application.properties file.

Then connect to the chat by opening your browser at http://localhost:8080/killrchat/index.html.

Production mode

To run the application in the production mode:

killrchat> mvn clean test
killrchat> mvn spring-boot:run -Pprod

When running the application in prod mode, Achilles will connect to an existing Cassandra server. You can configure the server host and port in the the src/main/resources/config/application.properties file. By default Achilles will execute the src/main/resources/cassandra/schema_creation.cql script to create the killrchat keyspace and appropriate tables.

Then connect to the chat by opening your browser at http://localhost:8080/killrchat/index.html.

To deploy the application in multiple back-end servers, you will need to reconfigure the messaging system in the ChatRoomResource and MessageResource. For the hand's on, we use an in-memory messaging system but for production you'd probably want to plugin a distributed messaging broker like RabbitMQ.

Packaging the application

To package KillrChat and build a stand-alone Java jar archive, type mvn package. It will generate a killrchat-1.0.war file in the target folder

To run the application in development mode:

> java -jar killrchat-1.0.war --spring.profiles.active=dev -Dlogback.configurationFile=logback_dev.xml

To run the application in production mode:

> java -jar killrchat-1.0.war --spring.profiles.active=prod -Dlogback.configurationFile=logback_prod.xml

The data model for chat room message is still not perfect because it is a wide row. Typically the partition will grow over time and performance will suffer.

The solution is to use bucketing techniques but it is an advanced data modelling topic, far beyond the goal of this hands-on.

Alternatively, we can use the DateTieredCompactionStrategy to make reading recent messages faster.

Related Articles

spring
angular
rest

GitHub - jhipster/jhipster-sample-app-cassandra: This is a sample application created with JHipster, with the Cassandra option

jhipster

3/7/2024

cassandra
github

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

angular