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
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
com
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
https://textbookfull.com/product/homer-s-allusive-art-1st-edition-
bruno-currie/
textbookfull.com
https://textbookfull.com/product/koren-talmud-bavli-noe-edition-
volume-29-sanhedrin-part-1-hebrew-english-large-color-edition-adin-
steinsaltz/
textbookfull.com
https://textbookfull.com/product/handbook-of-milk-of-non-bovine-
mammals-second-edition-young-w-park/
textbookfull.com
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
v
Table of Contents
vi
Table of Contents
vii
Table of Contents
viii
Table of Contents
Transactions������������������������������������������������������������������������������������������������������������������������ 211
API Exposure������������������������������������������������������������������������������������������������������������������������ 213
Summary and Achievements���������������������������������������������������������������������������������������������������� 213
ix
Table of Contents
x
Visit https://textbookfull.com
now to explore a rich
collection of eBooks, textbook
and enjoy exciting offers!
Table of Contents
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.
xv
About the Technical Reviewers
xvi
CHAPTER 1
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.
2
Chapter 1 Setting the Scene
Regarding the knowledge required to read this book, the following topics should be
familiar to you:
• Spring (you don’t need strong experience, but you should know at
least how dependency injection works)
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.
4
Chapter 1 Setting the Scene
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:
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
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
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.