This is an excerpt from my book, Hello, Scala. In this lesson I’ll show two examples of applications that use Akka actors, both of which can help you get started with my larger “Alexa written with Akka” = Aleka application.Back to top
An Akka “Hello, world” example
First, let’s look at an example of how to write a “Hello, world” application using Akka.
Writing a “Hello” actor
An actor is an instance of the
akka.actor.Actor class, and once it’s created it starts running on a parallel thread, and all it does is respond to messages that are sent to it. For this “Hello, world” example I want an actor that responds to “hello” messages, so I start with code like this:
Famed programmer Joe Armstrong passed away this weekend. He created the Erlang programming language, based on the actor model, and without using Google, I’m pretty darned sure that Erlang had an impact on Akka, the very cool actor library for Scala. Here’s an article Mr. Armstrong wrote some years ago, titled, Why OO Sucks (OO as in OOP).
Lightbend has a case study of how Groupon uses Akka and Play to meet their demanding performance needs. The article doesn’t say if they use Scala or Java,
When you’re working with multi-threaded programming in Java — such as when working with Thread, Runnable, SwingUtilities.invokeLater, Akka, futures, or Observable in RxJava — you may need to get the name of the current thread as a way to debug your code. Here’s how you get the name of the current thread in Java:
- Work hard at minimizing your ego & attachment to identity
- Learn deliberately, seek out weaknesses & work hard at them
- Eliminate bad habits, replace them with good, one at a time
- Read a lot, foundational stuff, not just latest hyped thing
PayPal Engineering has an article titled, Learning from Using a Reactive Platform — Akka/Squbs.
Way back in 2013 — before my first fake heart attack followed by learning that I had thyroid cancer — I thought I was about to go “back to work”, and I decided to try to write another visual demo of Akka Actors before I went back to work. I gave myself 10 hours to write something, and at first I decided to just create some bubbles that would move about randomly on screen. But I got that working so fast that I decided to do something else.
Eventually I came up with the idea of a little “kill the bubbles” game, which turned into a “kill the characters” game. This video shows how it works:
LinkedIn’s engineering blog post has this article about how they use the Play Framework and Akka show online “presence indicators.”
I recently started working on a project that may or may not make it into my book on Scala and functional programming. I’m currently calling it “Akkazon Ekko” — or “Ekko” — because it’s a little like the Amazon Echo, but written with Scala and Akka.
“In Erlang, processes share no memory and can interact with each other only by sending messages. This is exactly how objects in the real world behave.”