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:
- understand the data model (tables)
- 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
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:
/tmp/killrchat_cassandra/data
/tmp/killrchat_cassandra/commitlog
/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.
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.
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
- Exercise 1: manage accounts
- Exercise 2: manage chat rooms
- Exercise 3: manage participants joining and leaving rooms
- Exercise 4: manage chat messages
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.