UP | HOME
../../ | 2020-04-14

Akka Actors: Simple Practical Examples

Table of Contents

  1. Make sure you study and actually run the examples described.
  2. The code shown may not always compile as-is. The syntax may need tweaking.

1 Akka Install

  1. Versions: Scala 2.11+, Akka 2.3.1+. Code for older versions may not work with these versions. Most, not 100%, are open source.
  2. 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?

fig-actor-users.png

Figure 1: How Does Akka work?

  1. 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

5 Dining Philosophers 1

6 Dining Philosophers 2 with FSM

7 Akka and Other PL

  1. The code shown in various blogs is not always self-contained enough to compile it stand-alone. Even the syntax may need tweaking.
  2. scala.actor is deprecated. Caution: Many articles on the web are based on scala.actor. Use import akka.actor . http://docs.scala-lang.org/overviews/core/actors-migration-guide.html
  3. Akka library can be used in Java as well.
  4. http://www.pykka.org/ with Python.

8 References

  1. https://doc.akka.io/docs/akka/current/typed/guide/ Getting Started Guide. Must visit. The following are linked there.
    1. Introduction to Akka. Required Reading
    2. Part 1: Actor Architecture. Required Reading
    3. Part 2: Creating the First Actor. Required Reading
    4. Part 3: Working with Device [in the small] Actors Optional Reading
    5. Part 4: Working with Device Groups Optional Reading
    6. Part 5: Querying Device Groups Optional Reading
  2. https://alvinalexander.com/scala/simple-scala-akka-actor-examples-hello-world-actors/ Required Reading.
  3. https://github.com/nadimbahadoor/learn-akka "Examples To Help You Learn Akka" Some 25+ examples. Highly Recommended.

9 End


Copyright © 2020 www.wright.edu/~pmateti • 2020-04-14