Akka Actors: Simple Practical Examples
Table of Contents
- Make sure you study and actually run the examples described.
- The code shown may not always compile as-is. The syntax may need tweaking.
1 Akka Install
- Versions: Scala 2.11+, Akka 2.3.1+. Code for older versions may not work with these versions. Most, not 100%, are open source.
- https://developer.lightbend.com/guides/akka-quickstart-scala/ Must read and follow. This will show howto install Akka and gives a "hello-world" of Akka.
2 How Does Akka work?
Figure 1: How Does Akka work?
Akka can be used without defining a configuration, since sensible default values are provided.
// application.conf at the root of the class path. akka { loggers = ["akka.event.slf4j.Slf4jLogger"] loglevel = "DEBUG" stdout-loglevel = "WARNING" actor { provider = "akka.cluster.ClusterActorRefProvider" default-dispatcher { # set to 1 for as fair as possible throughput = 10 } } remote { netty.tcp.port = 2552 } }
3 Akka Hello World
4 One Producer and Several Consumers
- https://github.com/foobatman/producer-consumer-akka-actor Required Reading.
5 Dining Philosophers 1
- ./dining-philosophers-akka.html Required Reading.
6 Dining Philosophers 2 with FSM
- ./dining-philosophers-akka-fsm.html Required Reading.
7 Akka and Other PL
- The code shown in various blogs is not always self-contained enough to compile it stand-alone. Even the syntax may need tweaking.
scala.actor
is deprecated. Caution: Many articles on the web are based on scala.actor. Useimport akka.actor
. http://docs.scala-lang.org/overviews/core/actors-migration-guide.html- Akka library can be used in Java as well.
- http://www.pykka.org/ with Python.
8 References
- https://doc.akka.io/docs/akka/current/typed/guide/ Getting Started
Guide. Must visit. The following are linked there.
- Introduction to Akka. Required Reading
- Part 1: Actor Architecture. Required Reading
- Part 2: Creating the First Actor. Required Reading
- Part 3: Working with Device [in the small] Actors Optional Reading
- Part 4: Working with Device Groups Optional Reading
- Part 5: Querying Device Groups Optional Reading
- https://alvinalexander.com/scala/simple-scala-akka-actor-examples-hello-world-actors/ Required Reading.
- https://github.com/nadimbahadoor/learn-akka "Examples To Help You Learn Akka" Some 25+ examples. Highly Recommended.