A hand's on exercise for Cassandra 2.1
This hands-on will make you, step by step with TDD, create a working chat application using
The hands-on will focus on the data modelling part, you need to
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 !
Warning! You'll need a recent and decent browser (no IE8) to make the chat front-end work: IE10, Chrome, FireFox ...
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:
You can change those default values in the src/main/resources/config/application.yml
file
Then connect to the chat by opening your browser at http://localhost:8080/killrchat/index.html
To run the application in the production mode:
killrchat> mvn clean test killrchat> mvn spring-boot:run -Pprod
When running the application in dev 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.yml
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.
To package KillrChat and build a stand-alone Java jar archive, type mvn package
. It will generate
a killrchat-1.0.jar file in the target
folder
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.