This repository contains an Akka kata that can be used whenever you feel like doing some Akka Karate related training.
- A computer
- An installed OS
- Java
- Maven
- Git (not mandatory)
So you decided to install Git (or already had it installed). Smart move! Open a terminal and type:
> git clone git://github.com/henrikengstrom/akka-kata-java.git
Open a browser and point it to:
https://github.com/henrikengstrom/akka-kata-java/archive/master.zip
Select your preferred flavor of compression (zip or tar.gz), download and extract onto your machine.
To compile the project with Maven:
> mvn compile
Since it is a multi-module project with dependencies between the modules you need to install the jar files in the local maven repository before running.
> mvn install
See Eclipse Guide
Open IntelliJ, select File
-> Open Project…
and point to the root pom.xml in the project (i.e. the akka-kata-java/pom.xml
file).
The aim with this kata is to show some core elements of Akka:
- Remoting
- Supervision
- Some Akka patterns
To showcase the elements above we have selected to implement a simple betting application - or at least provide a skeleton of such an application. The implemented application should simulate a transacted system, i.e. it should handle a crash of a JVM. We will discuss pros and cons of alternative implementations during the meetup.
The application you create will run in two different JVMs (and actor systems). One "node", called betting service, receives bet messages from a client, creates a transaction number and sends this message to the other "node" betting processor. The betting service keeps track of messages sent and should also handle confirmation messages from the betting processor. It also handles re-sending of messages that have not been confirmed.
The task of the betting processor is to spawn workers that do the dangerous job (in this case interacting with an unstable service), supervise these workers and send back confirmation that a task has been performed.
The betting service should be able to function without any available betting processor, i.e. should it receive bet(s) before the betting processor has registered it should keep these bets locally and send them as soon as a betting processor becomes available.
Sometimes your servers crash(!) and therefore you should design with this in mind. Sending too many bets to the betting processor will cause it (the JVM) to crash. It is an essential part of this kata to make sure that the betting service can handle such a crash.
We will provide some alternative implementations to show how to solve the different tasks/assignments raised in the code (see comments in provided code).
You should run the service, processor and client in that order to make sure that this kata runs as intended.
Start the service
> cd <project_home>/service
> mvn exec:java -Dexec.mainClass="com.typesafe.akkademo.service.BettingServiceApplication"
The next step is to start the processor
> cd <project_home>/processor
> mvn exec:java -Dexec.mainClass="com.typesafe.akkademo.processor.BettingProcessorApplication"
Finally you should run the client. Start off by sending bets to the service
> cd <project_home>/client
> mvn exec:java -Dexec.mainClass="com.typesafe.akkademo.client.BetClient" -Dexec.args="send"
The final step is to retrieve the bets from the service
> cd <project_home>/client
> mvn exec:java -Dexec.mainClass="com.typesafe.akkademo.client.BetClient"
Remember to clean out the persistent store of bets in between runs of your system. It is stored in the file persistent_store
in the top level project directory.
That's it!
For a small collection of akka information useful for this kata see Green Belt Akka
When you feel that you have accomplished all tasks specified in the code there is a solution proposal to be found in a branch called solution. We recommend that you try to solve the kata before looking at this proposal though.
- Henrik Engström : @h3nk3
- Björn Antonsson : @bantonsson