What is Akka.NET?
• Akka.NET is a framework and runtime for building highly concurrent, distributed, and fault tolerant event-driven applications on .NET & Mono
• Community driven .NET port of the Java/Scala Akka framework
• Open Source (Apache 2 License)
• 1.0 version released (stable API)
• Commercial training, consulting & support available from
Actors
• Akka.NET is based on the Actor Model paradigm
• All work in an actor model system is executed by Actors
• An Actor is a single threaded entity that acts upon received messages• Event driven (non-blocking async messaging using a “mailbox”)• Akka.NET takes care of threading (state is private)• Lightweight (millions of actors per GB of heap memory)• Location transparency
Configuration
• Actors are configured using HOCON• Human Optimized Configuration Object Notation
• JSON like structure
• Can be specified in code (parsed from a string) or in the .config file in a CDATA block
Actor hierarchy
• All actors live within an ActorSystem• A process can host multiple actorsystems
• Within the ActorSystem the actors form a hierarchical structure• Supervision• Fault tolerance
• Each actor is addressable using an ActorPath:• Local: /user/a1/b1/c2• Remote: akka.tcp://my-system@localhost:9999/user/a2/b3
ActorSystem Address PathProtocol
Supervision
• Each parent actor supervises his childactors• Isolate failure
• The configured SuperVision Strategydictates how an actor deals with a failure in a child actor• OneForOne - only the failed child is impacted• AllForOne - all children are impacted
• Based on the exception type, a certain action is taken:• Resume, Restart, Stop, Escalate
Communicating with Actors
• An actor is used through an ActorReference• Returned when creating an Actor
• Can be passed around
• Shields internal state
• An actor can be looked-up using an ActorSelection• Address the actor using an ActorPath (both locally as remote)
• Path can be relative (../b2)
• Path can contain wildcards (multicast)
Communicating with Actors
• Messages are POCO’s• Immutable
• Akka.Net offers at-most-once message delivery• So message delivery is not guaranteed!• Use explicit acks / nacks when guaranteed delivery is necessary• At-least-once semantics is possible through Akka.Persistence
Location transparency
• An Actor can be created in the local process or in a remote process• On the same machine of across a network on another machine
• Akka.Remote plugin
• Only the address is different, programming model is the same
• Deployment of an actor can be configured
• Different protocols available for communication• TCP
• UDP
• Your own
Actor Persistence
• Actors can be made persistent• Akka.Persistence plugin
• Preview version
• Based on the Event Sourcing mechanism• Journal for events that have occurred
• SnapShots for “roll-up” of events to a certain point in time
• Storage can be configured separately for Journal and Snapshot• Default: In Memory / Disk
• Contrib: SQL Server / MongoDB / Sql Lite / Event Store / Azure / … / Your Own
Akka.NET - 101
• This session just barely scratches the surface of the possibilities of Akka.NET
• See the documentation for more information:http://getakka.net/
• Do the Akka.NET bootcamp: https://github.com/petabridge/akka-bootcamp
Host Process
Store Actor
WarehouseActorSystem
Demo application - Actors
Inventory Actor
Backorder Actor
Sales Actor
InventoryActor
InventoryActor
Scanner Actor
Creates Finds
/user/store
/user/store/scanner/user/store/inventory
/user/store/inventory/backorder
/user/sales
Demo application - ActorsStore Actor
Scanner Actor
Scanner Actor
Scanner Actor
Inventory Actor
Backorder Actor
Sales Actor
Create
Create
Look up
Create
PurchaseProduct
ScanningCompleted[scannedItems >= minimalAmountRequired]
SellProduct
BackorderProduct[stock < amount]
DumpBackorders
DumpSales
ScanItem
ScanItem
[scannedItems < minimalAmountRequired]
Host
Host ProcessHost Process
Store Actor
Warehouse ActorSystem
Demo application - Remoting
Inventory Actor
Backorder Actor
InventoryActor
InventoryActor
Scanner Actor
Sales ActorSystem
Sales Actor
akka.tcp://sales@localhost:9999
Creates Finds
/user/sales/user/store
/user/store/scanner/user/store/inventory
/user/store/inventory/backorder
Host ProcessHost Process
Store Actor
Warehouse ActorSystem
Demo application - Persistence
Inventory Actor
Backorder Actor
InventoryActor
InventoryActor
Scanner Actor
Sales ActorSystem
Sales Actor
akka.tcp://sales@localhost:9999
Creates Finds
/user/sales/user/store
/user/store/scanner/user/store/inventory
/user/store/inventory/backorder
Journal