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
Credits
About the Authors
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface

Custom stream processing


Sometimes, all the out-of-the-box Akka Streams stages do not cover a specific scenario you need. Akka Streams provides a set of APIs to create your own custom stage. Since Streams are essentially processing graphs, to create a custom stage, you need to extend the GraphStage abstraction. Let's not confuse GraphDSL with GraphStage. The main difference between GraphDSL, which is used to compose multiple stages into a single stage, and GraphStage is that the latter cannot be decomposed into smaller pieces.

At this point, we need to learn a bit about how Akka Streams works internally. To begin with, there is the concept of shape. A shape defines the number of input and output ports in your stage (known as inlets and outlets). For example, SourceShape has only one outlet. A SinkShape has one inlet. A FlowShape has one inlet and one outlet. It is also possible to have an AmorphousShape, which has an arbitrary number of inlets and outlets. Every GraphStage also encompasses...