The application is a simple webshop that is build with the following stack:
- Akka
- Spray
- AngularJS
- Twitter Bootstrap
- Execute
./bin/activator ui
- Activator is a web-ide. Write code, compile it, run tests, run the application or generate files for your favourite IDE.
- To start the application click on Run and then Start
- Open a browser using the following url:
http://localhost:8080/
- From there all endpoints of the REST interface can be called using the gui
- Execute
./bin/sbt.sh
- Type
run
- Open a browser using the following url:
http://localhost:8080/
- From there all endpoints of the REST interface can be called using the gui
- Execute
./bin/sbt.sh assembly
. This will create an executable jar intarget/scala-2.11
- Run the server as follows:
java -jar xita-innovationday-assembly-<version>.jar
Note: Since it's a shopping cart the REST API is session-based. The name of the session cookie is session-id.
- Add an item to the shopping cart:
curl -b session-id=12121212 -d '{"itemId":"dell-venue"}' -H "Content-Type: application/json" http:localhost:8080/cart
- Retrieve shopping cart contents:
curl -b session-id=12121212 http://localhost:8080/cart
- Remove an item from the shopping cart:
curl -b session-id=12121212 -X "DELETE" http://localhost:8080/cart?itemId=dell-venue
- Place order
curl -b session-id=12121212 -X "PUT" http://localhost:8080/order
##Labs
###Lab 1: git checkout lab1
- Starting point: Web UI & Spray Rest API voor shopping cart manipulations. The Carts Manager Actor and Cart Actor are not implemented
- Lab 1: Implement the
com.xebia.openkitchen.cart.CartManagerActor
that handlescom.xebia.openkitchen.cart.CartManagerActor.Envelope
messages received from the Spray route:com.xebia.openkitchen.api.Api
. Per session theCartManagerActor
has to create a Cart Actor. To achieve that use theEnvelope
's session id to create or get a Cart Actor using the Props passed as a constructor argument. The payload of theEnvelope
needs to be forwarded to the Cart Actor. As for now use a Dummy implementation for the Cart Actor. - Make the following test succeed:
com.xebia.openkitchen.cart.CartMangerActorSpec
###Lab 2 git checkout lab2
- Starting point: Implementation of the Carts Manager Actor (
CartManagerActor
). The Cart Actor is not implemented. - Lab 2: Implement the
com.xebia.openkitchen.cart.SimpleCartActor
that keeps the cart data in-memory. To see which operations this Actor must support take a look at the Spray route:com.xebia.openkitchen.api.Api
, which sends the payload intended for the Cart Actor wrapped in anEnvelope
. As mentioned in the previous lab the Cart Actor only has to handle the payload message (likecom.xebia.openkitchen.cart.CartDomain.AddToCartRequest, RemoveFromCartRequest, GetCartRequest, OrderRequest
) and not the wholeEnvelope
message. - Make the following test succeed:
com.xebia.openkitchen.cart.SimpleCartActorSpec
###Lab 3 git checkout lab3
- Starting point: Implementation of an in-memory Cart Actor (
SimpleCartActor
) - Lab 3: Implement the
com.xebia.openkitchen.cart.PersistentCartActor
, which makes use of Event Sourcing (Akka persistence) to persist all cart events. - For testability add each succesfully persisted
Event
to the eventStream using the predefinedpublish
method. - Change the Props passed to the
CartManagerActor
incom.xebia.openkitchen.api.WebshopActor
to return an instance ofPersistentCartActor
. - Make the following tests succeed: Lab 3 of
com.xebia.openkitchen.cart.PersistentCartActorSpec
###Bonus Lab 4 git checkout lab4
- Starting point: Implementation of a persistent Cart Actor (
PersistentCartActor
) - Lab 4: Extend the
com.xebia.openkitchen.cart.PersistentCartActor
to make use of: passivation and snapshotting - Implement a receiveTimeout (e.g. 10 seconds). Upon receival of the
akka.actor.ReceiveTimeout
message take a snapshot (saveSnapshot
) of the current cart - After the snapshot is saved Akka persistence sends a
akka.persistence.SaveSnapshotSuccess
orakka.persistence.SaveSnapshotFailure
message to the actor. In both cases: set the message on the message bus for testability, then kill the actor - When the actor recovers
receiveRecover
receives aakka.persistence.SnapshotOffer
. Make sure it is processsed correctly - Make the following test succeed: Bonus Lab 4 of
com.xebia.openkitchen.cart.PersistentCartActorSpec
###Solution git checkout final-solution
- Final solution with the
com.xebia.openkitchen.cart.PersistentCartActor
that supports snapshotting en passivation