SlideShare a Scribd company logo
CREATING SCALABLE MESSAGE-
DRIVEN SOLUTIONS
(WITH AKKA.NET)
David Hoerster
ABOUT ME
5-Time .NET (Visual C#) MVP (April 2011)
Sr. Solutions Architect at Confluence
One of the organizers for Pittsburgh TechFest (http://pghtechfest.com)
Organizer of Pittsburgh Reactive Dev Group (http://meetup.com/reactive)
Past President of Pittsburgh .NET Users Group
Twitter - @DavidHoerster
Blog – http://blog.agileways.com
Email – david@agileways.com
AGENDA
Messages as Part of Application Design
Being Reactive
What the Actor Model Provides
Hello Akka.NET
Working with Akka.NET
Cross-Process Actor Systems (Akka.Remote)
CQRS
Command Query Responsibility Segregation
 Coined by Greg Young
Evolution of CQS (Command Query Separation)
 Coined by Bertrand Meyer
Both revolve around the separation of writes (command) and reads
(query)
CQS is more at the unit level
CQRS is at the bounded context level, or so
MESSAGES
The core of CQRS  Messages
Communication from the service layer to the domain via commands
 Command handlers could also update the underlying repository
As actions happen, events are raised
Event handlers could issue other commands
Event handlers could update the underlying repository
MESSAGES
Regardless of how it’s implemented, communication between
application parts is via messages
Not only helps communicate intent of the action
 “PublishWidget”, “ExpireWorkItem”, “UpdateDefinition”, “DefinitionUpdated”
But allows for remote handling of messages
 Queue, REST payload, etc.
MESSAGES ARE KEY TO BEING
REACTIVE
SO?
So how does this affect my system design?
Let’s consider some procedural pitfalls
WORD COUNTER EXAMPLE
Simple program to count the occurrences of words in a document
Print out the top 25 words and their counts at the end
Can be accomplished easily via procedural code
WORD COUNTER EXAMPLE
WORD COUNTER EXAMPLE
What if you wanted to spread out the counting load?
What if you wanted to scale out to other nodes/processes/machines?
Fault tolerance, concurrent actions, etc.?
BUILDING CONCURRENT APPS
In word counter, may need to spawn some threads
Lock some critical sections, etc.
The system becomes responsible for knowing everything going on
 Very Proactive (not Reactive!) system
SIDE NOTE: REACTIVE VS.
PROACTIVE
Isn’t proactive a good thing?
A system taking upon itself to
check state is proactive
 It’s doing too much
A reactive system reacts to
events that occur
 It’s doing just the right amount
SIDE NOTE: REACTIVE VS.
PROACTIVE
Isn’t proactive a good thing?
A system taking upon itself to
check state is proactive
 It’s doing too much
A reactive system reacts to
events that occur
 It’s doing just the right amount
System
EvtEvt
System
EvtEvt
Proactive
Reactive
REAL WORLD SCENARIO
Loosely structured data
Multiple files to combine
Operations to perform during the projection process
REAL WORLD SCENARIO
File File File
Join
Op
Join/
End
REAL WORLD SCENARIO
Number of “steps”
May need some sub-steps
Can be broken down into individual pieces
 Actors
Communicate via messages for loose coupling
REAL WORLD SCENARIO
Actually looks like this:
Multiple sources
Several transforms
Several joins
Configurable
ACTOR MODEL
Actor Model is a system made of small units of concurrent
computation
 Formulated in the early 70’s
Each unit is an actor
Communicates to each other via messages
Actors can have children, which they can supervise
WHAT IS AN ACTOR?
Class that encapsulates state and behavior
 State can be persisted (Akka.Persistence)
 Behavior can be switched (Become/Unbecome)
Has a mailbox to receive messages
 Ordered delivery by default
 Queue
Can create child actors
Has a supervisory strategy for child actors
 How to handle misbehaving children
Are always thread safe
Have a lifecycle
 Started, stopped, restarted
AKKA.NET
Akka.NET is an open source framework
Actor Model for .NET
Port of Akka (for JVM/Scala)
http://getakka.net
NuGet package – search for Akka.Net (not the first result usually!)
STARTING WITH AKKA.NET
Akka.NET is a hierarchical system
Root of the system is ActorSystem
Expensive to instantiate – create and hold!
ActorSystem can then be used to create Actors
CREATING AN ACTOR
An Actor has a unique address
Can be accessed/communicated to like a URI
Call ActorOf off ActorSystem, provide it a name
 URI (actor path) is created hierarchically
Actor Path = akka://myName/user/announcer
SENDING A MESSAGE
Messages are basis of actor communication
 Should be IMMUTABLE!!!
“Tell” an actor a message
Async call
 Immutable!!
RECEIVING A MESSAGE
Create your Actor
Derive from ReceiveActor
In constructor, register your
message subscriptions
RECEIVING A MESSAGE
Each actor has a mailbox
Messages are received in the actor’s mailbox (queue)
Actor is notified that there’s a message
 It receives the message
 Takes it out of the mailbox
 Next one is queued up
Ordered delivery by default
 Other mailboxes (like Priority) that are out-of-order
Actor
Mailbox
Msg
HELLO AKKA.NET Demo
CREATING CHILDREN
Best to call ActorOf to get an IActorRef
Create a static Props creator
Actor path is relative to parent’s actor path
 akka://myDemo/user/countChocula/{childName}
When creating a child, good idea to name it
 So you can reference it later!
WORD COUNTER WITH ACTORS
Program sends StartCount message to CountSupervisor
CountSupervisor, for each line, sends line to one of 5 LineCounterActors
(ReadLineForCounting message)
LineCounterActor counts the word in that line
Tells the Sender (CountSupervisor) the results (MappedList message)
CountSupervisor aggregates results of MappedList messages
When all lines complete, CountSupervisor sends each LineActor a Complete
message
LineCounterActor cleans up and sends CountSupervisor Complete
When all LineCounterActors are Complete, CountSupervisor prints out top 25
words
MAP-REDUCE DEMO
ROUTING
Map Reduce example used Round Robin
There are others OOTB
 Broadcast
 Random
 Consistent Hashing (used by Cluster)
 Smallest Mailbox
 More
Pools and Groups
 Pools are more anonymous
 Groups are pre-created
FINDING CHILDREN
Within an actor, call Context.Child with the name of the child actor
If not found, ActorRefs.Nobody is returned
If found, you have an IActorRef to work with
Using ActorSelection doesn’t guarantee actor is initialized
MORE COMPLEX ACTOR DEMO
baseball
gameCoo
rdinator
gameInfo
-x
gameInfo
-y
playerSup
ervisor
batter-abatter-bbatter-c
c-01 c-11 c-32
INTEGRATION
Integration with other systems is simple
Best to encapsulate in its own actor
Contain any errors there
 Prevent affecting parts of the system further upstream
ASYNC
Actors have messages delivered to them in order via a Mailbox
As message is received, handed to Actor to process
Messages in mailbox queue up
As a result, async processing of messages isn’t possible
 Receive<> (async msg => { … }) doesn’t work
If you need to perform async tasks within Receive
 PipeTo(Self) usually does the trick
 Re-queues message back on Mailbox
 When delivered, actor resumes
Actor
Mailbox
Msg
PipeTo
ACTORS ACROSS PROCESSES
Akka.Remote module
Configure via HOCON
 Human Optimized Configuration Object Notation
Allows an actor system to distribute messages to actors across
processes
Location transparency!!
ACTORS ACROSS PROCESSES
baseball
gameCoor
dinator
gameInfo
-x
gameInfo
-y
playerSup
ervisor
batter-abatter-bbatter-c
eventSupe
rvisor
batter-a batter-b
c-01 c-11 c-32
atBatWrite
r
ACTORS ACROSS PROCESSES
Actor Path modified
 akka.tcp://localhost:50000@{system}/user/{supervisor}/{name}
Protocol and location added to actor path
Protocol defaults to tcp, but you can provide your own
Actor path above is remote path
AKKA.REMOTE DEMO
ELASTICITY WITH ACTORS
Akka.Cluster
Multiple nodes of an actor system acting as one
Allows for failure
Can also expand out for performance
SAVING ACTOR STATE
Akka.Persistence
Persist each message (or snapshots) to storage
Like event sourcing
Rehydrate actor state after failure or for whatever reason
ASKING AN ACTOR
Wait for a response from an actor
Somewhat of an anti-pattern for Actor Model
If used, use sparingly
HANDLING ERRORS
An exception during processing with a classic app could crash the
whole system
An exception within a child actor is isolated
IS AKKA.NET…?
Pub/Sub?
 No, but it could be
Message Bus, like RabbitMQ or MassTransit
 Uses messages to communicate
 Message bus concerned with building a distributed system topology
Storm, ETL/ELT, etc.?
 Kind of
 Can build system like that with Akka.NET
RESOURCES
http://getakka.net
Petabridge blog
https://petabridge.com/blog/
Gitter
https://gitter.im/akkadotnet/akka.net
https://gitter.im/petabridge/akka-bootcamp

More Related Content

What's hot (17)

PDF
Distributed Deep Learning with Docker at Salesforce
Docker, Inc.
 
PPTX
Discovering the Service Fabric's actor model
Massimo Bonanni
 
PDF
I Am MongoDB – And So Can You!
MongoDB
 
PDF
Building and running Spring Cloud-based microservices on AWS ECS
Joris Kuipers
 
PDF
Reactive java - Reactive Programming + RxJava
NexThoughts Technologies
 
PPTX
Introduction to Akka.NET and Akka.Cluster
petabridge
 
PDF
Empower every Azure Function to achieve more!!
Massimo Bonanni
 
PDF
Serverless in production, an experience report (NDC London 2018)
Yan Cui
 
PDF
Intro to elixir and phoenix
Jared Smith
 
PDF
Durable Functions vs Logic App : la guerra dei workflow!!
Massimo Bonanni
 
PDF
MongoDB .local Houston 2019: REST-less Mobile Apps: Why Offline-first and Syn...
MongoDB
 
PDF
Deployment - Done Right!
Eberhard Wolff
 
PPTX
What is Docker?
Shubhrank Rastogi
 
PDF
Microservices pros and cons - houston tech fest
Andrew Siemer
 
PDF
Serverless in production, an experience report (London js community)
Yan Cui
 
PDF
There is No Server: Immutable Infrastructure and Serverless Architecture
Sonatype
 
PDF
Stateful patterns in Azure Functions
Massimo Bonanni
 
Distributed Deep Learning with Docker at Salesforce
Docker, Inc.
 
Discovering the Service Fabric's actor model
Massimo Bonanni
 
I Am MongoDB – And So Can You!
MongoDB
 
Building and running Spring Cloud-based microservices on AWS ECS
Joris Kuipers
 
Reactive java - Reactive Programming + RxJava
NexThoughts Technologies
 
Introduction to Akka.NET and Akka.Cluster
petabridge
 
Empower every Azure Function to achieve more!!
Massimo Bonanni
 
Serverless in production, an experience report (NDC London 2018)
Yan Cui
 
Intro to elixir and phoenix
Jared Smith
 
Durable Functions vs Logic App : la guerra dei workflow!!
Massimo Bonanni
 
MongoDB .local Houston 2019: REST-less Mobile Apps: Why Offline-first and Syn...
MongoDB
 
Deployment - Done Right!
Eberhard Wolff
 
What is Docker?
Shubhrank Rastogi
 
Microservices pros and cons - houston tech fest
Andrew Siemer
 
Serverless in production, an experience report (London js community)
Yan Cui
 
There is No Server: Immutable Infrastructure and Serverless Architecture
Sonatype
 
Stateful patterns in Azure Functions
Massimo Bonanni
 

Viewers also liked (20)

PPTX
Reactive Development: Commands, Actors and Events. Oh My!!
David Hoerster
 
PPTX
CQRS Evolved - CQRS + Akka.NET
David Hoerster
 
PPTX
Drm and the web
Anthony Brown
 
PDF
Building Skynet: Machine Learning for Software Developers
Anthony Brown
 
PDF
Streaming ETL With Akka.NET
petabridge
 
PDF
Distributed Transactions in Akka.NET
petabridge
 
PPTX
From Zero to the Actor Model (With Akka.Net) - CodeMash2017 - Tamir Dresher
Tamir Dresher
 
PPTX
Akka.net versus microsoft orleans
Bill Tulloch
 
PPTX
CQRS and Event Sourcing, An Alternative Architecture for DDD
Dennis Doomen
 
PDF
Der perfekte Microservice
OPEN KNOWLEDGE GmbH
 
PPTX
F# Type Provider for R Statistical Platform
Howard Mansell
 
PDF
CQRS basierte Architekturen mit Microservices
Michael Plöd
 
PPTX
Building responsive applications with Rx - CodeMash2017 - Tamir Dresher
Tamir Dresher
 
PDF
ASP.NET MVC Web API -twMVC#8
twMVC
 
PPTX
Owin and-katana-overview
sonia merchant
 
PPTX
Owin e katana
Tanato Cartaxo
 
PPTX
ASP.NET Web API O to 100
Himanshu Desai
 
PPTX
Moving forward with ASP.NET Core
Enea Gabriel
 
PPTX
Declarative authorization in REST services in SharePoint with F# and ServiceS...
Sergey Tihon
 
Reactive Development: Commands, Actors and Events. Oh My!!
David Hoerster
 
CQRS Evolved - CQRS + Akka.NET
David Hoerster
 
Drm and the web
Anthony Brown
 
Building Skynet: Machine Learning for Software Developers
Anthony Brown
 
Streaming ETL With Akka.NET
petabridge
 
Distributed Transactions in Akka.NET
petabridge
 
From Zero to the Actor Model (With Akka.Net) - CodeMash2017 - Tamir Dresher
Tamir Dresher
 
Akka.net versus microsoft orleans
Bill Tulloch
 
CQRS and Event Sourcing, An Alternative Architecture for DDD
Dennis Doomen
 
Der perfekte Microservice
OPEN KNOWLEDGE GmbH
 
F# Type Provider for R Statistical Platform
Howard Mansell
 
CQRS basierte Architekturen mit Microservices
Michael Plöd
 
Building responsive applications with Rx - CodeMash2017 - Tamir Dresher
Tamir Dresher
 
ASP.NET MVC Web API -twMVC#8
twMVC
 
Owin and-katana-overview
sonia merchant
 
Owin e katana
Tanato Cartaxo
 
ASP.NET Web API O to 100
Himanshu Desai
 
Moving forward with ASP.NET Core
Enea Gabriel
 
Declarative authorization in REST services in SharePoint with F# and ServiceS...
Sergey Tihon
 
Ad

Similar to Creating scalable message driven solutions akkadotnet (20)

PDF
Take a Look at Akka+Java (English version)
GlobalLogic Ukraine
 
PDF
Actor Model Akka Framework
Harinath Krishnamoorthy
 
PPTX
Akka Actors
Dylan Forciea
 
PDF
Akka-intro-training-public.pdf
BernardDeffarges
 
PPTX
Oop2011 actor presentation_stal
Michael Stal
 
PDF
Introduction to concurrent programming with akka actors
datamantra
 
PDF
Introduction to concurrent programming with Akka actors
Shashank L
 
PDF
Introduction to Akka
Knoldus Inc.
 
PPTX
Reactive Programming using Actor Model in Akka
StephenKoc1
 
PDF
Akka in Action: Heiko Seeburger
JAX London
 
PPTX
Akka.Net Ottawa .NET User Group Meetup
Taswar Bhatti
 
PDF
Sharing-akka-pub
Hendri Karisma
 
PDF
Akka - A Brief Intro
Thomas Lockney
 
PPTX
Introduction to Akka - Atlanta Java Users Group
Roy Russo
 
ODP
Reactive programming with scala and akka
Knoldus Inc.
 
PDF
Reactive programming with akka
Sovon Nath
 
PDF
Reactive Programming in Akka
DevFest DC
 
PDF
Introducing Akka
Meetu Maltiar
 
PPTX
Akka in-action
Raymond Roestenburg
 
PDF
Akka (1)
Rahul Shukla
 
Take a Look at Akka+Java (English version)
GlobalLogic Ukraine
 
Actor Model Akka Framework
Harinath Krishnamoorthy
 
Akka Actors
Dylan Forciea
 
Akka-intro-training-public.pdf
BernardDeffarges
 
Oop2011 actor presentation_stal
Michael Stal
 
Introduction to concurrent programming with akka actors
datamantra
 
Introduction to concurrent programming with Akka actors
Shashank L
 
Introduction to Akka
Knoldus Inc.
 
Reactive Programming using Actor Model in Akka
StephenKoc1
 
Akka in Action: Heiko Seeburger
JAX London
 
Akka.Net Ottawa .NET User Group Meetup
Taswar Bhatti
 
Sharing-akka-pub
Hendri Karisma
 
Akka - A Brief Intro
Thomas Lockney
 
Introduction to Akka - Atlanta Java Users Group
Roy Russo
 
Reactive programming with scala and akka
Knoldus Inc.
 
Reactive programming with akka
Sovon Nath
 
Reactive Programming in Akka
DevFest DC
 
Introducing Akka
Meetu Maltiar
 
Akka in-action
Raymond Roestenburg
 
Akka (1)
Rahul Shukla
 
Ad

More from David Hoerster (7)

PPTX
Elm - Could this be the Future of Web Dev?
David Hoerster
 
PPTX
Being RDBMS Free -- Alternate Approaches to Data Persistence
David Hoerster
 
PPTX
Mongo Baseball .NET
David Hoerster
 
PPTX
Freeing Yourself from an RDBMS Architecture
David Hoerster
 
PPTX
A Minimalist’s Attempt at Building a Distributed Application
David Hoerster
 
PPTX
Greenfield Development with CQRS and Windows Azure
David Hoerster
 
PPTX
jQuery and OData - Perfect Together
David Hoerster
 
Elm - Could this be the Future of Web Dev?
David Hoerster
 
Being RDBMS Free -- Alternate Approaches to Data Persistence
David Hoerster
 
Mongo Baseball .NET
David Hoerster
 
Freeing Yourself from an RDBMS Architecture
David Hoerster
 
A Minimalist’s Attempt at Building a Distributed Application
David Hoerster
 
Greenfield Development with CQRS and Windows Azure
David Hoerster
 
jQuery and OData - Perfect Together
David Hoerster
 

Recently uploaded (20)

PPTX
Quality on Autopilot: Scaling Testing in Uyuni
Oscar Barrios Torrero
 
PPTX
CV-Project_2024 version 01222222222.pptx
MohammadSiddiqui70
 
PDF
TEASMA: A Practical Methodology for Test Adequacy Assessment of Deep Neural N...
Lionel Briand
 
PPTX
Perfecting XM Cloud for Multisite Setup.pptx
Ahmed Okour
 
PPTX
IDM Crack with Internet Download Manager 6.42 [Latest 2025]
HyperPc soft
 
PDF
From Chaos to Clarity: Mastering Analytics Governance in the Modern Enterprise
Wiiisdom
 
PDF
What Is an Internal Quality Audit and Why It Matters for Your QMS
BizPortals365
 
PDF
Difference Between Kubernetes and Docker .pdf
Kindlebit Solutions
 
PPTX
computer forensics encase emager app exp6 1.pptx
ssuser343e92
 
PPTX
ERP - FICO Presentation BY BSL BOKARO STEEL LIMITED.pptx
ravisranjan
 
PPTX
For my supp to finally picking supp that work
necas19388
 
PPTX
IObit Driver Booster Pro 12.4-12.5 license keys 2025-2026
chaudhryakashoo065
 
PPTX
Seamless-Image-Conversion-From-Raster-to-wrt-rtx-rtx.pptx
Quick Conversion Services
 
PDF
Rewards and Recognition (2).pdf
ethan Talor
 
PDF
>Nitro Pro Crack 14.36.1.0 + Keygen Free Download [Latest]
utfefguu
 
PDF
LPS25 - Operationalizing MLOps in GEP - Terradue.pdf
terradue
 
PDF
How DeepSeek Beats ChatGPT: Cost Comparison and Key Differences
sumitpurohit810
 
PDF
>Wondershare Filmora Crack Free Download 2025
utfefguu
 
PDF
Continouous failure - Why do we make our lives hard?
Papp Krisztián
 
PDF
Cloud computing Lec 02 - virtualization.pdf
asokawennawatte
 
Quality on Autopilot: Scaling Testing in Uyuni
Oscar Barrios Torrero
 
CV-Project_2024 version 01222222222.pptx
MohammadSiddiqui70
 
TEASMA: A Practical Methodology for Test Adequacy Assessment of Deep Neural N...
Lionel Briand
 
Perfecting XM Cloud for Multisite Setup.pptx
Ahmed Okour
 
IDM Crack with Internet Download Manager 6.42 [Latest 2025]
HyperPc soft
 
From Chaos to Clarity: Mastering Analytics Governance in the Modern Enterprise
Wiiisdom
 
What Is an Internal Quality Audit and Why It Matters for Your QMS
BizPortals365
 
Difference Between Kubernetes and Docker .pdf
Kindlebit Solutions
 
computer forensics encase emager app exp6 1.pptx
ssuser343e92
 
ERP - FICO Presentation BY BSL BOKARO STEEL LIMITED.pptx
ravisranjan
 
For my supp to finally picking supp that work
necas19388
 
IObit Driver Booster Pro 12.4-12.5 license keys 2025-2026
chaudhryakashoo065
 
Seamless-Image-Conversion-From-Raster-to-wrt-rtx-rtx.pptx
Quick Conversion Services
 
Rewards and Recognition (2).pdf
ethan Talor
 
>Nitro Pro Crack 14.36.1.0 + Keygen Free Download [Latest]
utfefguu
 
LPS25 - Operationalizing MLOps in GEP - Terradue.pdf
terradue
 
How DeepSeek Beats ChatGPT: Cost Comparison and Key Differences
sumitpurohit810
 
>Wondershare Filmora Crack Free Download 2025
utfefguu
 
Continouous failure - Why do we make our lives hard?
Papp Krisztián
 
Cloud computing Lec 02 - virtualization.pdf
asokawennawatte
 

Creating scalable message driven solutions akkadotnet

  • 1. CREATING SCALABLE MESSAGE- DRIVEN SOLUTIONS (WITH AKKA.NET) David Hoerster
  • 2. ABOUT ME 5-Time .NET (Visual C#) MVP (April 2011) Sr. Solutions Architect at Confluence One of the organizers for Pittsburgh TechFest (http://pghtechfest.com) Organizer of Pittsburgh Reactive Dev Group (http://meetup.com/reactive) Past President of Pittsburgh .NET Users Group Twitter - @DavidHoerster Blog – http://blog.agileways.com Email – [email protected]
  • 3. AGENDA Messages as Part of Application Design Being Reactive What the Actor Model Provides Hello Akka.NET Working with Akka.NET Cross-Process Actor Systems (Akka.Remote)
  • 4. CQRS Command Query Responsibility Segregation  Coined by Greg Young Evolution of CQS (Command Query Separation)  Coined by Bertrand Meyer Both revolve around the separation of writes (command) and reads (query) CQS is more at the unit level CQRS is at the bounded context level, or so
  • 5. MESSAGES The core of CQRS  Messages Communication from the service layer to the domain via commands  Command handlers could also update the underlying repository As actions happen, events are raised Event handlers could issue other commands Event handlers could update the underlying repository
  • 6. MESSAGES Regardless of how it’s implemented, communication between application parts is via messages Not only helps communicate intent of the action  “PublishWidget”, “ExpireWorkItem”, “UpdateDefinition”, “DefinitionUpdated” But allows for remote handling of messages  Queue, REST payload, etc.
  • 7. MESSAGES ARE KEY TO BEING REACTIVE
  • 8. SO? So how does this affect my system design? Let’s consider some procedural pitfalls
  • 9. WORD COUNTER EXAMPLE Simple program to count the occurrences of words in a document Print out the top 25 words and their counts at the end Can be accomplished easily via procedural code
  • 11. WORD COUNTER EXAMPLE What if you wanted to spread out the counting load? What if you wanted to scale out to other nodes/processes/machines? Fault tolerance, concurrent actions, etc.?
  • 12. BUILDING CONCURRENT APPS In word counter, may need to spawn some threads Lock some critical sections, etc. The system becomes responsible for knowing everything going on  Very Proactive (not Reactive!) system
  • 13. SIDE NOTE: REACTIVE VS. PROACTIVE Isn’t proactive a good thing? A system taking upon itself to check state is proactive  It’s doing too much A reactive system reacts to events that occur  It’s doing just the right amount
  • 14. SIDE NOTE: REACTIVE VS. PROACTIVE Isn’t proactive a good thing? A system taking upon itself to check state is proactive  It’s doing too much A reactive system reacts to events that occur  It’s doing just the right amount System EvtEvt System EvtEvt Proactive Reactive
  • 15. REAL WORLD SCENARIO Loosely structured data Multiple files to combine Operations to perform during the projection process
  • 16. REAL WORLD SCENARIO File File File Join Op Join/ End
  • 17. REAL WORLD SCENARIO Number of “steps” May need some sub-steps Can be broken down into individual pieces  Actors Communicate via messages for loose coupling
  • 18. REAL WORLD SCENARIO Actually looks like this: Multiple sources Several transforms Several joins Configurable
  • 19. ACTOR MODEL Actor Model is a system made of small units of concurrent computation  Formulated in the early 70’s Each unit is an actor Communicates to each other via messages Actors can have children, which they can supervise
  • 20. WHAT IS AN ACTOR? Class that encapsulates state and behavior  State can be persisted (Akka.Persistence)  Behavior can be switched (Become/Unbecome) Has a mailbox to receive messages  Ordered delivery by default  Queue Can create child actors Has a supervisory strategy for child actors  How to handle misbehaving children Are always thread safe Have a lifecycle  Started, stopped, restarted
  • 21. AKKA.NET Akka.NET is an open source framework Actor Model for .NET Port of Akka (for JVM/Scala) http://getakka.net NuGet package – search for Akka.Net (not the first result usually!)
  • 22. STARTING WITH AKKA.NET Akka.NET is a hierarchical system Root of the system is ActorSystem Expensive to instantiate – create and hold! ActorSystem can then be used to create Actors
  • 23. CREATING AN ACTOR An Actor has a unique address Can be accessed/communicated to like a URI Call ActorOf off ActorSystem, provide it a name  URI (actor path) is created hierarchically Actor Path = akka://myName/user/announcer
  • 24. SENDING A MESSAGE Messages are basis of actor communication  Should be IMMUTABLE!!! “Tell” an actor a message Async call  Immutable!!
  • 25. RECEIVING A MESSAGE Create your Actor Derive from ReceiveActor In constructor, register your message subscriptions
  • 26. RECEIVING A MESSAGE Each actor has a mailbox Messages are received in the actor’s mailbox (queue) Actor is notified that there’s a message  It receives the message  Takes it out of the mailbox  Next one is queued up Ordered delivery by default  Other mailboxes (like Priority) that are out-of-order Actor Mailbox Msg
  • 28. CREATING CHILDREN Best to call ActorOf to get an IActorRef Create a static Props creator Actor path is relative to parent’s actor path  akka://myDemo/user/countChocula/{childName} When creating a child, good idea to name it  So you can reference it later!
  • 29. WORD COUNTER WITH ACTORS Program sends StartCount message to CountSupervisor CountSupervisor, for each line, sends line to one of 5 LineCounterActors (ReadLineForCounting message) LineCounterActor counts the word in that line Tells the Sender (CountSupervisor) the results (MappedList message) CountSupervisor aggregates results of MappedList messages When all lines complete, CountSupervisor sends each LineActor a Complete message LineCounterActor cleans up and sends CountSupervisor Complete When all LineCounterActors are Complete, CountSupervisor prints out top 25 words
  • 31. ROUTING Map Reduce example used Round Robin There are others OOTB  Broadcast  Random  Consistent Hashing (used by Cluster)  Smallest Mailbox  More Pools and Groups  Pools are more anonymous  Groups are pre-created
  • 32. FINDING CHILDREN Within an actor, call Context.Child with the name of the child actor If not found, ActorRefs.Nobody is returned If found, you have an IActorRef to work with Using ActorSelection doesn’t guarantee actor is initialized
  • 33. MORE COMPLEX ACTOR DEMO baseball gameCoo rdinator gameInfo -x gameInfo -y playerSup ervisor batter-abatter-bbatter-c c-01 c-11 c-32
  • 34. INTEGRATION Integration with other systems is simple Best to encapsulate in its own actor Contain any errors there  Prevent affecting parts of the system further upstream
  • 35. ASYNC Actors have messages delivered to them in order via a Mailbox As message is received, handed to Actor to process Messages in mailbox queue up As a result, async processing of messages isn’t possible  Receive<> (async msg => { … }) doesn’t work If you need to perform async tasks within Receive  PipeTo(Self) usually does the trick  Re-queues message back on Mailbox  When delivered, actor resumes Actor Mailbox Msg PipeTo
  • 36. ACTORS ACROSS PROCESSES Akka.Remote module Configure via HOCON  Human Optimized Configuration Object Notation Allows an actor system to distribute messages to actors across processes Location transparency!!
  • 38. ACTORS ACROSS PROCESSES Actor Path modified  akka.tcp://localhost:50000@{system}/user/{supervisor}/{name} Protocol and location added to actor path Protocol defaults to tcp, but you can provide your own Actor path above is remote path
  • 40. ELASTICITY WITH ACTORS Akka.Cluster Multiple nodes of an actor system acting as one Allows for failure Can also expand out for performance
  • 41. SAVING ACTOR STATE Akka.Persistence Persist each message (or snapshots) to storage Like event sourcing Rehydrate actor state after failure or for whatever reason
  • 42. ASKING AN ACTOR Wait for a response from an actor Somewhat of an anti-pattern for Actor Model If used, use sparingly
  • 43. HANDLING ERRORS An exception during processing with a classic app could crash the whole system An exception within a child actor is isolated
  • 44. IS AKKA.NET…? Pub/Sub?  No, but it could be Message Bus, like RabbitMQ or MassTransit  Uses messages to communicate  Message bus concerned with building a distributed system topology Storm, ETL/ELT, etc.?  Kind of  Can build system like that with Akka.NET