Shutting down an actor is often achieved by sending a PoisonPill
message to it. This allows the previous messages in the mailbox to get processed by the actor before it is stopped. Although this is totally correct for regular actors, it can turn into unexpected behaviors when using a persistent actor. Incoming commands are stashed while the persistent actor is awaiting confirmation from the journal that events have been stored when calling persist()
. The incoming commands will be drained from the Actor's mailbox and put into its internal stash while awaiting the confirmation (thus, before calling the persist
handlers). Therefore, the persistent actor may receive and (auto) handle the PoisonPill
message before it processes the other messages, causing a premature (and maybe unexpected) shutdown of the actor. In this recipe, we will look at how we should correctly shut down a persistent actor.
Akka Cookbook
By :
Akka Cookbook
By:
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
Credits
About the Authors
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface
Free Chapter
Diving into Akka
Supervision and Monitoring
Routing Messages
Using Futures and Agents
Scheduling Actors and Other Utilities
Akka Persistence
Remoting and Akka Clustering
Akka Streams
Akka HTTP
Understanding Various Akka patterns
Microservices with Lagom
Customer Reviews