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

Working with streaming I/O


One of the most common scenarios of streaming is input-output applications. Nowadays, almost any modern application uses I/O to communicate with external entities or services. This is usually achieved by either listening on a port or pushing data to a remote system. For example, this concept is what the Internet of Things relies on when machines use I/O to contact with each other.

Akka Streams provide a set of Sources and Sinks to use files, InputStreams, and OutputStreams in your streams. In this recipe, we will create a stream to listen for words and count them as they come.

Getting ready

In this recipe, we will create a stream that will listen for TCP connections on port 1234. Once it receives an incoming message from the stream, it will count its words and return the counts in ByteString.

How to do it...

For this recipe, perform the following steps:

  1. Create a file named WorkingIOStreamsApplication.scala inside the com.packt.chapter8 package.  This object instantiates...