100% found this document useful (1 vote)
260 views

Full Download Learn Microservices with Spring Boot: A Practical Approach to RESTful Services Using an Event-Driven Architecture, Cloud-Native Patterns, and Containerization 2nd Edition Moisés Macero García PDF DOCX

Macero

Uploaded by

gkavaaehvik
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
260 views

Full Download Learn Microservices with Spring Boot: A Practical Approach to RESTful Services Using an Event-Driven Architecture, Cloud-Native Patterns, and Containerization 2nd Edition Moisés Macero García PDF DOCX

Macero

Uploaded by

gkavaaehvik
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 52

Download the full version of the textbook now at textbookfull.

com

Learn Microservices with Spring Boot: A


Practical Approach to RESTful Services Using
an Event-Driven Architecture, Cloud-Native
Patterns, and Containerization 2nd Edition
Moisés Macero García
https://textbookfull.com/product/learn-
microservices-with-spring-boot-a-practical-
approach-to-restful-services-using-an-event-
driven-architecture-cloud-native-patterns-and-
containerization-2nd-edition-moises-macero-garcia/

Explore and download more textbook at https://textbookfull.com


Recommended digital products (PDF, EPUB, MOBI) that
you can download immediately if you are interested.

Learn Microservices with Spring Boot: A Practical Approach


to RESTful Services using RabbitMQ, Eureka, Ribbon, Zuul
and Cucumber 1st Edition Moises Macero (Auth.)
https://textbookfull.com/product/learn-microservices-with-spring-boot-
a-practical-approach-to-restful-services-using-rabbitmq-eureka-ribbon-
zuul-and-cucumber-1st-edition-moises-macero-auth/
textbookfull.com

Practical Microservices Architectural Patterns: Event-


Based Java Microservices with Spring Boot and Spring Cloud
Christudas
https://textbookfull.com/product/practical-microservices-
architectural-patterns-event-based-java-microservices-with-spring-
boot-and-spring-cloud-christudas/
textbookfull.com

Practical Microservices Architectural Patterns - Event-


Based Java Microservices with Spring Boot and Spring Cloud
1st Edition Binildas Christudas
https://textbookfull.com/product/practical-microservices-
architectural-patterns-event-based-java-microservices-with-spring-
boot-and-spring-cloud-1st-edition-binildas-christudas/
textbookfull.com

The Black Dog Days 1st Edition Taylor Newman

https://textbookfull.com/product/the-black-dog-days-1st-edition-
taylor-newman/

textbookfull.com
In a Cowboy s Arms Home Series Book 2 1st Edition Krista
Ames [Ames

https://textbookfull.com/product/in-a-cowboy-s-arms-home-series-
book-2-1st-edition-krista-ames-ames/

textbookfull.com

Homer s Allusive Art 1st Edition Bruno Currie

https://textbookfull.com/product/homer-s-allusive-art-1st-edition-
bruno-currie/

textbookfull.com

Koren Talmud Bavli Noe Edition Volume 29 Sanhedrin Part 1


Hebrew English Large Color Edition Adin Steinsaltz

https://textbookfull.com/product/koren-talmud-bavli-noe-edition-
volume-29-sanhedrin-part-1-hebrew-english-large-color-edition-adin-
steinsaltz/
textbookfull.com

Handbook of milk of non-bovine mammals Second Edition


Young W. Park

https://textbookfull.com/product/handbook-of-milk-of-non-bovine-
mammals-second-edition-young-w-park/

textbookfull.com

E cole de Physique des Houches Session CII 7 July 1 August


2014 From molecules to living organisms an interplay
between biology and physics 1st Edition Cugliandolo
https://textbookfull.com/product/e-cole-de-physique-des-houches-
session-cii-7-july-1-august-2014-from-molecules-to-living-organisms-
an-interplay-between-biology-and-physics-1st-edition-cugliandolo/
textbookfull.com
The Electronic Doppelgänger The Mystery of the Double in
the Age of the Internet 1st Edition Rudolf Steiner

https://textbookfull.com/product/the-electronic-doppelganger-the-
mystery-of-the-double-in-the-age-of-the-internet-1st-edition-rudolf-
steiner/
textbookfull.com
Learn
Microservices
with Spring Boot
A Practical Approach to RESTful Services
Using an Event-Driven Architecture,
Cloud-Native Patterns, and Containerization

Second Edition

Moisés Macero García
Learn Microservices
with Spring Boot
A Practical Approach to RESTful
Services Using an Event-Driven
Architecture, Cloud-Native Patterns,
and Containerization
Second Edition

Moisés Macero García


Learn Microservices with Spring Boot: A Practical Approach to RESTful Services
Using an Event-Driven Architecture, Cloud-­Native Patterns, and Containerization

Moisés Macero García


New York, NY, USA

ISBN-13 (pbk): 978-1-4842-6130-9 ISBN-13 (electronic): 978-1-4842-6131-6


https://doi.org/10.1007/978-1-4842-6131-6

Copyright © 2020 by Moisés Macero García


This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the
material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation,
broadcasting, reproduction on microfilms or in any other physical way, and transmission or information
storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now
known or hereafter developed.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with
every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an
editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the
trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not
identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to
proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of publication,
neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or
omissions that may be made. The publisher makes no warranty, express or implied, with respect to the
material contained herein.
Managing Director, Apress Media LLC: Welmoed Spahr
Acquisitions Editor: Steve Anglin
Development Editor: Matthew Moodie
Coordinating Editor: Mark Powers
Cover designed by eStudioCalamar
Cover image by Ash from Modern Afflatus on Unsplash (www.unsplash.com)
Distributed to the book trade worldwide by Apress Media, LLC, 1 New York Plaza, New York, NY 10004,
U.S.A. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail [email protected], or visit www.
springeronline.com. Apress Media, LLC is a California LLC and the sole member (owner) is Springer
Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation.
For information on translations, please e-mail [email protected]; for reprint,
paperback, or audio rights, please e-mail [email protected].
Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and
licenses are also available for most titles. For more information, reference our Print and eBook Bulk Sales
web page at www.apress.com/bulk-sales.
Any source code or other supplementary material referenced by the author in this book is available to
readers on GitHub via the book’s product page, located at www.apress.com/9781484261309. For more
detailed information, please visit www.apress.com/source-code.
Printed on acid-free paper
To my family, especially to my mom and my wife. All of you keep
teaching me many things, amongst them care, love, and curiosity,
the most important learnings in life.
In memory of my dad, an engineer at heart. You encouraged me to
keep learning, sparked my curiosity thanks to your inventions,
and taught me to be pragmatic to solve the problem at hand.
This book has a bit of all of you.
Table of Contents
About the Author��������������������������������������������������������������������������������������������������� xiii

About the Technical Reviewers�������������������������������������������������������������������������������xv

Chapter 1: Setting the Scene������������������������������������������������������������������������������������ 1


Who Are You?�������������������������������������������������������������������������������������������������������������������������������� 2
How Is This Book Different from Other Books and Guides?���������������������������������������������������������� 3
Learning: An Incremental Process������������������������������������������������������������������������������������������� 3
Is This a Guide or a Book?������������������������������������������������������������������������������������������������������� 4
From Basics to Advanced Topics��������������������������������������������������������������������������������������������������� 4
Skeleton with Spring Boot, the Professional Way�������������������������������������������������������������������� 5
Test-Driven Development�������������������������������������������������������������������������������������������������������� 5
Microservices�������������������������������������������������������������������������������������������������������������������������� 6
Event-Driven System��������������������������������������������������������������������������������������������������������������� 6
Nonfunctional Requirements��������������������������������������������������������������������������������������������������� 6
Online Content������������������������������������������������������������������������������������������������������������������������������ 7
Summary�������������������������������������������������������������������������������������������������������������������������������������� 7

Chapter 2: Basic Concepts���������������������������������������������������������������������������������������� 9


Spring������������������������������������������������������������������������������������������������������������������������������������������� 9
Spring Boot��������������������������������������������������������������������������������������������������������������������������������� 10
Lombok and Java������������������������������������������������������������������������������������������������������������������������ 12
Testing Basics����������������������������������������������������������������������������������������������������������������������������� 15
Test-Driven Development������������������������������������������������������������������������������������������������������ 15
Behavior-Driven Development����������������������������������������������������������������������������������������������� 15
JUnit�������������������������������������������������������������������������������������������������������������������������������������� 16
Mockito���������������������������������������������������������������������������������������������������������������������������������� 17
AssertJ���������������������������������������������������������������������������������������������������������������������������������� 20

v
Table of Contents

Testing in Spring Boot����������������������������������������������������������������������������������������������������������������� 21


Logging��������������������������������������������������������������������������������������������������������������������������������������� 21
Summary and Achievements������������������������������������������������������������������������������������������������������ 23

Chapter 3: A Basic Spring Boot Application����������������������������������������������������������� 25


Setting Up the Development Environment���������������������������������������������������������������������������������� 26
The Skeleton Web App���������������������������������������������������������������������������������������������������������������� 27
Spring Boot Autoconfiguration���������������������������������������������������������������������������������������������������� 31
Three-Tier, Three-Layer Architecture������������������������������������������������������������������������������������������ 36
Modeling Our Domain����������������������������������������������������������������������������������������������������������������� 39
Domain Definition and Domain-Driven Design���������������������������������������������������������������������� 39
Domain Classes��������������������������������������������������������������������������������������������������������������������� 41
Business Logic���������������������������������������������������������������������������������������������������������������������������� 43
What We Need����������������������������������������������������������������������������������������������������������������������� 44
Random Challenges��������������������������������������������������������������������������������������������������������������� 44
Attempt Verification��������������������������������������������������������������������������������������������������������������� 48
Presentation Layer���������������������������������������������������������������������������������������������������������������������� 52
REST�������������������������������������������������������������������������������������������������������������������������������������� 52
REST APIs with Spring Boot��������������������������������������������������������������������������������������������������� 53
Designing Our APIs���������������������������������������������������������������������������������������������������������������� 55
Our First Controller���������������������������������������������������������������������������������������������������������������� 56
How Automatic Serialization Works��������������������������������������������������������������������������������������� 58
Testing Controllers with Spring Boot������������������������������������������������������������������������������������� 61
Summary and Achievements������������������������������������������������������������������������������������������������������ 73

Chapter 4: A Minimal Front End with React����������������������������������������������������������� 75


A Quick Intro to React and Node������������������������������������������������������������������������������������������������� 76
Setting Up the Development Environment���������������������������������������������������������������������������������� 76
The React Skeleton��������������������������������������������������������������������������������������������������������������������� 78
A JavaScript Client���������������������������������������������������������������������������������������������������������������������� 80

vi
Table of Contents

The Challenge Component���������������������������������������������������������������������������������������������������������� 81


The Main Structure of a Component�������������������������������������������������������������������������������������� 85
Rendering������������������������������������������������������������������������������������������������������������������������������ 87
Integration with the App�������������������������������������������������������������������������������������������������������� 89
Running Our Front End for the First Time������������������������������������������������������������������������������������ 90
Debugging����������������������������������������������������������������������������������������������������������������������������������� 91
Adding CORS Configuration to the Spring Boot App�������������������������������������������������������������������� 93
Playing with the Application�������������������������������������������������������������������������������������������������������� 94
Deploying the React App������������������������������������������������������������������������������������������������������������� 95
Summary and Achievements������������������������������������������������������������������������������������������������������ 98

Chapter 5: The Data Layer������������������������������������������������������������������������������������ 101


The Data Model������������������������������������������������������������������������������������������������������������������������� 102
Choosing a Database���������������������������������������������������������������������������������������������������������������� 105
SQL vs. NoSQL��������������������������������������������������������������������������������������������������������������������� 105
H2, Hibernate, and JPA�������������������������������������������������������������������������������������������������������� 106
Spring Boot Data JPA���������������������������������������������������������������������������������������������������������������� 107
Dependencies and Autoconfiguration���������������������������������������������������������������������������������� 107
Spring Boot Data JPA Technology Stack������������������������������������������������������������������������������ 111
Data Source (Auto)configuration����������������������������������������������������������������������������������������� 113
Entities�������������������������������������������������������������������������������������������������������������������������������������� 115
Repositories������������������������������������������������������������������������������������������������������������������������������ 120
Storing Users and Attempts������������������������������������������������������������������������������������������������������ 124
Displaying Last Attempts���������������������������������������������������������������������������������������������������������� 130
Service Layer����������������������������������������������������������������������������������������������������������������������� 130
Controller Layer������������������������������������������������������������������������������������������������������������������� 132
User Interface���������������������������������������������������������������������������������������������������������������������� 138
Playing with the New Feature��������������������������������������������������������������������������������������������������� 144
Summary and Achievements���������������������������������������������������������������������������������������������������� 146

vii
Table of Contents

Chapter 6: Starting with Microservices���������������������������������������������������������������� 149


The Small Monolith Approach��������������������������������������������������������������������������������������������������� 149
Why a Small Monolith?������������������������������������������������������������������������������������������������������������� 150
The Problems with Microservices from Day Zero���������������������������������������������������������������� 150
Small Monoliths Are for Small Teams���������������������������������������������������������������������������������� 151
Embracing Refactoring�������������������������������������������������������������������������������������������������������� 152
Planning the Small Monolith for a Future Split������������������������������������������������������������������������� 152
New Requirements and Gamification��������������������������������������������������������������������������������������� 154
Gamification: Points, Badges, and Leaderboards���������������������������������������������������������������� 155
Moving to Microservices����������������������������������������������������������������������������������������������������������� 156
Independent Workflows������������������������������������������������������������������������������������������������������� 157
Horizontal Scalability����������������������������������������������������������������������������������������������������������� 158
Fine-Grained Nonfunctional Requirements������������������������������������������������������������������������� 160
Other Advantages���������������������������������������������������������������������������������������������������������������� 160
Disadvantages��������������������������������������������������������������������������������������������������������������������� 161
Architecture Overview�������������������������������������������������������������������������������������������������������������� 163
Designing and Implementing the New Service������������������������������������������������������������������������� 164
Interfaces���������������������������������������������������������������������������������������������������������������������������� 165
The Spring Boot Skeleton for Gamification������������������������������������������������������������������������� 165
Domain�������������������������������������������������������������������������������������������������������������������������������� 166
Service�������������������������������������������������������������������������������������������������������������������������������� 172
Data������������������������������������������������������������������������������������������������������������������������������������� 183
Controller����������������������������������������������������������������������������������������������������������������������������� 186
Configuration����������������������������������������������������������������������������������������������������������������������� 188
Changes in Multiplication Microservice������������������������������������������������������������������������������ 190
UI����������������������������������������������������������������������������������������������������������������������������������������� 195
Playing with the System����������������������������������������������������������������������������������������������������������� 201
Fault Tolerance�������������������������������������������������������������������������������������������������������������������������� 203
The Challenges Ahead��������������������������������������������������������������������������������������������������������������� 205
Tight Coupling���������������������������������������������������������������������������������������������������������������������� 206
Synchronous Interfaces vs. Eventual Consistency�������������������������������������������������������������� 206

viii
Table of Contents

Transactions������������������������������������������������������������������������������������������������������������������������ 211
API Exposure������������������������������������������������������������������������������������������������������������������������ 213
Summary and Achievements���������������������������������������������������������������������������������������������������� 213

Chapter 7: Event-Driven Architectures����������������������������������������������������������������� 215


Core Concepts��������������������������������������������������������������������������������������������������������������������������� 215
The Message Broker������������������������������������������������������������������������������������������������������������ 216
Events and Messages���������������������������������������������������������������������������������������������������������� 218
Thinking in Events��������������������������������������������������������������������������������������������������������������� 219
Asynchronous Messaging���������������������������������������������������������������������������������������������������� 223
Reactive Systems���������������������������������������������������������������������������������������������������������������� 226
Pros and Cons of Going Event-Driven��������������������������������������������������������������������������������������� 226
Messaging Patterns������������������������������������������������������������������������������������������������������������������ 229
Publish-Subscribe��������������������������������������������������������������������������������������������������������������� 230
Work Queues����������������������������������������������������������������������������������������������������������������������� 230
Filtering������������������������������������������������������������������������������������������������������������������������������� 230
Data Durability��������������������������������������������������������������������������������������������������������������������� 230
Message Broker Protocols, Standards, and Tools��������������������������������������������������������������������� 231
AMQP and RabbitMQ����������������������������������������������������������������������������������������������������������������� 232
Overall Description�������������������������������������������������������������������������������������������������������������� 233
Exchange Types and Routing����������������������������������������������������������������������������������������������� 234
Message Acknowledgments and Rejection������������������������������������������������������������������������� 236
Setting Up RabbitMQ����������������������������������������������������������������������������������������������������������������� 237
Spring AMQP and Spring Boot�������������������������������������������������������������������������������������������������� 239
Solution Design������������������������������������������������������������������������������������������������������������������������� 239
Adding the AMQP Starter����������������������������������������������������������������������������������������������������� 241
Event Publishing from Multiplication����������������������������������������������������������������������������������� 243
Gamification as a Subscriber���������������������������������������������������������������������������������������������� 250
Analysis of Scenarios���������������������������������������������������������������������������������������������������������������� 259
Happy Flow�������������������������������������������������������������������������������������������������������������������������� 260
Gamification Becomes Unavailable������������������������������������������������������������������������������������� 266

ix
Table of Contents

The Message Broker Becomes Unavailable������������������������������������������������������������������������ 269


Transactionality������������������������������������������������������������������������������������������������������������������� 270
Scaling Up Microservices���������������������������������������������������������������������������������������������������� 274
Summary and Achievements���������������������������������������������������������������������������������������������������� 279

Chapter 8: Common Patterns in Microservice Architectures������������������������������� 283


Gateway������������������������������������������������������������������������������������������������������������������������������������ 284
Spring Cloud Gateway��������������������������������������������������������������������������������������������������������� 286
The Gateway Microservice�������������������������������������������������������������������������������������������������� 290
Changes in Other Projects��������������������������������������������������������������������������������������������������� 294
Running the Gateway Microservice������������������������������������������������������������������������������������� 296
Next Steps��������������������������������������������������������������������������������������������������������������������������� 297
Health���������������������������������������������������������������������������������������������������������������������������������������� 298
Spring Boot Actuator����������������������������������������������������������������������������������������������������������� 299
Including Actuator in Our Microservices����������������������������������������������������������������������������� 302
Service Discovery and Load Balancing������������������������������������������������������������������������������������� 304
Consul���������������������������������������������������������������������������������������������������������������������������������� 310
Spring Cloud Consul������������������������������������������������������������������������������������������������������������ 312
Spring Cloud Load Balancer������������������������������������������������������������������������������������������������ 319
Service Discovery and Load Balancing in the Gateway������������������������������������������������������� 323
Playing with Service Discovery and Load Balancing����������������������������������������������������������� 327
Configuration per Environment������������������������������������������������������������������������������������������������� 337
Configuration in Consul������������������������������������������������������������������������������������������������������� 340
Spring Cloud Consul Config������������������������������������������������������������������������������������������������� 341
Implementing Centralized Configuration����������������������������������������������������������������������������� 343
Centralized Configuration in Practice���������������������������������������������������������������������������������� 347
Centralized Logs����������������������������������������������������������������������������������������������������������������������� 355
Log Aggregation Pattern������������������������������������������������������������������������������������������������������ 356
A simple Solution for Log Centralization����������������������������������������������������������������������������� 357
Consuming Logs and Printing Them������������������������������������������������������������������������������������ 361

x
Visit https://textbookfull.com
now to explore a rich
collection of eBooks, textbook
and enjoy exciting offers!
Table of Contents

Distributed Tracing�������������������������������������������������������������������������������������������������������������������� 368


Spring Cloud Sleuth������������������������������������������������������������������������������������������������������������� 369
Implementing Distributed Tracing��������������������������������������������������������������������������������������� 371
Containerization������������������������������������������������������������������������������������������������������������������������ 373
Docker��������������������������������������������������������������������������������������������������������������������������������� 376
Spring Boot and Buildpacks������������������������������������������������������������������������������������������������ 380
Running Our System in Docker�������������������������������������������������������������������������������������������� 381
Dockerizing Microservices�������������������������������������������������������������������������������������������������� 382
Dockerizing the UI��������������������������������������������������������������������������������������������������������������� 383
Dockerizing the Configuration Importer������������������������������������������������������������������������������ 384
Docker Compose����������������������������������������������������������������������������������������������������������������� 387
Scaling Up the System with Docker������������������������������������������������������������������������������������ 401
Sharing Docker Images������������������������������������������������������������������������������������������������������� 404
Platforms and Cloud-Native Microservices������������������������������������������������������������������������������� 408
Container Platforms������������������������������������������������������������������������������������������������������������� 408
Application Platforms���������������������������������������������������������������������������������������������������������� 410
Cloud Providers������������������������������������������������������������������������������������������������������������������� 410
Making a Decision��������������������������������������������������������������������������������������������������������������� 412
Cloud-Native Microservices������������������������������������������������������������������������������������������������ 413
Conclusions������������������������������������������������������������������������������������������������������������������������������� 413

Afterword�������������������������������������������������������������������������������������������������������������� 417

Index��������������������������������������������������������������������������������������������������������������������� 419

xi
About the Author
Moisés Macero García has been a software developer since
he was a kid, when he started playing around with BASIC on
his ZX Spectrum. During his career, Moisés has most often
worked in development and architecture for small and large
projects, and for his own startups too. He enjoys making
software problems simple, and he likes working in teams
where he not only coaches others but also learns from them.
Moisés is the author of the blog
thepracticaldeveloper.com, where he shares solutions
for technical challenges, guides, and his view on ways of
working in IT companies. He also organizes workshops
for companies that need a practical approach to software engineering. In his free time,
he enjoys traveling and hiking. You can follow Moisés or contact him on his Twitter
account: @moises_macero.

xiii
About the Technical Reviewers
Diego Rosado Fuentes has always enjoyed computers,
electronics, and programming. As a child, he liked to
disassemble computers and electronic toys. After finishing
his studies as a computer science engineer, he started
working as a software developer. He worked in several
companies, beginning in startups and later in bigger
companies. He has been working as a software developer
but always somehow doing stuff related to teaching and
learning, which he loves.
He likes physics, astronomy, biology, and all sciences,
but he also enjoys reading a novel now and then. He considers himself a proactive
curious human being trying always to learn something new and comprehend every day
a little bit more of all the unrevealed mysteries still to come. You can find him on his
Twitter account: @rosado_diego.

Vinay Kumtar is a technology evangelist. He has extensive experience in designing and


implementing large-scale projects in enterprise technologies in various consulting and
system integration companies. He started working in middleware/integration in 2008
and fell in love with it. His passion helped him achieve certifications in Oracle ADF,
Oracle SOA, BPM, WebCenter Portal, and Java. Experience and in-depth knowledge have
helped him evolve into a focused domain expert and a well-known technical blogger. He
loves to spend his time mentoring, writing professional blogs, publishing white papers,
and maintaining a dedicated education channel at YouTube for ADF/Webcenter. Vinay
has been contributing to various topics, such as Oracle ­SOA/BPM/Webcenter/Kafka/
microservices/events, for the community by publishing technical articles on his blog
Techartifact.com that has 250+ articles. He is a technology leader and currently leading
two major digital transformation projects.

xv
About the Technical Reviewers

Manuel Jordan Elera is an autodidactic developer and


researcher who enjoys learning new technologies for his own
experiments, which focus on finding new ways to integrate them.
Manuel won the 2010 Springy Award – Community
Champion and Spring Champion 2013. In his little free time,
he reads the Bible and composes music on his bass and
guitar.
Manuel believes that constant education/training
is essential for all developers. You can reach him mostly
through his Twitter account: @dr_pompeii.

xvi
CHAPTER 1

Setting the Scene


Microservices are becoming more popular and widely used these days. This is not a
surprise; this software architecture style has many advantages, such as flexibility and
ease of scale. Mapping microservices into small teams in an organization also gives you
a lot of efficiency in development. However, going on the adventure of microservices
knowing only the benefits is a wrong call. Distributed systems introduce extra
complexity, so you need to understand what you are facing and be prepared for that in
advance. You can get a lot of knowledge from many books and articles on the Internet,
but when you get hands-on with the code, the story changes.
This book covers some of the most important concepts of microservices in a
practical way, but not without explaining those concepts. First, we define a use case:
an application to build. Then we start with a small monolith, based on some sound
reasoning. Once we have the minimal application in place, we evaluate whether it’s
worthy to move to microservices, and what would be a good way to do so. With the
introduction of the second microservice, we analyze the options we have for their
communication. Then, we can describe and implement the event-driven architecture
pattern to reach loose coupling by informing other parts of the system about what
happened, instead of explicitly calling others to action. When we reach that point, we
notice that a poorly designed distributed system has some flaws that we have to fix
with some popular patterns: service discovery, routing, load balancing, traceability,
etc. Adding them one by one to our codebase instead of presenting all of them together
helps us understand these patterns. We also prepare these microservices for a cloud
deployment using Docker and compare the different platform alternatives to run the
applications.
The advantage of going step-by-step, pausing when it’s needed to settle down
the concepts, is that you will understand which problem each tool is trying to solve.
That’s why the evolving example is an essential part of this book. You can also grasp
the concepts without coding one single line since the source code is presented and
explained throughout the chapters.

1
© Moisés Macero García 2020
M. Macero García, Learn Microservices with Spring Boot, https://doi.org/10.1007/978-1-4842-6131-6_1
Chapter 1 Setting the Scene

All the code included in this book is available on GitHub in the project Book-­
Microservices-­v2. There are multiple repositories available, divided into chapters and
sections, which makes it easier for you to see how the application evolves. The book
includes notes with the version that is being covered in each part.

Who Are You?


Let’s first start with this: how interesting is this book going to be for you? This book is
practical, so let’s play this game. If you identify with any of these statements, this book
might be good for you:

• “I would like to learn how to build microservices with Spring Boot


and how to use the related tools.”

• “Everybody is talking about microservices, but I have no clue what


a microservice is yet. I have read only theoretical explanations or
just hype-enforcing articles. I can’t understand the advantages, even
though I work in IT….”

• “I would like to learn how to design and develop Spring Boot


applications, but all I find are either quick-start guides with too
simple examples or lengthy books that resemble the official
documentation. I would like to learn the concepts following a more
realistic project-guided approach.”

• “I got a new job, and they’re using a microservices architecture. I’ve


been working mainly in big, monolithic projects, so I’d like to have
some knowledge and guidance to learn how everything works there,
as well as the pros and cons of this architecture.”

• “Every time I go to the cafeteria developers are talking about


microservices, gateways, service discovery, containers, resilience
patterns, etc. I can’t socialize anymore with my colleagues if I don’t
get what they’re saying.” (This one is a joke; don’t read this book
because of that, especially if you’re not interested in programming.)

2
Chapter 1 Setting the Scene

Regarding the knowledge required to read this book, the following topics should be
familiar to you:

• Java (we use Java 14)

• Spring (you don’t need strong experience, but you should know at
least how dependency injection works)

• Maven (if you know Gradle, you’ll be fine as well)

 ow Is This Book Different from Other Books


H
and Guides?
Software developers and architects read many technical books and guides, either
because we’re interested in learning new technologies or because our work requires it.
We need to do that anyway since it’s a constantly changing world. We can find all kinds
of books and guides out there. Good ones are usually those from which you learn quickly
and that teach you not only how to do stuff but also why you should do it that way. Using
new techniques just because they’re new is the wrong way to go about it; you need to
understand the reasoning behind them so you use them in the best way possible.
This book uses that philosophy: it navigates through the code and design patterns,
explaining the reasons to follow one way and not others.

Learning: An Incremental Process


If you look at the guides available on the Internet, you’ll notice quickly that they are not
real-life examples. Usually, when you apply those cases to more complex scenarios, they
don’t fit. Guides are too shallow to help you build something real.
Books, on the other hand, are much better at that. There are plenty of good books
explaining concepts around an example; they are good because applying theoretical
concepts to code is not always easy if you don’t see the code. The problem with some
of these books is that they’re not as practical as guides. You need to read them first to
understand the concepts and then code (or see) the example, which is frequently given
as a whole piece. It’s difficult to put into practice concepts when you see the final version
directly. This book stays on the practical side and starts with code that evolves through
the chapters so that you grasp the concepts one by one. We cover the problem before
exposing the solution.
3
Chapter 1 Setting the Scene

Because of this incremental way of presenting concepts, this book also allows you to
code as you learn and to reflect on the challenges by yourself.

Is This a Guide or a Book?


The pages you have in front of you can’t be called a guide: it won’t take you 15 or 30
minutes to finish them. Besides, each chapter introduces all the required topics to lay the
foundations for the new code additions. But this is not the typical book either, in which
you go through isolated concepts illustrated with some scattered code fragments that are
made specifically for that situation. Instead, you start with a real-life application that is
not yet optimal, and you learn how to evolve it, after learning about the benefits you can
extract from that process.
That does not mean you can’t just sit down and read it, but it’s better if you code at
the same time and play with the options and alternatives presented. That’s the part of the
book that makes it similar to a guide.
In any case, to keep it simple, from here onward we call this a book.

From Basics to Advanced Topics


This book focuses first on some essential concepts to understand the rest of the
topics (Chapter 2): Spring Boot, testing, logging, etc. Then, it covers how to design
and implement a production-ready Spring Boot application using a well-known
layered design, and it dives into how to implement a REST API, the business logic, and
database repositories (Chapters 3 and 5). While doing it, you’ll see how Spring Boot
works internally so it’s not magic for you anymore. You’ll also learn how to build a basic
front-end application with React (Chapter 4), because that will help you visualize how
the backend architecture impacts the front end. After that, the book enters into the
microservices world with the introduction of a second piece of functionality in a different
Spring Boot app. The practical example helps you analyze the factors that you should
examine before making the decision of moving to microservices (Chapter 6). Then,
you’ll get to know the differences between communicating microservices synchronously
and asynchronously and how an event-driven architecture can help you keep your
system components decoupled (Chapter 7). From there, the book takes you through the
journey of tools and frameworks applicable to distributed systems to achieve important

4
Chapter 1 Setting the Scene

nonfunctional requirements: resilience, scalability, traceability, and deployment to the


cloud among others (Chapter 8).
If you are already familiar with Spring Boot applications and how they work, you
can go quickly through the first chapters and focus more on the second part of the book.
There, we cover more advanced topics such as event-driven design, service discovery,
routing, distributed tracing, testing with Cucumber, etc. However, pay attention to
the foundations we set up in the first part: test-driven development, the focus on the
minimum viable product (MVP), and monolith-first.

Skeleton with Spring Boot, the Professional Way


First, the book guides you through the creation of an application using Spring Boot. All
the contents mainly focus on the backend side, but you will create a simple web page
with React to demonstrate how to use the exposed functionality as a REST API.
It’s important to point out that we don’t create “shortcut code” just to showcase
Spring Boot features: that’s not the objective of this book. We use Spring Boot as a vehicle
to teach concepts, but we could use any other framework, and the ideas of this book
would still be valid.
You will learn how to design and implement the application following the well-­
known three-tier, three-layer pattern. You do this supported by an incremental example,
with hands-on code. While writing the applications, we’ll also pause a few times to get
into the details about how Spring Boot works with so little code (autoconfiguration,
starters, etc.).

T est-Driven Development
In the first chapters, we use test-driven development (TDD) to map the prerequisites
presented to technical features. This book tries to show this technique in a way that you
can see the benefits from the beginning: why it’s always a good idea to think about the
test cases before writing your code. JUnit 5, AssertJ, and Mockito will serve us to build
useful tests efficiently.
The plan is the following: you’ll learn how to create the tests first, then make them
fail, and finally implement the logic to make them work.

5
Chapter 1 Setting the Scene

Microservices
Once you have your first application ready, we introduce a second one that will interact
with the existing functionality. From that moment on, you’ll have a microservices
architecture. It doesn’t make any sense to try to understand the advantages of
microservices if you have only one of them. The real-life scenarios are always distributed
systems with functionality split into different services. As usual, to keep it practical, we’ll
analyze the specific situation for our case study, so you’ll see if moving to microservices
fits your needs.
The book covers not only the reasons to split the system but also the disadvantages
that come with that choice. Once you make the decision to move to microservices, you’ll
learn which patterns you should use to build a good architecture for the distributed
system: service discovery, routing, load balancing, distributed tracing, containerization,
and some other supporting mechanisms.

Event-Driven System
An additional concept that does not always need to come with microservices is an event-­
driven architecture. This book uses it since it’s a pattern that fits well into a microservice
architecture, and you’ll make your choice based on good examples. You’ll see what the
differences are between synchronous and asynchronous communication, as well as their
main pros and cons.
This asynchronous way of thinking introduces new ways of designing code, with
eventual consistency as one of the key changes to embrace. You’ll look at it while coding
your project, using RabbitMQ to send and receive messages between microservices.

Nonfunctional Requirements
When you build an application in the real world, you have to take into account some
requirements that are not directly related to functionalities, but they prepare your system
to be more robust, to keep working in the event of failures, or to ensure data integrity, as
some examples.
Many of these nonfunctional requirements are related to things that can go wrong
with your software: network failures that make part of your system unreachable, a
high traffic volume that collapses your backend capacity, external services that don’t
respond, etc.

6
Visit https://textbookfull.com
now to explore a rich
collection of eBooks, textbook
and enjoy exciting offers!
Chapter 1 Setting the Scene

In this book, you’ll learn how to implement and verify patterns to make the system
more resilient and scalable. In addition, we’ll discuss the importance of data integrity
and the tools that help us guarantee it.
The good part about learning how to design and solve all these nonfunctional
requirements is that it’s knowledge applicable to any system, no matter the
programming language and frameworks you’re using.

O
 nline Content
For this second edition of the book, I decided to create an online space where you can
keep learning new topics related to microservice architectures. On this web page, you’ll
find new guides that extend the practical use case covering other important aspects
of distributed systems. Additionally, new versions of the repositories using up-to-date
dependencies will be published there.
The first guide that you’ll find online is about testing a distributed system with
Cucumber. This framework helps us build human-readable test scripts to make sure our
functionalities work end to end.
Visit https://tpd.io/book-extra for all the extra content and new updates about the
book.

S
 ummary
This chapter introduced the main goals of this book: to teach you the main aspects of a
microservice architecture, by starting simple and then growing your knowledge through
the development of a sample project.
We also covered briefly the main content of the book: from monolith-first to
microservices with Spring Boot, test-driven development, event-driven systems,
common architecture patterns, nonfunctional requirements, and end-to-end testing
with Cucumber (online).
The next chapter will start with the first step of our learning path: a review of some
basic concepts.

7
CHAPTER 2

Basic Concepts
This book follows a practical approach, so most of the tools covered are introduced as
we need them. However, we’ll go over some core concepts separately because they’re
either the foundations of our evolving example or used extensively in the code examples,
namely, Spring, Spring Boot, testing libraries, Lombok, and logging. These concepts
deserve a separate introduction to avoid long interruptions in our learning path, which is
why this chapter gives an overview of them.
Keep in mind that the next sections are not intended to give you a full knowledge
base of these frameworks and libraries. The primary objective of this chapter is that
either you refresh the concepts in your mind (if you already learned them) or you grasp
the basics so that you don’t need to consult external references before reading the rest of
the chapters.

S
 pring
The Spring Framework is a vast set of libraries and tools simplifying software
development, namely, dependency injection, data access, validation,
internationalization, aspect-oriented programming, etc. It’s a popular choice for Java
projects, and it also works with other JVM-based languages such as Kotlin and Groovy.
One of the reasons why Spring is so popular is that it saves a lot of time by providing
built-in implementations for many aspects of software development, such as the
following:

• Spring Data simplifies data access for relational and NoSQL


databases.

• Spring Batch provides powerful processing for large volumes of


records.

9
© Moisés Macero García 2020
M. Macero García, Learn Microservices with Spring Boot, https://doi.org/10.1007/978-1-4842-6131-6_2
Chapter 2 Basic Concepts

• Spring Security is a security framework that abstracts security features


to applications.

• Spring Cloud provides tools for developers to quickly build some of


the common patterns in distributed systems.

• Spring Integration is an implementation of enterprise integration


patterns. It facilitates integration with other enterprise applications
using lightweight messaging and declarative adapters.

As you can see, Spring is divided into different modules. All of the modules are built
on top of the core Spring Framework, which establishes a common programming and
configuration model for software applications. This model itself is another important
reason to choose the framework since it facilitates good programming techniques such
as the use of interfaces instead of classes to decouple application layers via dependency
injection.
A key topic in Spring is the Inversion of Control (IoC) container, which is supported
by the ApplicationContext interface. Spring creates this “space” in your application
where you, and the framework itself, can put some object instances such as database
connection pools, HTTP clients, etc. These objects, called beans, can be later used in
other parts of your application, commonly through their public interface to abstract your
code from specific implementations. The mechanism to reference one of these beans
from the application context in other classes is what we call dependency injection, and in
Spring this is possible via XML configuration or code annotations.

Spring Boot
Spring Boot is a framework that leverages Spring to quickly create stand-alone
applications in Java-based languages. It has become a popular tool for building
microservices.
Having so many available modules in Spring and other related third-party libraries
that can be combined with the framework is powerful for software development. Yet,
despite a lot of efforts to make Spring configuration easier, you still need to spend
some time to set up everything you need for your application. And, sometimes, you
just require the same configuration over and over again. Bootstrapping an application,
meaning the process to configure your Spring application to have it up and running,
is sometimes tedious. The advantage of Spring Boot is that it eliminates most of that

10
Chapter 2 Basic Concepts

process by providing default configurations and tools that are set up automatically for
you. The main disadvantage is that if you rely too much on these defaults, you may
lose control and awareness of what’s happening. We’ll unveil some of the Spring Boot
implementations within the book to demonstrate how it works internally so that you can
be in control at all times.
Spring Boot provides some predefined starter packages that are like collections
of Spring modules and some third-party libraries and tools together. As an example,
spring-boot-starter-web helps you build a stand-alone web application. It groups
the Spring Core Web libraries with Jackson (JSON handling), validation, logging,
autoconfiguration, and even an embedded Tomcat server, among other tools.
In addition to starters, autoconfiguration plays a key role in Spring Boot. This feature
makes adding functionality to your application extremely easy. Following the same
example, just by including the web starter, you will get an embedded Tomcat server.
There’s no need to configure anything. This is because the Spring Boot autoconfiguration
classes scan your classpath, properties, components, etc., and load some extra beans
and behavior based on that.
To be able to manage different configuration options for your Spring Boot
application, the framework introduces profiles. You can use profiles, for example, to
set different values for the host to connect to when using a database in a development
environment and a production environment. Additionally, you can use a different profile
for tests, where you may need to expose additional functions or mock parts of your
application. We’ll cover profiles more in detail in Chapter 8.
We’ll use the Spring Boot Web and Data starters to quickly build a web application
with persistent storage. The Test starter will help us write tests, given that it includes
some useful test libraries such as JUnit and AssertJ. Then, we’ll add messaging
capabilities to our applications by adding the AMQP starter, which includes a message
broker integration (RabbitMQ) that we’ll use to implement an event-driven architecture.
In Chapter 8, we’ll include a different type of starters, grouped within the Spring Cloud
family. We’ll make use of some of these tools to implement common patterns for
distributed systems: routing (Spring Cloud Gateway), service discovery (Consul), and
load balancing (Spring Cloud Load Balancer), among others. Don’t worry about all these
new terms for now; they’ll be explained in detail while we make progress on the practical
example.
The next chapter covers in detail how these starters and Spring Boot
autoconfiguration work, based on a practical example.

11
Chapter 2 Basic Concepts

L ombok and Java


The code examples in this book use Project Lombok, a library that generates Java code
based on annotations. The main reason to include Lombok in the book is educational:
it keeps the code samples concise, reducing the boilerplate so the reader can focus on
what it matters.
Let’s use one of the first simple classes as an example. We want to create an
immutable multiplication challenge class with two factors. See Listing 2-1.

Listing 2-1. The Challenge Class in Plain Java


public final class Challenge {

    // Both factors


    private final int factorA;
    private final int factorB;

    public Challenge(int factorA, int factorB) {


        this.factorA = factorA;
        this.factorB = factorB;
    }

    public int getFactorA() {


        return this.factorA;
    }

    public int getFactorB() {


        return this.factorB;
    }

    public boolean equals(final Object o) {


        if (o == this) return true;
        if (!(o instanceof Challenge)) return false;
        final Challenge other = (Challenge) o;
        if (this.getFactorA() != other.getFactorA()) return false;
        if (this.getFactorB() != other.getFactorB()) return false;
        return true;
    }

12
Random documents with unrelated
content Scribd suggests to you:
BOOK VIII
BOOK VIII
Charles marries his sister to the Prince of Hesse—He is besieged in
Stralsund and escapes to Sweden—The enterprise of Baron
Gortz his premier—Plans of reconciliation with the Czar—An
attack on England—Charles besieges Frederickshal in Norway
—He is killed—His character—Gortz is beheaded.

DURING these preparations the King gave his only surviving


sister in marriage to Frederic, Prince of Hesse-Cassel. The Queen
Dowager, his grandmother, aged fourscore years, did the honours of
the fête on the 4th of April, 1715, and died shortly afterwards. The
King could not attend the ceremony, as he was so busy finishing the
fortifications of Stralsund, which was in danger from the Kings of
Denmark and Prussia. But he made his brother-in-law generalissimo
of all the forces of Sweden. This Prince had served the States-
General in the French war, and was considered a good soldier, a
qualification for his sister’s hand in the eyes of Charles XII.
Misfortunes now followed as fast as victories had once done. In
June 1715 the English King’s German forces and those of Denmark
invested the strong town of Wismar; the Danes, Saxons and
Prussians, 36,000 of them, marched in a body to Stralsund to form a
siege. Not far from Stralsund, five Swedish ships were sunk by the
Danes and Prussians. The Czar held the Baltic with two large men-
of-war, and 150 transports, which had 30,000 men on board. He
threatened a descent on Sweden, appearing alternately on the coast
of Elsingburg and Stockholm. All Sweden was in arms, expecting an
invasion; his land forces were chasing the Swedes from the places
they held in Finland towards the Gulf of Bothnia, but he attempted
nothing further. At the mouth of the Oder, a river that divides
Pomerania, and, passing Stetin, falls into the Baltic, there is a little
island called Usedom. Its position makes it a place of considerable
importance, for it commands the Oder both on the right and the left,
and whoever holds it is master of the navigation of that river. The
King of Prussia had dislodged the Swedes, and was holding the
place as well as Stetin, saying that he did so purely for the sake of
peace. But the Swedes had retaken Usedom in May 1715, and held
two forts there, one called Suine, on a branch of the Oder of that
name, the other called Penamonder, of greater importance, on
another branch of the river. The forts were manned with only 250
Pomeranians, commanded by an old Swedish officer called Kuze-
Slerp, a man who deserves to be remembered. On the 4th of April
the King of Prussia sent 1,500 foot and 800 dragoons into the island.
They arrived and landed on the side of Suine without opposition. The
Swedish commander had left them this fort, as being the least
important, and, not being able to divide his small force, he withdrew
to the castle of Penamonder, resolving to await the worst.
So they were forced to make a formal siege. They shipped
artillery at Stetin, and sent in a reinforcement of 1,000 Prussian foot
and 400 horse. On the 18th, they opened the trenches in two places,
and a brisk battery was played by cannon and mortars. During the
siege a Swedish soldier, sent privately with a letter to Charles, found
means to land on the island and slip into the place. He gave the
letter to the commander. It was as follows: “Do not fire till the enemy
come to the edge of the ditch; defend yourselves to the last drop of
your blood.—Charles.”
Slerp read the note, resolved to obey, and die as he was bid in
his master’s service. On the 22nd, at daybreak, the assault was
made. The besieged did as they were told, and killed many, but the
ditch was full, the breach large, and the besiegers too numerous.
They entered at two different places at once.
The commander now thought that he had no further duty but to
obey orders and sell his life dear, so he abandoned the breaches,
entrenched his few troops, who all had honour and courage enough
to go with him, and placed them so that they should not be
surrounded.
The enemy hastened up, surprised that he did not ask for
quarter; but he fought a whole hour, and when he had lost half his
soldiers, was killed at last with his lieutenant and major. There were
then left 100 men and one officer; these asked that their lives might
be spared, and were taken prisoners. In the commander’s pocket
they found his master’s letter, which was taken to the King of
Prussia.
Just as Charles had lost Usedom, and the neighbouring islands
which were quickly taken, while Wismar was on the point of
surrender, with no fleet to lend aid, and Sweden in great danger, he
himself was at Stralsund, besieged by 36,000 men. Stralsund,
famous throughout Europe for the siege the King of Sweden
sustained there, is one of the strongest places in Pomerania. It is
built between the Baltic and the Lake of Franken, near the Straits of
Gella. There is no land passage to it but across a narrow crossway
defended by a citadel, and by retrenchments that were once thought
inaccessible. There was in it a garrison of 9,000 men, and, more
than all, the King of Sweden himself. The Kings of Denmark and
Prussia besieged it with an army of 36,000 men, consisting of
Saxons, Prussians and Danes. The honour of besieging Charles was
too great an incitement to them to make any task difficult, so the
trenches were opened on the night between the 19th and 20th of
October, 1715.
The King of Sweden said at first that he wondered how any place
well manned and fortified could be taken. True, he had taken many
towns himself in the course of his victories, but none by regular
attack. It was the fame of his exploits that gained them; besides, he
never judged others by his own standard, and always underrated his
enemies. The besiegers carried on their work with great alacrity, and
they were assisted by a curious chance.
It is well known that the Baltic has no flux and reflux. The
entrenchments of the town were thought impregnable, as there was
an impassable marsh on the west and the sea on the east.
No one had remarked before that in a strong westerly wind the
waves of the Baltic roll back so as to leave only three feet of water
under the entrenchment. They had always thought it deep. A soldier,
happening to fall from the top of the entrenchment, was surprised to
find a bottom; but having made that discovery, he concluded that it
might make his fortune. So he deserted, and going to the quarters of
Count Wakerbath, General of the Saxon forces, he told him that the
sea was fordable, and that it would be easy to carry the Swedes’
entrenchments. The King of Prussia was not slow to take the hint.
The next day the west wind was still blowing; Lieutenant-Colonel
Kepel entered the water with 1,800 men, and 2,000 advanced at the
same time on the causeway; all the Prussian artillery fired, and the
Prussians and Danes gave an alarm on the other side. The Swedes
were sure they could deal with those who were advancing with such
rashness by the causeway; but Kepel, coming in behind them from
the sea, enclosed them so that they could make no headway, and
the position was carried after terrible slaughter on both sides. Some
of the Swedes retired into the town, but they were pursued by the
besiegers, and some entered pell-mell with those that were fleeing.
Two officers and four Saxon soldiers were already on the
drawbridge, but they had just time to shut it, and took the men, and
so for that time the town was saved. They found four-and-twenty
pieces of cannon on the entrenchments, which they turned against
the town. After this success the siege was carried on eagerly, the
town being cannonaded and bombarded without remission.
Opposite Stralsund on the Baltic is the island of Ruegen, which is
a rampart of the place, whither the garrison and people could retire if
they only had boats. This island was of the first importance to
Charles, for he knew that if the enemy were masters of it he would
soon be invested both by sea and land, and probably buried in the
ruins of Stralsund, or else taken prisoner by those whom he had
formerly despised so much and used so harshly.
However, the wretched state of his affairs had prevented him
from sending a sufficient garrison to Ruegen, and there were not
more than 2,000 regular troops altogether on the island. For three
months the enemy had been making all the preparations for an
attack on it, but having built boats for the purpose, the Prince of
Anhalt, favoured by good weather, made a landing at last with
12,000 men on the 15th of November.
The King, who was everywhere, was in this island; he joined
2,000 men who were entrenched near a little haven, about three
leagues from where the enemy had landed. He marched with them
at midnight, with great silence. The Prince of Anhalt had used what
seemed unnecessary caution to entrench his cannon. His officers
expected no attack by night, and had no idea but that Charles was
safe at Stralsund. But the Prince, who knew Charles much better,
ordered a deep ditch, with chevaux de frise on the edge, and took as
much care as if he had to do with a superior force.
At two in the morning Charles came to the enemy’s camp,
without the slightest noise. His soldiers said to one another, “Come,
let us pull up the chevaux de frise.” These words were overheard by
the sentinels; the alarm was quickly given, and the enemy stood to
arms. The King, raising the chevaux de frise, saw a great ditch. “Ah,”
he said, “impossible; this is more than I expected.” Not at all
discouraged, and knowing nothing of their numbers, nor they of his,
for the night favoured him in that, he decided at once, leaped into the
ditch, followed by some of the boldest. The chevaux de frise was
removed, the earth levelled with any trunks and branches they could
find, and the bodies of the dead for fascines. The King, generals,
and boldest of the officers and soldiers got on one another’s
shoulders as in assaults.
The fight began in the enemy’s camp; the vigour of the Swedes
threw the Danes and Prussians into disorder, but their numbers
being too disparate, the Swedes were repulsed in about a quarter of
an hour, and repaired to the ditch.
The unfortunate King rallied his troops in the field, and the fight
was renewed with equal warmth on both sides. He saw his favourite
Grothusen fall, and General Dardoff, and as he fought passed over
the body of the latter while he was still breathing. During, his
companion from Turkey to Stralsund, was killed before his face. The
King himself was shot near the left breast; Count Poniatowski, who
had been so lucky as to save his life before at Pultawa, had the good
fortune to do the same again, and gave him a new mount. The
Swedes retired to a part of the island named Alteferre, where they
still held a fort; from thence the King returned to Stralsund, obliged to
leave those brave troops who had served him so well in that
expedition; they were all prisoners of war two days later.
Among the prisoners was that unfortunate French regiment, the
débris of the battle of Hochstet, which had first served Augustus, and
afterwards Charles. Most of the soldiers were drafted into a new
regiment belonging to the son of the Prince of Anhalt, and he was
their fourth master. In Ruegen the commander of this vagrant
regiment was then the famous Count Villelongue, who had so nobly
risked his life at Adrianople to save Charles. He was taken with all
his men, and was ill rewarded for all his services, fatigues and
sufferings.
The King, having only weakened himself by all these prodigies of
valour, pent up in Stralsund and expecting to be taken, was yet the
same as he had been at Bender. Nothing could surprise him. All day
he was making ditches and entrenchments behind the walls, and at
night he sallied out against the enemy. The town was badly
damaged, bombs fell thick and fast, and half the town was in ashes.
The townsfolk, far from complaining, were full of admiration for their
master, whose temperance, courage and fatigues were astonishing;
they acted as soldiers under him, following to the attack, and were
now as good as another garrison.
One day, as the King was dictating to a secretary some
dispatches for Sweden, a bomb fell into the house, came through the
roof, and burst very near his room. Part of the floor fell in, but the
ante-room where he was at work, being attached to a thick wall, was
undisturbed, and by a lucky chance none of the splinters came in at
the door, though it was open. In this noise and confusion the
secretary dropped his pen, thinking that the house was coming
down. “What is the matter?” said the King calmly; “why are you not
writing?” The man could only stammer out, “The bomb, Sire!” “Well,”
said the King, “what has that to do with our writing? Go on.”
An ambassador of France, a M. de Croissy, was then shut up
with the King in Stralsund. To send a man on an embassy to Charles
was like sending him to the trenches. The King would talk with
Croissy for hours together, in the most exposed places, where
people were falling on all sides, killed by the bombs and cannon; the
King was unconscious of the danger, and the ambassador did not
care to say anything to make him chose a safer place for business.
Before the siege this minister tried his best to make a treaty between
the Kings of Sweden and Prussia; but the one expected too much,
and the other would not make any concessions. So that the only
satisfaction that Croissy got out of his embassy was the familiarity he
enjoyed with this remarkable man. He often slept on the same cloak
with him, and, as they shared so many dangers and fatigues, he was
outspoken with him. Charles encouraged this in the case of those he
liked, and would sometimes say to Croissy, “Veni, maledicamus de
rege.” “Come, let us talk scandal of Charles.”
Croissy stayed in the town till the 13th of November. Then, with
the permission of the enemy to pass with his baggage, he took leave
of Charles, whom he left among the ruins of Stralsund with only a
third of his garrison left, and fully resolved to stand an assault.
In fact, the assault on the horn-work was made in four days. The
enemy took it twice, and were twice beaten off.
At last numbers prevailed, and they became masters of it.
Charles stayed two days longer in the town, expecting every moment
a general assault; on the 16th he stayed till midnight in a little ravelin
quite destroyed by bombs and cannon; the day after the principal
officers begged him to stay no longer in this untenable situation, but
retreat was now as dangerous as to stay there. The Baltic was full of
Russian and Danish ships; in the port at Stralsund there was only
one boat with sails and oars. So many dangers made retreat
glorious, and determined Charles to go; he embarked on the evening
of December 20th, with ten persons aboard. They were obliged to
break the ice, and it was several hours before they could get away.
The enemy’s admiral had strict orders not to let Charles escape from
Stralsund. Happily they were to leeward of him, and could not
approach. He ran the most risk in passing a place called the
Barbette, in Ruegen, where the Danes had fixed a battery of twelve
cannon. They fired, and he made all the sail he could to get clear of
their range. Two men were killed close by him, and at another shot
the mast was shattered. In the midst of these dangers the King met
two of his ships that were cruising in the Baltic, and the next day
Stralsund was surrendered, and the garrison made prisoners of war.
The King landed at Isted in Scania, and came to Carlscrona, in a
very different state from that in which he had left it, ten years before,
when he started in a ship of twelve guns, to dictate to the North.
As he was so near his capital, it was concluded he would go
there after so long an absence. But he could not bear the thought of
it till he had gained some great victories. Nor did he want to see his
people who loved him, and to whose burdens he had perforce to add
to defend himself against his enemies. He only wanted to see his
sister, and he sent for her to meet him near Lake Wetter, in
Ostrogothia. He rode post-haste with one attendant, spent a day with
her, and returned.
At Carlscrona, where he passed the winter, he levied new forces
everywhere. He thought his subjects were only born to follow him to
war, and he had accustomed them to think so too. He enlisted many
of but fifteen years old. In many villages there were only old men,
women and children left; in some places the women ploughed
unaided. It was still more difficult to get a fleet. But to bring that
about commissions were given to privateers, who enjoyed great
privileges to the ruin of the country, but who provided him with some
ships. This was the last effort of Sweden to meet the great expense;
all the houses were searched, and half their provisions carried into
the King’s warehouses. All the iron in the country was bought up for
his use and paid for in paper, which he sold for ready money.
Whoever wore silk, or wigs, or gilded swords was taxed, and there
was a heavy hearth-rate.
A people thus loaded with taxation would have revolted under
any other King, but here the most miserable peasant knew that his
master was faring harder than he himself. So they quietly bore what
their King was always the first to bear. In the public danger, private
misfortunes were not thought of. They expected hourly an attack
from the Russians, Danes, Prussians, Saxons, and the English.
Their fear was so strong, and so well justified, that those who
possessed valuables buried them.
It was a surprise to all Europe, who had still an eye on Charles,
when, instead of defending his country about to be attacked by so
many princes, he invaded Norway at the head of 20,000 men. Since
the time of Hannibal there had been no instance of a general who,
unable to hold his own against his enemies at home, had gone to
attack them in their own dominions. His brother-in-law, the Prince of
Hesse, accompanied him. There is no way from Sweden to Norway
except by dangerous by-ways, where at every turn one meets with
pools of water, formed by the sea between the rocks; bridges have to
be made every day. A very few Danes might have stopped the
Swedish army, but they were not ready for such a rapid invasion.
Europe was still more surprised to find the Czar so quiet, without
descending on Sweden as he had intended.
The reason was that he had a plan, which was one of the
greatest, and one of the most difficult to carry out, that has ever been
conceived.
Baron Gortz, a Franconian by birth, and Baron of the empire,
having done the King of Sweden important services during his
sojourn at Bender, was now his favourite and Prime Minister. He was
the boldest and the most diplomatic of men: full of resource in
adversity, ambitious in his plans, and active in his policy, no project
was too ambitious for him, no means too dear for his end; he was
prodigal with presents, oaths, truth and falsehood. From Sweden he
went to England, France, Holland, to himself lay the train which he
meant to use; he was able to inflame all Europe, and that was his
idea. What his master was at the head of an army, he was in the
cabinet, and this gave him more influence over Charles than any
minister had ever had before. This King, who from the age of twenty
had given orders to Court Piper, was now willing to receive them
from Baron Gortz, and was the more submissive because his
misfortunes had made it necessary for him to ask advice, and
because Gortz’s advice suited with his courageous disposition. He
found that of all the princes in league against him Charles felt
especially resentful to George of Hanover, King of England: because
he was the only one whom Charles had never injured, and had
entered into the affair only as a mediator, with intent to hold Bremen
and Verden, which he bought for a trifle from the King of Denmark.
It was early that he discovered the Czar’s secret discontent with
the allies, who all wanted to prevent his getting any footing in
Germany.
Since the year 1714 the Czar had been in a position to make a
descent on Sweden, but whether he could not agree with the Kings
of Poland, England, Denmark, and Prussia, allies whose suspicions
were justifiable, or whether he thought his troops not seasoned
enough to attack that people at home, whose very peasants had
beat the pick of the Danish forces, he still took care to put it off.
The want of money was what had hitherto delayed him. For the
Czar was one of the greatest monarchs in the world, but not one of
the richest, his revenue not amounting to more than 18,000,000
French francs. He had discovered gold, silver, iron and copper
mines, but the profit they yielded was uncertain, and the working of
them expensive. He had established a great trade, yet at first it did
not flourish; his new conquests increased his power and his fame,
but brought him very little treasure.
Time was necessary to bind up the wounds of Livonia, a fertile
country which had suffered much from a fifteen years’ war, by fire,
sword and plague—almost desolate of inhabitants, and a burden to
the conqueror. The fleets he now maintained; and every day some
new enterprise was exhausting all his treasures. He had been
reduced to the bad expedient of raising the value of the coinage, a
remedy which never cures the evil, and is particularly injurious to any
country where the imports exceed the exports. It was upon these
grounds that Gortz had laid the basis of a revolution; he was bold
enough to suggest to the King of Sweden that he should make
peace with the Czar, insinuating that the Czar was very angry with
the Kings of Poland and England, and that Peter and Charles
together might make the rest of Europe tremble.
There was no making peace with the Czar, unless he yielded a
good many provinces to the east and west of the Baltic, but he called
his attention to the fact that in yielding such places as the Czar
possessed already, and which he could not possibly regain, he might
have the honour of replacing Stanislas on the throne of Poland, and
setting James II’s son upon that of England, besides restoring the
Duke of Holstein.
Charles was pleased with all this, and without giving the matter
much consideration he gave the minister full powers to act: Gortz left
Sweden with carte blanche for any prince he wished to treat with. His
first business was to try how the Court of Moscow stood, which he
did through the Czar’s chief physician, a man devoted to the
Pretender’s interests, as most of the Scots are, where they are not in
the pay of the English Court. This physician represented to Prince
Menzikoff, with all the eagerness of a man much interested, the
greatness and importance of such a plan. Prince Menzikoff was
pleased with it, and the Czar approved it. Instead of an invasion of
Sweden he sent his troops to winter in Mecklenburg, and came there
himself on the pretext of settling some disputes between his nephew
the Duke and his nobles: his real object was to gain a principality in
Germany, for which he hoped to bargain with the Duke.
The allies were angry at this step, not caring to have so terrible
and formidable a neighbour, who, should he once gain German
provinces, might become Emperor and oppress the sovereigns. The
greater was their resentment, the more that Gortz’s plan flourished.
But he negotiated with all the confederates in order to conceal his
private intrigues. The Czar fed them all with vain hopes. Charles was
all this while with his brother-in-law in Norway at the head of 20,000
men, the country was defended by 110,000 Danes in separate
bands, which were routed by the King and Prince of Hesse. Charles
advanced to Christiania, the capital, and fortune smiled on him
again, but from want of provisions he was forced to retire to Sweden,
there to await the result of his minister’s plan.
This affair was to be carried through with profound secrecy, and
elaborate preparations were necessary: these two are incompatible.
Gortz planned to go as far as Asia in his quest, and though the
means seemed undesirable, it would at least bring men, money and
ships to Sweden, which could be used for an attack on Scotland.
For some time the pirates of all nations, and especially the
English, had banded themselves together to infest the seas of
Europe and America; they had received no quarter and had retired to
Madagascar, a large island on the east coast of Africa; they were
quite desperate, and famed for actions which would have made them
heroes had they been legal. They wanted a prince to take them
under his protection, but international law shut them out from every
harbour.
When they heard that Charles XII was returned to Sweden they
hoped that, as he was devoted to war and forced to take share in it,
and needed a fleet and soldiers, he would be glad to make terms
with them. So they sent a deputy, who travelled to Europe in a Dutch
ship, to propose to Baron Gortz that they might be received at
Gothenburg, where they promised to prepare three-score ships
loaded with treasure.
The Baron persuaded the King to agree, and two Swedes were
sent to negotiate with them. Then more honourable and substantial
help came from Cardinal Alberoni, who directed the government of
Spain long enough for his own reputation but not for the good and
glory of that kingdom.
He took up the project of setting James II’s son on the English
throne with great enthusiasm. But as he had only just taken up the
ministry, and Spain was to be settled before he could attempt to
overthrow thrones, it appeared that there was no great likelihood of
his undertaking the task at present. Yet in two years he had done so
much for Spain, and had so raised her prestige in Europe that he
had got the Turks (it is reported) to attack the Emperor. Then he took
steps to remove the Duke of Orleans from the Regency and King
George from the English throne. Such danger lies in the power of
one single man who is absolute, and has the sense and capacity to
use his power.
Gortz, having made this beginning in the Courts of Russia and
Spain, went secretly to France, and thence to Holland, where he
interviewed representatives of the Pretender’s party. He got special
information concerning the strength, number, and position of the
disaffected in England, what money they could raise, and what men
they could put in the field. They only wanted 10,000 men, with which
they would feel assured of success. Count Gyllemburg, the Swedish
ambassador in England, acting under Gortz’s instructions, had
several meetings with the disaffected; he encouraged them and
promised them all they wanted. The Pretender’s party even
advanced considerable sums, which Gortz received in Holland, and
with which he bought ships and ammunition.
Then he secretly sent some officers to France, especially a
certain Folard, who, having served in thirty French campaigns
without mending his fortune, had volunteered with Charles, not with
any ulterior motive, but just to serve under a prince with such a
reputation. He especially hoped to get the Prince to adopt the new
discoveries he had made in the art of war, which he had studied
theoretically and had published views of in a commentary of
Polybius. Charles was pleased with his ideas, and, as he was never
governed by convention, he intended to make use of Folard in his
attack on Scotland.
The main point for Baron de Gortz was to settle a peace between
Charles and the Czar, in spite of the many difficulties in the way.
Baron Osterman, a man of weight in Russia, was not so ready to
agree with Gortz. He was as cautious as the other was enthusiastic.
One was for letting things gradually ripen, the other wanted to reap
and sow together. Osterman was afraid his master, pleased with the
plan, would grant too advantageous terms with Sweden, and so
delayed the conclusion of the matter. Luckily for Gortz the Czar
himself came to Holland at the beginning of 1717 on the way to
France, for he had yet to see this nation, criticized, envied, and
imitated by all Europe. He wanted to satisfy his insatiable curiosity,
but also he hoped to arrange some political matters.
Gortz had two talks with the Emperor at the Hague, and did more
by their means than he could have done in six months with
plenipotentiaries. Everything went well, his great plans seemed quite
unsuspected, and he hoped they would only be known to Europe in
their execution. The first who discovered these intrigues was the
Duke of Orleans, Regent of France, who had spies everywhere. The
Duke, having personal obligations to the King of England, made the
discovery of the whole plot against him. At the same time the Dutch,
having suspicions of Gortz’s behaviour, communicated them to the
English ministry. Gortz and Gyllemburg were getting on with their
schemes rapidly, when one was arrested at the Hague and the other
in London.
As Gyllemburg had broken international law by the conspiracy
they did not scruple in England to attack his person. But it was
thought exceedingly strange that the States-General imprisoned
Baron Gortz out of mere friendship for the King of England. They
even went so far as to appoint Count Velderen to question him. This
was going very far, and as it turned out, only added to their
confusion. Gortz asked Velderen if he knew him. “Yes,” said the
Dutchman. “Well, then,” he answered, “you must then be aware that
I shall only answer what I like.”
All the foreign ministers protested against the wrong done to the
persons of Gortz and Gyllemburg. Nothing could excuse the Dutch
from breaking so sacred a law in seizing the King of Sweden’s
premier, who had never done anything against them, and so violating
the spirit of freedom which has attracted so many strangers and has
been the cause of her greatness. The King of England acted within
his rights in seizing an enemy, so that the letters found among
Gyllemburg’s papers from him to Gortz were printed to justify the
King’s proceedings.
The King of Sweden was in Scania when the printed letters came
with the news of his ministers having been seized. He only smiled
and asked if his letters were printed too, and ordered the English
ambassador and all his family to be seized. But he could not take the
same vengeance on the Dutch, because they had no minister then at
the Court of Sweden. He kept a disdainful silence towards England
and Holland.
The Czar’s behaviour was just the opposite: as he was not
named but only hinted at by distant references in the letters of Gortz
and Gyllemburg, he wrote a long letter full of congratulations to the
King of England on the discovery, with assurances of his good-will.
King George received his protestations with incredulity, but
pretended to believe them. A plot laid by private men is at an end
when once discovered, but where kings are concerned a discovery
only makes it go further. The Czar came to Paris in 1717, and did not
spend all his time in viewing the wonders of art and nature there: the
academies, public libraries, cabinets of the antiquaries and royal
palaces. He made a proposal to the Regent which, had it been
accepted, would have put the finishing touch to the greatness of
Russia. It was this: to himself ally with the King of Sweden, who
would yield many countries to him, to take from the Danes their
power in the Baltic, to weaken England by a civil war, and to attract
to Russia all the trade of the North. He had thoughts, too, of setting
up Stanislas against King Augustus, so that when the fire was
kindled in all directions he could fan the flame or damp it as he saw
fit. With these views he proposed to the King’s Regent to mediate
between Sweden and Russia, and to make an offensive and
defensive alliance with them and Spain. The treaty, though so
natural and so useful to the nations concerned, putting into their
hands the balancing of power in Europe, was yet rejected by
Orleans, for he did just the opposite and made a league with the
Emperor and the King of England.
Political motives were then so powerful with all princes that the
Czar was going to declare war against his old friend Augustus, and
to help Charles his mortal enemy; while France, for the sake of the
English and Germans, was going to declare war against a grandson
of Louis XIV, after having so long supported him at great expenditure
of blood and treasure against those very enemies. All that the Czar
could obtain was that the Regent should interpose for the freeing of
Baron Gortz and Gyllemburg. He returned to Russia about the end of
June, having shown a rare example of an emperor travelling to
improve his mind. But what most of the French people saw of him
was a rough, unpolished exterior, the result of his education, while
they were blind to the legislator and the genius who had founded a
new nation. What he had sought for in Orleans he soon found in
Alberoni, who governed all Spain. Alberoni wanted to restore the
Pretender: first as the minister of Spain, so ill-used by the English,
and secondly because he had a personal quarrel with the Duke of
Orleans for his close alliance with England against Spain; besides,
he was a priest of that Church for which the Pretender’s father had
lost his crown.
The Duke of Ormond, as unpopular in England as the Duke of
Marlborough was admired, had left the country at the time of
George’s accession, and was now in Spain. He went with full powers
from the King of Spain to meet the Czar, in Courland, accompanied
by a certain D’Irnegan, an Englishman of ability and daring. The
business was to ask the Princess Anna, the Czar’s daughter, for
marriage with James’s son, in the hopes that such an alliance would
bring the Czar over to the King’s side. Baron Gortz, among his other
schemes, had intended this lady for the Duke of Holstein, who did
marry her later. As soon as he heard of the Duke of Ormond’s plan
he grew jealous and did what he could to defeat it.
He left prison in August with the Count Gyllemburg, without any
apology from the Swedish to the English King. At the same time the
English ambassador and his family were released at Stockholm,
where their treatment had been a great deal worse than
Gyllemburg’s in London.
Gortz at liberty was an implacable enemy, for besides his other
aims he now sought vengeance. He went post-haste to the Czar,
who was now better pleased with him than ever, for he undertook to
remove in less than three months all obstacles to a peace with
Sweden. He took up a map which the Czar had drawn himself, and,
drawing a line from Wibourg, by Lake Ladoga, up to the frozen
ocean, promised to bring his master to part with all that lay east of
that line, besides Carelia, Ingria, and Livonia. Then he mentioned the
marriage of the Czar’s daughter to the Duke of Holstein, holding out
hopes that the Duke would readily give his country instead, and if
once he became a member of the Empire the Imperial crown would,
of course, come to him or some of his descendants. The Czar
named the isle of Aland for the conferences between Osterman and
Gortz; he asked the English Duke of Ormond to withdraw lest the
English Court should take alarm. But D’Irnegan, his confidant,
remained in the town with many precautions, for he only went out at
night and never saw the Czar’s ministers but in the disguise of either
a peasant or a Tartar.
As soon as the Duke of Ormond went, the Czar impressed upon
the King his courtesy in having sent away the chief partisan of the
Pretender, and Baron Gortz returned to Sweden with great hopes of
success.
He found his master at the head of 30,000 troops with all the
coast guarded by militia. The King needed nothing but money, but he
had no credit at home or abroad. France, under the Duke of Orleans,
would give him none. He was promised money from Spain, but that
country was not yet in a position to support him.
Baron Gortz then tried a project he had tried before. He gave
copper the same value as silver, so that a copper coin whose
intrinsic value was a halfpenny might, with the royal mark, pass for
thirty or forty pence, just as the governors of besieged towns have
sometimes paid their soldiers with leather money till they could get
better. Such expedients may be useful in a free country, and have
often been the salvation of a republic, but they are sure to ruin a
monarchy, for the people quickly lose confidence, the minister is
unable to keep faith, the money paper increases, individuals bury
their specie, and the whole plan fails, often with disastrous results.
This was the case in Sweden. Baron Gortz had paid out his new coin
with discretion, but was soon carried beyond what he had intended
by forces he could not check. Everything became excessively dear,
so that he was obliged to multiply his copper coin. The more there
was of it the less was its value. Sweden was inundated with this
false money, and one and all complained of Gortz. So great was the
veneration of the people for Charles that they could not hate him, so
the weight of their displeasure fell on the minister who, as a foreigner
and financier, was sure to suffer their opprobrium.
A tax that he arranged on the clergy gave the final touch to the
universal hatred; priests are only too ready to plead that their cause
is God’s, and publicly declared him an atheist, because he asked for
their money. The new coins were embossed with the figure of
heathen gods, and hence they called them the gods of Gortz.
The ministry joined in the universal hatred of him, all the more
ardently because they were powerless. None in the country liked him
except the King, whom his unpopularity confirmed in his affection.
He placed absolute confidence in him, giving him also his entire
confidence at home. He trusted to him, too, all negotiations with the
Czar, especially as to the conference at Aland, which of all things he
wished to urge on with the greatest haste.
As soon as Gortz had completed at Stockholm the arrangements
for the treasury which demanded his presence, he went away to
complete with Osterman the great work he had in hand. These were
the preliminaries of that alliance which was to have changed the face
of affairs in Europe, as they were found among Gortz’s papers.
The Czar was to keep Livonia, part of Ingria, and Carelia, leaving
the rest to Sweden. He was to join Charles in restoring Stanislas,
and to send to Poland 80,000 men to dethrone the very king on
whose side he had been fighting for so many years before; he was to
supply ships to carry 30,000 to Germany and 10,000 to England; the
forces of both were to attack the King of England’s German
dominions, especially Bremen and Verden; the same troops were to
restore the Duke of Holstein and force the King of Prussia to an
agreement by parting with a good deal of his new acquisitions.
Charles acted henceforth as if his own victorious troops had done
all this, and demanded of the Emperor the execution of the peace of
Altranstadt. But the Court of Vienna scarcely deigned an answer to
one whom they feared so little. The King of Poland was not
altogether so safe, but saw the storm coming. Fleming was the most
suspicious man alive and the least reliable. He suspected the
designs of the Czar and the King of Sweden in favour of Stanislas,
so he endeavoured to have him taken off to Deux Ponts, as James
Sobieski had been in Silesia. But Stanislas was on his guard, and
the design miscarried.
In the meantime Charles was making a second attempt upon
Norway in October 1718. He had so arranged matters that he hoped
to be master of the country in six months.

You might also like