Akka Cookbook

Book description

Learn how to use the Akka framework to build effective applications in Scala

About This Book

  • Covers a discussion on Lagom—the newest launched Akka framework that is built to create complex microservices easily
  • The recipe approach of the book allows the reader to know important and independent concepts of Scala and Akka in a seamless manner
  • Provides a comprehensive understanding of the Akka actor model and implementing it to create reactive web applications

Who This Book Is For

If you are a Scala developer who wants to build scalable and concurrent applications, then this book is for you. Basic knowledge of Akka will help you take advantage of this book.

What You Will Learn

  • Control an actor using the ContolAware mailbox
  • Test a fault-tolerant application using the Akka test kit
  • Create a parallel application using futures and agents
  • Package and deploy Akka application inside Docker
  • Deploy remote actors programmatically on different nodes
  • Integrate Streams with Akka actors
  • Install Lagom and create a Lagom project

In Detail

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.

Style and approach

This highly practical recipe-based approach will allow you to build scalable, robust, and reactive applications using the Akka framework.

Table of contents

  1. Preface
    1. What this book covers
    2. What you need for this book
    3. Who this book is for
    4. Sections
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
      5. See also
    5. Conventions
    6. Reader feedback
    7. Customer support
      1. Downloading the example code
      2. Errata
      3. Piracy
      4. Questions
  2. Diving into Akka
    1. Introduction
    2. Creating an Akka Scala SBT project from scratch
      1. Getting ready
      2. How to do it...
    3. Creating and understanding ActorSystem
      1. Getting ready
      2. How to do it...
      3. How it works...
        1. Why we need ActorSystem
    4. Defining the actor's behavior and state
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    5. Sending messages to actors
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    6. Asking for a result from an actor
      1. How to do it...
      2. How it works...
      3. There's more...
    7. Communication between actors
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    8. Creating a custom mailbox for an actor
      1. Getting ready
      2. How to do it...
      3. How it works...
    9. Prioritizing messages that an actor receives
      1. Getting ready
      2. How to do it...
      3. How it works...
    10. Creating a control-aware mailbox for an actor
      1. Getting ready
      2. How to do it...
      3. How it works...
    11. Become/unbecome behavior of an actor
      1. Getting ready
      2. How to do it...
      3. How it works...
    12. Stopping an actor
      1. Getting ready
      2. How to do it...
      3. How it works...
  3. Supervision and Monitoring
    1. Introduction
      1. What is fault tolerance?
      2. What is a component?
      3. How Akka fits in between all of them?
    2. Creating child actors of a parent actor
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Overriding the life cycle hooks of an actor
      1. How to do it...
      2. How it works...
    4. Sending messages to actors and collecting responses
      1. How to do it...
      2. How it works...
    5. Understanding OneForOneStrategy for actors
      1. How to do it...
      2. How it works...
    6. Understanding AllForOneStrategy for actors
      1. How to do it...
      2. How it works...
    7. Monitoring an actor life cycle using DeathWatch
      1. How to do it...
      2. How it works...
  4. Routing Messages
    1. Introduction
      1. Where to use routers
    2. Creating a SmallestMailboxPool of actors
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Creating a BalancingPool of actors
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Creating a RoundRobinPool of actors
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Creating a BroadcastPool of actors
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Creating a ScatterGatherFirstCompletedPool of actors
      1. Getting ready
      2. How it works...
    7. Creating a TailChoppingPool of actors.
      1. Getting ready
      2. How it works...
    8. Creating a ConsistentHashingPool of actors
      1. Getting ready
      2. How to do it...
      3. How it works...
    9. Creating a RandomPool of actors
      1. Getting ready
      2. How to do it...
      3. How it works...
    10. Sending specially handled messages to routers
      1. Getting ready
      2. How to do it...
      3. How it works...
    11. Creating a dynamically resizable pool of actors
      1. Getting ready
      2. How to do it...
  5. Using Futures and Agents
    1. Introduction
    2. Using a future directly for a simple operation
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Using futures with actors
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Using futures inside actors
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Using for-comprehensions for futures
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Handling callback on futures
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Creating a simple parallel application using futures
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. Reducing a sequence of futures
      1. Getting ready
      2. How to do it...
      3. How it works...
    9. Reading and updating agents
      1. Getting ready
      2. How to do it...
      3. How it works...
    10. Composing agents monadically
      1. Getting ready
      2. How to do it..
      3. How it works...
  6. Scheduling Actors and Other Utilities
    1. Introduction
    2. Scheduling an operation at a specified interval
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Scheduling an actor's operation at a specified interval
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Canceling a scheduled operation of the actor
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Creating a circuit breaker to avoid cascading failure
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. How to introduce logging with actors
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Writing unit test for actors
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. Packaging and deploying the Akka standalone application
      1. Getting ready
      2. How to do it...
      3. How it works...
    9. Packaging and deploying Akka application inside a Docker container
      1. Getting ready
      2. How to do it...
      3. How it works...
    10. Configurating Akka applications
      1. Getting ready
      2. How to do it...
      3. How it works...
  7. Akka Persistence
    1. Introduction
    2. Preparing an actor for persistence
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Recovering the state of an actor
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Safely shutting down a persistent actor
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Reducing recovery time using snapshots
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Creating a persistence FSM model
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Persisting the state to LevelDB
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. Persisting the state to Cassandra
      1. Getting ready
      2. How to do it...
      3. How it works...
    9. Persisting the state to Redis
      1. Getting ready
      2. How to do it...
      3. How it works...
    10. Understanding event sourcing
      1. Getting ready
      2. How to do it...
      3. How it works...
    11. Handling failure in event sourcing
      1. Getting ready
      2. How to do it...
      3. How it works...
    12. Using persistence query
      1. Getting ready
      2. How to do it...
      3. How it works...
    13. Persistence query for LevelDB
      1. Getting ready
      2. How to do it...
      3. How it works...
  8. Remoting and Akka Clustering
    1. Introduction
    2. Enabling Akka applications for remoting
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Creating remote actors on different machines
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Looking up remote actors from different machines
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Deploying remote actors programmatically on different nodes
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Scaling out your application using remote actors
      1. Getting ready
      2. How to do it...
      3. How it works
    7. Creating a chat-based application using remote actors
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. Enabling Akka clustering for your project
      1. Getting ready
      2. How to do it...
      3. How it works...
    9. Using Distributed Publish-Subscribe in the cluster
      1. Getting ready
      2. How to do it...
      3. How it works...
    10. Cluster Sharding
      1. Getting ready
      2. How to do it...
      3. How it works...
    11. Sharing data between nodes in an Akka cluster
      1. Getting ready
      2. How to do it...
      3. How it works...
    12. Creating a singleton actor across clusters
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
  9. Akka Streams
    1. Introduction
    2. Creating simple Akka Streams
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. How to transform streams and consume them
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Creating stream sources, flows, and sinks
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Custom stream processing
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Error handling in Akka streams
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Pipelining and parallelizing streams
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. Working with streaming I/O
      1. Getting ready
      2. How to do it...
      3. How it works...
    9. Integrating streams with Akka actors
      1. Getting ready
      2. How to do it...
      3. How it works...
    10. Working with graphs
      1. Getting ready
      2. How to do it...
      3. How it works...
    11. Processing RabbitMQ messages with Akka streams
      1. Getting ready
      2. How to do it...
      3. How it works...
    12. Integrating Akka Streams with Kafka using Reactive Kafka
      1. Getting ready
      2. How to do it...
      3. How it works...
  10. Akka HTTP
    1. Introduction
    2. Creating a minimal HTTP server using Akka HTTP
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Consuming Akka HTTP services using a client-side API
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Writing routing DSL for HTTP servers
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Understanding the configuration of Akka HTTP
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Marshaling and unmarshaling data
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Encoding and decoding data
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. Understanding directives
      1. Getting ready
      2. How to do it...
      3. How it works...
    9. Exception handling
      1. Getting ready
      2. How to do it...
      3. How it works...
    10. Uploading a file using Akka HTTP
      1. Getting ready
      2. How to do it...
      3. How it works...
    11. Building JSON support with Akka HTTP
      1. Getting ready
      2. How to do it...
      3. How it works...
    12. XML support with Akka HTTP
      1. Getting ready
      2. How to do it...
      3. How it works...
  11. Understanding Various Akka patterns
    1. Introduction
    2. The Master Slave work pulling pattern
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Ordered termination of actors
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Shutdown patterns in Akka
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Scheduling periodic messages to an actor
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Throttling of messages while sending them to an actor
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Balancing workload across actors
      1. Getting ready
      2. How it works...
      3. How it works...
    8. The aggregator pattern
      1. Getting ready
      2. How to do it...
      3. How it works...
    9. The CountDownLatch pattern
      1. Getting ready
      2. How to do it...
      3. How it works...
    10. Finite-state machine
      1. Getting ready
      2. How to do it...
      3. How it works...
    11. The pausable actor pattern
      1. Getting ready
      2. How to do it...
      3. How it works...
    12. Enveloping actor
      1. Getting ready
      2. How to do it...
      3. How it works...
  12. Microservices with Lagom
    1. Introduction
    2. Installing Lagom and creating a Lagom project
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Understanding the service locator
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Understanding service descriptors
      1. Getting ready
      2. How to do it...
      3. How it works
    5. Implementing Lagom services
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Consuming services
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Testing services
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. Writing persistent and clustered services
      1. Getting ready
      2. How to do it...
      3. How it works...
    9. Running Lagom in production
      1. Getting ready
      2. How to do it...
      3. How it works...
    10. Integrating with Akka
      1. Getting ready
      2. How to do it...
      3. How it works

Product information

  • Title: Akka Cookbook
  • Author(s): Héctor Veiga Ortiz, Piyush Mishra
  • Release date: May 2017
  • Publisher(s): Packt Publishing
  • ISBN: 9781785288180