Clement Escoer
Building Reactive
Microservices in Java
Asynchronous and Event-Based
Application Design
Boston Farnham Sebastopol
Tokyo
Beijing Boston Farnham Sebastopol
Tokyo
Beijing
978-1-491-98626-4
[LSI]
Building Reactive Microservices in Java
by Clement Escoffier
Copyright © 2017 O’Reilly Media. All rights reserved.
Printed in the United States of America.
Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA
95472.
O’Reilly books may be purchased for educational, business, or sales promotional use.
Online editions are also available for most titles (http://oreilly.com/safari). For more
information, contact our corporate/institutional sales department: 800-998-9938 or
corporate@oreilly.com.
Editor: Brian Foster
Production Editor: Shiny Kalapurakkel
Copyeditor: Christina Edwards
Proofreader: Sonia Saruba
Interior Designer: David Futato
Cover Designer: Karen Montgomery
Illustrator: Rebecca Demarest
May 2017:
First Edition
Revision History for the First Edition
2017-04-06: First Release
The O’Reilly logo is a registered trademark of O’Reilly Media, Inc. Building Reactive
Microservices in Java, the cover image, and related trade dress are trademarks of
O’Reilly Media, Inc.
While the publisher and the author have used good faith efforts to ensure that the
information and instructions contained in this work are accurate, the publisher and
the author disclaim all responsibility for errors or omissions, including without limi‐
tation responsibility for damages resulting from the use of or reliance on this work.
Use of the information and instructions contained in this work is at your own risk. If
any code samples or other technology this work contains or describes is subject to
open source licenses or the intellectual property rights of others, it is your responsi‐
bility to ensure that your use thereof complies with such licenses and/or rights.
Table of Contents
1. Introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Preparing Your Environment 2
2.
Understanding Reactive Microservices and Vert.x. . . . . . . . . . . . . . . . 3
Reactive Programming 4
Reactive Systems 7
Reactive Microservices 8
What About Vert.x ? 9
Asynchronous Development Model 11
Verticles—the Building Blocks 14
From Callbacks to Observables 15
Let’s Start Coding! 17
Summary 21
3.
Building Reactive Microservices. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
First Microservices 23
Implementing HTTP Microservices 24
Consuming HTTP Microservices 28
Are These Microservices Reactive Microservices? 31
The Vert.x Event Bus—A Messaging Backbone 32
Message-Based Microservices 33
Initiating Message-Based Interactions 35
Are We Reactive Now? 37
Summary 40
4.
Building Reactive Microservice Systems. . . . . . . . . . . . . . . . . . . . . . . . 43
Service Discovery 43
Stability and Resilience Patterns 47
Summary 54
iii