LogicalTime / Akka-Persistence-example-with-Protocol-Buffers-serialization

A simple example that demonstrates the usage of Akka Persistence along with Protocol Buffers as the serialization mechanism

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Akka Persistence example with Protocol Buffers serialization

Build Status

Build Status

Overview

This example uses ScalaPB in order to obtain case class support for Scala when generating code from *.proto files. This project also makes use of protoc-jar in order to keep a self-contained project without posing any requirements on the user of having the Protocol Buffer compiler on their system.

Execute sbt run in order to run the Main application. The Calculator actor is used to persist events across runs using Event Sourcing. We define a custom serializer that makes use of the generated class' (from proto) serialization mechanisms to easily serialize and deserialize events.

Unfortunately, you cannot compile through IntelliJ so sbt compile will have to do.

The Main application fires events at the Calculator actor. Since Calculator actor is Persistent, it makes use of the Serializer (set up in application.conf) when reading and persistent events to/from the event journal.

We also have a test that exercises the Persistent Calculator Actor by sending it events, killing it and making sure it uses Event Sourcing to bring the Calculator up to the current state. You can use sbt test to run the test.

If you are using IntelliJ and want syntax highlighting, then make sure your directory setup looks like this: image

External Libraries

  • ScalaPB is used to generate Scala case classes from proto files. These case classes have the ability to convert to and from binary
  • Protoc is used to remove the dependency of making sure the user has the Protocol Buffers compiler
  • Akka for its actor framework, persistence module and test kit

Warning: Make sure you have Python 2.7 installed (accessible via python) otherwise the protocol buffers compiler will give you errors and will not compile your project

About

A simple example that demonstrates the usage of Akka Persistence along with Protocol Buffers as the serialization mechanism


Languages

Language:Scala 93.6%Language:Protocol Buffer 6.4%