Scala Reactive Programming
Build scalable, functional reactive microservices with Akka, Play, and Lagom
Rambabu Posa
BIRMINGHAM - MUMBAI
Scala Reactive Programming
Copyright 2018 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
Commissioning Editor: Merint Mathew
Acquisition Editor: Karan Sadawana
Content Development Editor: Akshada Iyer
Technical Editor: Abhishek Sharma
Copy Editor: Pranjali Chury, Safis Editing
Project Coordinator: Prajakta Naik
Proofreader: Safis Editing
Indexer: Priyanka Dhadke
Graphics: Jisha Chirayil
Production Coordinator: Nilesh Mohite
First published: February 2018
Production reference: 1270218
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham
B3 2PB, UK.
ISBN 978-1-78728-864-5
www.packtpub.com
To my lovely wife, Bhargs, for all her help and encouragement during this book and to my beautiful little princess, Sai Aashika.
mapt.io
Mapt is an online digital library that gives you full access to over 5,000 books and videos, as well as industry leading tools to help you plan your personal development and advance your career. For more information, please visit our website.
Why subscribe?
Spend less time learning and more time coding with practical eBooks and Videos from over 4,000 industry professionals
Improve your learning with Skill Plans built especially for you
Get a free eBook or video every month
Mapt is fully searchable
Copy and paste, print, and bookmark content
PacktPub.com
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at service@packtpub.com for more details.
At www.PacktPub.com , you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks.
Contributors
About the author
Rambabu Posa has been working as Java developer since 2004 and a Scala developer since mid-2015. He loves Functional Programming in the Test-Driven Development way to develop Reactive microservices. He loves teaching and has been giving online training and writing tutorials on both the Java and Scala ecosystems. He loves developing Reactive systems using Lightbend's Reactive Platform Technology stack like Lagom Framework, ConductR, Scala, Akka Toolkit, Akka Streams, Play Framework, and others.
I would like to thank my wife, Bhargs, who helped me to draw some of the images, taking paper drawn pictures and photos, and sharing them with me. Without her efforts and encouragement, it would not have been possible to write this book.
About the reviewers
Pavlo Lysak is a seasoned developer with 10 years of experience in JVM and languages that run on it. He has previously worked on Java, that is, JavaEE and Spring, however, since the past 5 years, he has been working mostly with Scala, that is, Play, Akka, and Spark. After working with companies such as Jaspersoft, Kreditech, and more, he became an independent consultant. His daily work includes the development of Reactive Web Applications and RESTful services, taking care of their stability, maintainability, and transparency.
Dave Wentzel is the Chief Technology Officer (CTO) of Capax Global, a premier Microsoft consulting partner. He is responsible for setting the strategy and defining service offerings and capabilities for the data platform and Azure practice at Capax. Dave also works directly with clients to help them with their big data journey. He is a frequent blogger and speaker on big data and data science topics.
Packt is searching for authors like you
If you're interested in becoming an author for Packt, please visit authors.packtpub.com and apply today. We have worked with thousands of developers and tech professionals, just like you, to help them share their insight with the global tech community. You can make a general application, apply for a specific hot topic that we are recruiting an author for, or submit your own idea.
Table of Contents
Preface
This book is all about how to develop Reactive systems using the Functional Reactive Programming (FRP) style. It is a combination of both Functional Programming (FP) and Reactive Programming(RP) styles.
Scala is a multi-paradigm language that supports both FP and RP very well. It also has an AP (Asynchronous Programming) API. It supports Concurrency and true Parallelism using the Future API and Akka's Actor Model.
We will develop a couple of Reactive microservices using Lightbend's Reactive Platform, that is, Scala, Akka, Akka Streams, Play Framework, and Lagom Framework. We will deploy and test our Reactive system into Lightbend's ConductR sandbox environment.
Who this book is for
This book is for Scala developers who have knowledge of the basics of Scala, SBT, and the IntelliJ IDEA and want to update their skills to develop Reactive microservices using Lightbend's Reactive Platform.
What this book covers
, Getting started With Reactive and Functional Programming, covers the FP, RP, and FRP paradigm in detail. It covers the Reactive Manifesto and explains how it solves most of the current systems' issues. It also discusses the Actor Model and the Shared-State Concurrency model. This chapter ends with Marble diagrams.
, Functional Scala, explains some of Scala's important Functional Programming features at a high level with some simple and useful examples.
, Asynchronous Programming with Scala, explains Scala's Future API, how it solves Concurrency issues, and how it supports asynchronous programming.
, Building Reactive Applications with Akka, explains about the Actor Model and Akka Toolkit concepts. It demonstrates how to develop Reactive applications using Akka's Actor Model and how it solves shared-state concurrency issues.