Skip to content

pestades/akka-persistence-POC

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Quick Start

Use ccm to start a Cassandra cluster.

Get ccm from https://github.com/pcmanus/ccm. Follow the instructions to install.

On Mac OS X you may need to:

sudo ifconfig lo0 alias 127.0.0.2 up
sudo ifconfig lo0 alias 127.0.0.3 up

Create a test cluster:

ccm create test -v 3.0.8 -n 3 -s

Run the command side of the application: $sbt run and select WriteApp

Initialize an order:

curl -H "Content-Type: application/json" -X POST http://localhost:8080/order/initialize -d '{"idOrder":"1", "idUser": 42}'

Cancel the order:

 curl -H "Content-Type: application/json" -X POST http://localhost:8080/order/cancel -d '{"idOrder":"1", "idUser": 42}'

Note that if you try to cancel the order again, you'll get a rejection message.

{"message":"command rejected"}

Connect to Cassandra using cqlsh.

$ ccm node1 cqlsh

Issue the following commands:

Connected to test at 127.0.0.1:9042.
[cqlsh 5.0.1 | Cassandra 3.0.8 | CQL spec 3.4.0 | Native protocol v4]
Use HELP for help.
cqlsh> USE akka;
cqlsh:akka> SELECT persistence_id, sequence_nr, ser_manifest, blobastext(event) AS event FROM messages;

 persistence_id | sequence_nr | ser_manifest                            | event
----------------+-------------+-----------------------------------------+-----------------------------
              1 |           1 | poc.persistence.events.OrderInitialized | {"idOrder":"1","idUser":42}
              1 |           2 |   poc.persistence.events.OrderCancelled | {"idOrder":"1","idUser":42}

(2 rows)
cqlsh:akka>

Now run the read side of the application: $sbt run and select ReadApp

Issue the following curl commands:

$ curl -X GET http://localhost:8080/users/42

You should see this:

{"history":[{"UserInitializedOrder":{"idOrder":"1","idUser":42}},{"UserCancelledOrder":{"idOrder":"1","idUser":42}}]}

Go into cqlsh again. You should see this.

$ ccm node1 cqlsh
Connected to test at 127.0.0.1:9042.
[cqlsh 5.0.1 | Cassandra 3.0.8 | CQL spec 3.4.0 | Native protocol v4]
Use HELP for help.
cqlsh> USE akka;
cqlsh:akka> SELECT persistence_id, sequence_nr, ser_manifest, blobastext(event) AS event FROM messages;

 persistence_id | sequence_nr | ser_manifest                                                   | event
----------------+-------------+----------------------------------------------------------------+-----------------------------
              1 |           1 |                        poc.persistence.events.OrderInitialized | {"idOrder":"1","idUser":42}
              1 |           2 |                          poc.persistence.events.OrderCancelled | {"idOrder":"1","idUser":42}
 stream-manager |           1 | poc.persistence.read.streammanager.events.ProgressAcknowledged |         {"i":1481825522840}
 stream-manager |           2 | poc.persistence.read.streammanager.events.ProgressAcknowledged |         {"i":1481825526154}
             42 |           1 |          poc.persistence.read.user.events.UserInitializedOrder | {"idOrder":"1","idUser":42}
             42 |           2 |            poc.persistence.read.user.events.UserCancelledOrder | {"idOrder":"1","idUser":42}

(6 rows)
cqlsh:akka>

Done!

You can always remove the test Cassandra cluster in ccm by writing:

ccm remove test

Running a Cluster

Run

$ sbt universal:packageBin

This produces a zip file.

$ cd target/universal
$ unzip akka-persistence-poc-2.4.4.zip

This produces an executable file under ./akka-persistence-poc-2.4.4/bin

Run the seed node:

$ ./akka-persistence-poc

Run two more nodes:

$ ./akka-persistence-poc -Dclustering.port=2552 -Dweb.port=8081
$ ./akka-persistee-poc -Dclustering.port=2553 -Dweb.port=8082

About

POC akka-persistence CQRS

Resources

License

Unknown, CC0-1.0 licenses found

Licenses found

Unknown
LICENSE
CC0-1.0
COPYING

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Scala 100.0%