A Tour of Advanced Akka Features in 60
![A Tour of (Advanced) Akka Features in 60 Minutes [CON 1706] Johan Janssen, Info A Tour of (Advanced) Akka Features in 60 Minutes [CON 1706] Johan Janssen, Info](https://slidetodoc.com/presentation_image/268cacb198fccf85f409d906676d76e3/image-1.jpg)











![val worker. Actor. Ref = system. actor. Of(Props[Worker]) worker. Actor. Ref ! "Hello conference" val worker. Actor. Ref = system. actor. Of(Props[Worker]) worker. Actor. Ref ! "Hello conference"](https://slidetodoc.com/presentation_image/268cacb198fccf85f409d906676d76e3/image-13.jpg)




















![Routing "" Coordinator Actor on JVM 1 Hash. Map[hostname, counter] Empty. String Actor on Routing "" Coordinator Actor on JVM 1 Hash. Map[hostname, counter] Empty. String Actor on](https://slidetodoc.com/presentation_image/268cacb198fccf85f409d906676d76e3/image-34.jpg)






![Cluster singleton "" Coordinator Hash. Map[hostname, counter] Empty. String Actor on JVM 2 Empty. Cluster singleton "" Coordinator Hash. Map[hostname, counter] Empty. String Actor on JVM 2 Empty.](https://slidetodoc.com/presentation_image/268cacb198fccf85f409d906676d76e3/image-41.jpg)

![Cluster singleton "" Coordinator Hash. Map[hostname, counter] Empty. String Actor on JVM 2 Empty. Cluster singleton "" Coordinator Hash. Map[hostname, counter] Empty. String Actor on JVM 2 Empty.](https://slidetodoc.com/presentation_image/268cacb198fccf85f409d906676d76e3/image-43.jpg)


![Cluster singleton Coordinator "" Hash. Map[hostname, counter] Empty. String Actor on JVM 3 Empty. Cluster singleton Coordinator "" Hash. Map[hostname, counter] Empty. String Actor on JVM 3 Empty.](https://slidetodoc.com/presentation_image/268cacb198fccf85f409d906676d76e3/image-46.jpg)

![Cluster singleton Coordinator "" Hash. Map[hostname, counter] Empty. String Actor on JVM 3 Empty. Cluster singleton Coordinator "" Hash. Map[hostname, counter] Empty. String Actor on JVM 3 Empty.](https://slidetodoc.com/presentation_image/268cacb198fccf85f409d906676d76e3/image-48.jpg)















































- Slides: 95
A Tour of (Advanced) Akka Features in 60 Minutes [CON 1706] Johan Janssen, Info Support @johanjanssen 42
Content ▪ Why Akka? ▪ Sharding ▪ Local actor ▪ Persistence ▪ Remote actor ▪ Akka HTTP ▪ Scheduling ▪ Finite State Machines ▪ Cluster ▪ Conclusion ▪ Routing ▪ Questions ▪ Cluster singleton
Why Akka?
Why Akka? ▪ Concurrent ▪ Scalable ▪ Fault tolerant ▪ More natural programming experience when connecting to other systems ▪ Easy to use?
i a l c s i D r e m
Local actor
Local actor Actor on JVM 1
Local actor Coordinator Actor Hello conference
Local actor Coordinator Actor println("Hello conference")
class Worker extends Actor { def receive = { case x => println(x) } } Scala val system = Actor. System("Example. Actor. System") val worker. Actor. Ref = system. actor. Of(Props[Worker]) worker. Actor. Ref ! "Hello conference"
Remote actor
Remote actor Actor on JVM 1 Actor on JVM 2
val worker. Actor. Ref = system. actor. Of(Props[Worker]) worker. Actor. Ref ! "Hello conference" val worker. Actor. Ref = context. actor. Selection("akka. tcp: // Example. Actor. System@127. 0. 0. 1: 9005 /user/worker. Actor") worker. Actor. Ref ! "Hello conference"
akka { actor { provider = "akka. remote. Remote. Actor. Ref. Provider" } remote { enabled-transports = ["akka. remote. netty. tcp"] netty. tcp { hostname = "127. 0. 0. 1" port = 9002
Remote actor Start. Message Hello conference Coordinator actor Worker actor
Remote actor Coordinator actor Worker. Message Greetings from the coordinator: Hello Conference Worker actor
Remote actor Coordinator actor Worker. Response Message Item processed successfully Worker actor
Scheduling
Scheduling Tick Scheduled once after 1 second system. scheduler. schedule. Once(1 seconds, schedule. Receive. Actor, Tick) Tock Scheduled every 5 seconds system. scheduler. schedule(0 seconds, 5 seconds, schedule. Receive. Actor, Tock) Actor
Scheduling ▪ Does not work for fixed point in time like 17: 00 – Use Quartz
Cluster
Cluster Actor. System on JVM 2 Actor. System on JVM 1 Actor. System on JVM 3 Actor. System on JVM 4
Seed nodes ▪ Contact points for automatically joining a cluster
akka { cluster { seed-nodes = [ "akka. tcp: //Cluster. Node@127. 0. 0. 1: 2551", "akka. tcp: //Cluster. Node@127. 0. 0. 1: 2552" ] } }
Cluster Worker Node Port 2551 Association failed with [akka. tcp: //Cluster. System@127. 0. 0. 1: 2552
Cluster Member Up with IP: 127. 0. 0. 1 and port: 2551 Member Up with IP: 127. 0. 0. 1 and port: 2552 Worker Node Port 2552
Cluster Member Up with IP: 127. 0. 0. 1 and port: 2550 Coordinator Node Port 2550 Member Up with IP: 127. 0. 0. 1 and port: 2550 Worker Node Port 2551 Worker Node Port 2552
Cluster Coordinator Node Port 2550 Register. Worker Node Port 2551 Register. Worker Node Port 2552
Cluster Coordinator Node Port 2550 Worker registered with IP: 127. 0. 0. 1 and port: 2551 Worker registered with IP: 127. 0. 0. 1 and port: 2552 Worker Node Port 2551 Worker Node Port 2552
Routing
Routing Actor on JVM 2 Actor on JVM 1 Actor on JVM 3 Loadbalancer Actor on JVM 4
akka { actor { provider = "akka. cluster. Cluster. Actor. Ref. Provider" } } deployment { /coordinator/router { router = round-robin-pool nr-of-instances = 10 routees. paths = ["/user/emptystringactor"] cluster { enabled = on allow-local-routees = off } } }
Routing "" Coordinator Actor on JVM 1 Empty. String Actor on JVM 2 Empty. String Actor on JVM 3 Empty. String Actor on JVM 4
Routing "" Coordinator Actor on JVM 1 Hash. Map[hostname, counter] Empty. String Actor on JVM 2 Empty. String Actor on JVM 3 Empty. String Actor on JVM 4
Routing Empty. String Actor on JVM 2 Coordinator Actor on JVM 1 "" Empty. String Actor on JVM 3 Empty. String Actor on JVM 4
Routing Empty. String Actor on JVM 2 Coordinator Actor on JVM 1 Empty. String Actor on JVM 3 "" Empty. String Actor on JVM 4
Cluster singleton
Cluster singleton ▪ Only one instance of the actor in the cluster ▪ (Re)created on the oldest node ▪ Can be used for instance for scheduling/caching
Cluster singleton Actor on JVM 1 Singleton actor and other actors on JVM 2 Other actors on JVM 3 Other actors on JVM 4
Cluster singleton "" Coordinator Empty. String Actor on JVM 2 Empty. String Actor on JVM 3 Empty. String Actor on JVM 4
Cluster singleton "" Coordinator Hash. Map[hostname, counter] Empty. String Actor on JVM 2 Empty. String Actor on JVM 3 Empty. String Actor on JVM 4
Cluster singleton "" Coordinator Empty. String Actor on JVM 2 Empty. String Actor on JVM 3 Empty. String Actor on JVM 4
Cluster singleton "" Coordinator Hash. Map[hostname, counter] Empty. String Actor on JVM 2 Empty. String Actor on JVM 3 Empty. String Actor on JVM 4
Cluster singleton Coordinator Empty. String Actor Crashon JVM 2 Empty. String Actor on JVM 3 Empty. String Actor on JVM 4
Cluster singleton Coordinator "" Empty. String Actor on JVM 3 Empty. String Actor on JVM 4
Cluster singleton Coordinator "" Hash. Map[hostname, counter] Empty. String Actor on JVM 3 Empty. String Actor on JVM 4
Cluster singleton Coordinator "" Empty. String Actor on JVM 3 Empty. String Actor on JVM 4
Cluster singleton Coordinator "" Hash. Map[hostname, counter] Empty. String Actor on JVM 3 Empty. String Actor on JVM 4
Sharding
Sharding ▪ Dividing a set of actors over a cluster ▪ Actors will be divided into groups called shards ▪ It will divide based on a logical identifier
Sharding 0, 2, 4, 6, 8 Actor on JVM 1 1, 3, 5, 7, 9 even Shard on JVM 2 odd Shard on JVM 3
Persistence
Persistence ▪ Store actor information ▪ Recover after crash ▪ Possibility to take snapshots
Example without persistence Actor Cobol
Example without persistence Actor Cobol
Example without persistence Actor Cobol
Example without persistence Actor Java Cobol
Example without persistence Actor Crash Cobol Java Restart
Example without persistence Actor
Example without persistence Actor Scala
Example without persistence Actor Scala
Persistence Journal Command Cobol Persistent. Actor
Persistence Journal Persistent. Actor Cobol Event
Persistence Journal Persistent. Actor ACK Cobol Event
Persistence Journal Persistent. Actor Cobol Event
Persistence Journal Persistent. Actor Cobol Event Java Event
Persistence Journal Crash Persistent. Actor Cobol Java Restart Cobol Event Java Event
Persistence Journal Persistent. Actor Cobol Event Java Event
Persistence Journal Persistent. Actor Scala Cobol Java Cobol Event Java Event
Persistence Journal Persistent. Actor Cobol Java Scala Cobol Event Java Event
Snapshots Snapshot store Persistent. Actor State until Event C++ Journal Cobol C++
Snapshots Snapshot store Persistent. Actor State until Event C++ Journal Cobol C++
Snapshots Snapshot store State until Event C++ Persistent. Actor Journal Cobol C++
Snapshots Snapshot store Journal Persistent. Actor State until Event C++ Java Cobol C++
Snapshots Snapshot store State until Event C++ Persistent. Actor Journal Cobol C++ Java Crash Restart
Snapshots Snapshot store State until Event C++ Persistent. Actor Journal Cobol C++ Java
Snapshots Snapshot store State until Event C++ Persistent. Actor Cobol C++ Journal Cobol C++ Java
Snapshots Snapshot store State until Event C++ Persistent. Actor Cobol C++ Java Journal Cobol C++ Java
Snapshots Snapshot store State until Event C++ Persistent. Actor Cobol C++ Java Scala Journal Cobol C++ Java
Akka HTTP
Akka HTTP Actor on JVM 1 Actor on JVM 2
Finite State Machine
Finite State Machine ▪ State ▪ Event
Finite State Machines (FSM) Progress, iteration Crappy Project New Project No. Progress, 2 Progress, iteration Inprogress Project
Finite State Machines (FSM) Iteration: 0 New Project Crappy Project Work harder Inprogress Project
Finite State Machines (FSM) Iteration: 0 New Project Good job! Crappy Project Inprogress Project
Finite State Machines (FSM) Iteration: 0 New Project Wrong direction Crappy Project Inprogress Project
Finite State Machines (FSM) Iteration: 0 New Project Use Akka Crappy Project Inprogress Project
Finite State Machines (FSM) Iteration: 1 New Project Good job! Crappy Project Inprogress Project
Finite State Machines (FSM) Iteration: 1 New Project Wrong direction Crappy Project Inprogress Project
Finite State Machines (FSM) Iteration: 1 New Project Use Akka Crappy Project Inprogress Project
Finite State Machines (FSM) Iteration: 2 New Project Crappy Project Get another job! Inprogress Project
Conclusion
Conclusion ▪ Akka can be used with Scala or Java ▪ There is even a. NET version of Akka ▪ Akka is really powerful ▪ Akka is quite easy to use ▪ Some features are still experimental
Questions Johan Janssen @johanjanssen 42 Git. Hub: https: //github. com/johanjanssen/Akka-examples