Book Image

Akka Cookbook

By : Vivek Mishra, Héctor Veiga Ortiz
Book Image

Akka Cookbook

By: Vivek Mishra, Héctor Veiga Ortiz

Overview of this book

Akka is an open source toolkit that simplifies the construction of distributed and concurrent applications on the JVM. This book will teach you how to develop reactive applications in Scala using the Akka framework. This book will show you how to build concurrent, scalable, and reactive applications in Akka. You will see how to create high performance applications, extend applications, build microservices with Lagom, and more. We will explore Akka's actor model and show you how to incorporate concurrency into your applications. The book puts a special emphasis on performance improvement and how to make an application available for users. We also make a special mention of message routing and construction. By the end of this book, you will be able to create a high-performing Scala application using the Akka framework.
Table of Contents (18 chapters)
Title Page
About the Authors
About the Reviewer
Customer Feedback

Ordered termination of actors

Actors are usually deployed in hierarchies. This layout brings flexibility to the actor system as well as other features, such as separation of concerns (where an actor will only care about the business logic and the parent would deal with the error handling through the supervision strategy). This layout also has repercussions when stopping actors. When a given actor is terminated, then all children actors of that given actor will also get terminated in a non-deterministic way. However, this default behavior might not always be the desired behavior for your use case. This might be the case when shutting down actors connecting to external services.

In this recipe, we will cover how to do ordered termination of actors to cover scenarios where some actors need to terminate before others. To demonstrate this, we will create a ServicesManager actor that will act as the parent of different ServiceHandler actors that need to terminate in an order. However, the real...