Copyright Ā© 2016 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, and its dealers and distributors will be held liable for any damages caused or alleged to be 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.
First published: October 2016
Production reference: 1141016
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham
B3 2PB, UK.
ISBN 978-1-78646-502-3
www.packtpub.com
Christian Baxter, from an early age, has always had an interest in understanding how things worked. Growing up, he loved challenges and liked to tinker with and fix things. This inquisitive nature was the driving force that eventually led him into computer programming. While his primary focus in college was life sciences, he always set aside time to study computers and to explore all aspects of computer programming. When he graduated from college during the height of the Internet boom, he taught himself the necessary skills to get a job as a programmer. Heās been happily programming ever since, working across diverse industries such as insurance, travel, recruiting, and advertising. He loves building out high-performance distributed systems using Scala on the Akka platform.
Christian was a long time Java programmer before making the switch over to Scala in 2010. He was looking for new technologies to build out high throughput and asynchronous systems and loved what he saw from Scala and Akka. Since then, he's been a major advocate for Akka, getting multiple ad tech companies heās worked for to adopt it as a means of building out reactive applications. He's also been an occasional contributor to the Akka codebase, identifying and helping to fix issues. When heās not hacking away on Scala and Akka, you can usually find him answering questions on Stackoverflow as cmbaxter.
A lot went into the writing of this book, and not just from me. As such, Iād like to thank a few people, starting with the two special women in my life.
To my beautiful wife, Laurie. Thank you for being so patient throughout the writing of this book, and with me, in general. All this time, youāve somehow been able to put up with all my quirks, which is a feat in and of itself. Youāve always believed in me, even if, at times, I didnāt believe in myself. Thank you for always challenging me and never letting me be complacent. Without you, this book would have never been possible.
To my amazing mother, you taught me how to be a good person by instilling in me the values one needs to be successful in life. Your strength of character and resilience to lifeās challenges have served as inspirations to me. Youāve always been there for me, no matter how hard the times got. For this, I am eternally grateful.
Lastly, Iād like to thank my very first mentor, Dan Gallagher. I learned so much from you during our time together. Who knows how my career would have ended up if you werenāt there in the beginning to screw my head on straight. I appreciate the enormous amount of patience that must have gone into dealing with me way back then. Thank you so much for starting my career down the right path to where I am today.
Dennis Vriend is a professional with more than 10 years of experience in programming for the Java Virtual Machine. Over the last 4 years, Dennis has been developing and designing fault tolerant, scalable, distributed, and highly performant systems using Scala, Akka, and Spark, and maintaining them across multiple servers. Dennis is active in the open source community and maintains two very successful Akka pluginsāthe akka-persistence-jdbc plugin and the akka-persistence-inmemory plugināboth useful to design and test state of the art business components leveraging domain-driven design and event sourcing in a distributed environment. Dennis is currently working as a software development engineer for Trivento in the Netherlands.
For support files and downloads related to your book, please visit www.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
[email protected] 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.
https://www.packtpub.com/mapt
Get the most in-demand software skills with Mapt. Mapt gives you full access to all Packt books and video courses, as well as industry-leading tools to help you plan your personal development and advance your career.
- Fully searchable across every book published by Packt
- Copy and paste, print, and bookmark content
- On demand and accessible via a web browser
The Akka library is well known in the Scala world for providing a means to build reactive applications. Akkaās core building block is the Actor, which is a simple concurrency unit that allows you to build asynchronous, event driven, fault tolerant, and potentially distributed components on top of. Actors are an excellent starting point to build your reactive applications and services on top of, but thereās a lot more within the entire Akka platform that you should be considering as well.
This book will provide the reader with a purpose-built tour through some of the additional modules within the Akka platform. The tour will be conducted by progressively refactoring an initial Akka application from an inflexible monolith all the way to a set of loosely coupled microservices. Along the way, you will learn how to apply new features, such as event sourcing via Akka Persistence, to the application in an effort to help it scale better. When the journey is complete, you will have a much better understanding of these additional offerings within the Akka platform and how they can help you build your applications and services.
Throughout the refactoring process, new concepts and libraries within Akka will be introduced to the reader on a chapter by chapter basis. Within those chapters, I will detail what each new feature is, and how that feature fits into breaking down a monolith into a set of loosely coupled services. Each chapter will also involve coding homework for the reader, giving them an active role in the progressive refactoring process. This hands-on experience will give the reader an immersive understanding of how to use these newer Akka features in the real-world code, which is the main goal of this book.
Chapter 1, Building a Better Reactive App, introduces you to the initial sample application and how it will be improved over the course of this book.
Chapter 2, Simplifying Concurrent Programming with Actors, is a refresher on Actors with some refactoring work using Akkaās FSM.
Chapter 3, Curing Anemic Models with Domain-Driven Design, introduces you to domain-driven design (DDD) and how it helps in modeling and building software.
Chapter 4, Making History with Event Sourcing, presents Akka Persistence as a means to build event-sourced entities.
Chapter 5, Separating Concerns with CQRS, teaches you how to separate read and write models using the CQRS pattern.
Chapter 6, Going with the Flow with Akka Streams, explains how Akka Streams can be used to build back-pressure aware, stream-based processing components.
Chapter 7, REST Easy with Akka HTTP, shows you how to leverage Akka HTTP to build and consume RESTful interfaces.
Chapter 8, Scaling Out with Akka Remoting/Clustering, demonstrates how to use remoting and clustering to gain horizontal scalability and high availability.
Chapter 9, Managing Deployments with ConductR, illustrates building, deploying, and locating your microservices with ConductR.
Chapter 10, Troubleshooting and Best Practices, presents a few final tips and best practices for using Akka.
What you need for this book
You will need a computer (Windows or Mac OS X) with Java 8 installed on it. You will need to have Simple Build Tool (sbt) installed on that computer as well. This book also leverages Docker, with the installation of Docker being covered in more detail in Chapter 1, Building a Better Reactive App.
If you want to use the Lightbend platform to create highly-performant reactive applications, then this book is for you. If you are a Scala developer looking for techniques to use all features of the new Akka release and want to incorporate these solutions in your current or new projects, then this book is for you. Expert Java developers who want to build scalable, concurrent, and reactive application will find this book helpful.
In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.
Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "If you want to stop a Docker container, use the docker stop
command, supplying the name of the container you want to stop."
A block of code is set as follows:
{ "firstName": "Chris", "lastName": "Baxter", "email": "[email protected]" }
Any command-line input or output is written as follows:
docker-build.sh
New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in th...