Learn Microservices with Spring Boot 3 3rd / converted Edition Moises Macero Garcia full chapter instant download

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 28

Learn Microservices with Spring Boot 3

3rd / converted Edition Moises Macero


Garcia
Visit to download the full and correct content document:
https://ebookmass.com/product/learn-microservices-with-spring-boot-3-3rd-converted
-edition-moises-macero-garcia/
More products digital (pdf, epub, mobi) instant
download maybe you interests ...

Learn Microservices with Spring Boot 3: A Practical


Approach Using Event-Driven Architecture, Cloud-Native
Patterns, and Containerization 3rd Edition Moisés
Macero García
https://ebookmass.com/product/learn-microservices-with-spring-
boot-3-a-practical-approach-using-event-driven-architecture-
cloud-native-patterns-and-containerization-3rd-edition-moises-
macero-garcia/

Hacking with Spring Boot 2.3: Reactive Edition

https://ebookmass.com/product/hacking-with-spring-
boot-2-3-reactive-edition/

Beginning Spring Boot 3: Build Dynamic Cloud-Native


Java Applications and Microservices - Second Edition K.
Siva Prasad Reddy

https://ebookmass.com/product/beginning-spring-boot-3-build-
dynamic-cloud-native-java-applications-and-microservices-second-
edition-k-siva-prasad-reddy/

Pro Spring Security: Securing Spring Framework 6 and


Boot 3–based Java Applications, Third Edition
Massimo Nardone

https://ebookmass.com/product/pro-spring-security-securing-
spring-framework-6-and-boot-3-based-java-applications-third-
edition-massimo-nardone/
Beginning Spring Data: Data Access and Persistence for
Spring Framework 6 and Boot 3 Andres Sacco

https://ebookmass.com/product/beginning-spring-data-data-access-
and-persistence-for-spring-framework-6-and-boot-3-andres-sacco/

Beginning Spring Boot 3 2nd Edition Siva Prasad Reddy


Katamreddy [K. Siva Prasad Reddy]

https://ebookmass.com/product/beginning-spring-boot-3-2nd-
edition-siva-prasad-reddy-katamreddy-k-siva-prasad-reddy/

Pro RESTful APIs with Micronaut: Build Java-Based


Microservices with REST, JSON, and XML 2 / converted
Edition Sanjay Patni

https://ebookmass.com/product/pro-restful-apis-with-micronaut-
build-java-based-microservices-with-rest-json-and-
xml-2-converted-edition-sanjay-patni/

Spring Rains (Whisper Ridge, Wyoming Book 3) Rj Scott

https://ebookmass.com/product/spring-rains-whisper-ridge-wyoming-
book-3-rj-scott/

Pro RESTful APIs with Micronaut: Build Java-Based


Microservices with REST, JSON, and XML, 2nd Edition
Sanjay Patni

https://ebookmass.com/product/pro-restful-apis-with-micronaut-
build-java-based-microservices-with-rest-json-and-xml-2nd-
edition-sanjay-patni/
Learn Microservices

with Spring Boot 3

A Practical Approach Using

Event- Driven Architecture,

Cloud-Native Patterns,

and Containerization

Third Edition

Moisés Macero García

Tarun Telang

Learn Microservices with Spring Boot 3: A Practical Approach Using


Event-Driven

Architecture, Cloud-Native Patterns, and Containerization, Third Edition

Moisés Macero García

Tarun Telang

New York, NY, USA

Hyderabad, Telangana, India

ISBN-13 (pbk): 978-1-4842-9756-8

ISBN-13 (electronic): 978-1-4842-9757-5

https://doi.org/10.1007/978-1-4842-9757-5

Copyright © 2023 by Moisés Macero García and Tarun Telang


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: Melissa Duffy

Development Editor: Laura Berendson

Coordinating Editor: Gryffin Winkler

Copy Editor: Kezia Endsley

Cover designed by eStudioCalamar

Cover image by Image by James DeMers on Pixabay (www.pixabay.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 orders-


ny@springer-sbm.com, 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


booktranslations@springernature.com; for reprint,

paperback, or audio rights, please e-mail


bookpermissions@springernature.com.

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 http://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 (https://github.com/Apress). For more detailed


information, please visit https://www.

apress.com/gp/services/source-code.

Paper in this product is recyclable

This book is dedicated to my grandparents, parents, wife Nikita, and

son Vihan. They have always been a source of inspiration and

encouragement to me. It’s also for all of the software and technology

creators who work hard to make our planet a better place to live.

—Tarun Telang

Table of Contents

About the Authors


������������������������������
������������������������������
������������������������������
�������� xiii About the Technical Reviewer
������������������������������
������������������������������
���������������������xv Acknowledgments
������������������������������
������������������������������
������������������������������
�������xvii About this Book
������������������������������
������������������������������
������������������������������
������������������������������
������������xix Chapter 1: Setting the Scene
������������������������������
������������������������������
������������������������ 1

Who Are You?


������������������������������
������������������������������
������������������������������
������������������������������
�������� 3

How Is This Book Different from Other Books and Guides?


������������������������������
���������������������������� 5

Learning: An Incremental Process


������������������������������
������������������������������
������������������������������
�5

Is This a Guide or a Book?


������������������������������
������������������������������
������������������������������
������������� 5

From Basics to Advanced Topics


������������������������������
������������������������������
������������������������������
��������� 6
Skeleton with Spring Boot, the Professional Way
������������������������������
������������������������������
�������� 7

Test-Driven Development
������������������������������
������������������������������
������������������������������
�������������� 7

Microservices
������������������������������
������������������������������
������������������������������
������������������������������
�� 7

Event-Driven Systems
������������������������������
������������������������������
������������������������������
������������������� 8

Nonfunctional Requirements
������������������������������
������������������������������
������������������������������
��������� 8

Online Content
������������������������������
������������������������������
������������������������������
������������������������������
������ 9

��������������������������
Summary��������������������������
������������������������������
������������������������������
������������������������������
������������������� 9

Chapter 2: Basic Concepts


������������������������������
������������������������������
�������������������������� 11

Spring���������������������������
������������������������������
������������������������������
������������������������������
��������������������� 11

Spring Boot
������������������������������
������������������������������
������������������������������
������������������������������
��������� 16

Lombok and Java


������������������������������
������������������������������
������������������������������
������������������������������
18

Testing Basics
������������������������������
������������������������������
������������������������������
������������������������������
����� 21
Test-Driven Development
������������������������������
������������������������������
������������������������������
������������ 21

Behavior-Driven Development
������������������������������
������������������������������
������������������������������
����� 22

Table of ConTenTs

JUnit 5
������������������������������
������������������������������
������������������������������
������������������������������
����������� 23

Mockito
������������������������������
������������������������������
������������������������������
������������������������������
���������� 23

AssertJ
������������������������������
������������������������������
������������������������������
������������������������������
���������� 27
Testing in Spring Boot
������������������������������
������������������������������
������������������������������
����������������������� 28

Logging
������������������������������
������������������������������
������������������������������
������������������������������
��������������� 29

Summary and Achievements


������������������������������
������������������������������
������������������������������
������������ 30

Chapter 3: A Basic Spring Boot Application


������������������������������
�����������������������������
33

Setting Up the Development Environment


������������������������������
������������������������������
���������������������� 34

Java Development Kit 17


������������������������������
������������������������������
������������������������������
������������� 34

Integrated Development Environment (IDE)


������������������������������

������������������������������
������������������������������
��������������� 34

HTTPie
������������������������������
������������������������������
������������������������������
������������������������������
����������� 35

POST Request
������������������������������
������������������������������
������������������������������
������������������������������
36

cURL
������������������������������
������������������������������
������������������������������
������������������������������
�������������� 36

The Skeleton Web App


������������������������������
������������������������������
������������������������������
���������������������� 36

Spring Boot Autoconfiguration


������������������������������
������������������������������
������������������������������
���������� 41
Three-Tier, Three-Layer Architecture
������������������������������
������������������������������
������������������������������
47

Modeling the Domain


������������������������������
������������������������������
������������������������������
������������������������ 50

Domain Definition and Domain-Driven Design


������������������������������
������������������������������
���������� 50

Domain Classes
������������������������������
������������������������������
������������������������������
��������������������������� 52

Business Logic
������������������������������
������������������������������
������������������������������
������������������������������
���� 55

What You Need


������������������������������
������������������������������
������������������������������
���������������������������� 55
Random Challenges
������������������������������
������������������������������
������������������������������
��������������������� 55

Attempt Verification
������������������������������
������������������������������
������������������������������
��������������������� 59

Presentation Layer
������������������������������
������������������������������
������������������������������
���������������������������� 64

REST
������������������������������
������������������������������
������������������������������
������������������������������
�������������� 64

REST APIs with Spring Boot


������������������������������
������������������������������
������������������������������
��������� 65

Designing the APIs


������������������������������
������������������������������
������������������������������
����������������������� 66
Your First Controller
������������������������������
������������������������������
������������������������������
��������������������� 67

How Automatic Serialization Works


������������������������������
������������������������������
��������������������������� 69

Testing Controllers with Spring Boot


������������������������������
������������������������������
������������������������� 73

Summary and Achievements


������������������������������
������������������������������
������������������������������
������������ 86

vi

Table of ConTenTs

Chapter 4: A Minimal Frontend with React


������������������������������
������������������������������
� 89

A Quick Intro to React and Node


������������������������������
������������������������������
������������������������������
������� 90
Setting Up the Development Environment
������������������������������
������������������������������
���������������������� 91

The React Skeleton


������������������������������
������������������������������
������������������������������
��������������������������� 92

A JavaScript Client
������������������������������
������������������������������
������������������������������
���������������������������� 94

The Challenge Component


������������������������������
������������������������������
������������������������������
���������������� 96

The Main Structure of a Component


������������������������������
������������������������������
�������������������������� 99

Rendering
������������������������������
������������������������������
������������������������������
������������������������������
���� 101

Integration with the App


������������������������������
������������������������������
������������������������������
������������������������������
������������ 104

Running the Frontend the First Time


������������������������������
������������������������������
�����������������������������
105

Debugging
������������������������������
������������������������������
������������������������������
������������������������������
��������� 105

Adding CORS Configuration to the Spring Boot App


������������������������������
������������������������������
������ 107

Playing with the Application


������������������������������
������������������������������
������������������������������
������������ 108

Deploying the React App


������������������������������
������������������������������
������������������������������
����������������� 109

Summary and Achievements


������������������������������
������������������������������
������������������������������
������������������������������
���������� 112

Chapter 5: The Data Layer


������������������������������
������������������������������
������������������������ 115

The Data Model


������������������������������
������������������������������
������������������������������
������������������������������
� 117

Choosing a Database
������������������������������
������������������������������
������������������������������
���������������������� 119

SQL vs� NoSQL


������������������������������
������������������������������
������������������������������
��������������������������� 121

H2, Hibernate, and JPA


������������������������������
������������������������������
������������������������������
�������������� 122

Spring Boot Data JPA


������������������������������
������������������������������

������������������������������
Another random document with
no related content on Scribd:
OR IMPLIED, INCLUDING BUT NOT LIMITED TO
WARRANTIES OF MERCHANTABILITY OR FITNESS FOR
ANY PURPOSE.

1.F.5. Some states do not allow disclaimers of certain implied


warranties or the exclusion or limitation of certain types of
damages. If any disclaimer or limitation set forth in this
agreement violates the law of the state applicable to this
agreement, the agreement shall be interpreted to make the
maximum disclaimer or limitation permitted by the applicable
state law. The invalidity or unenforceability of any provision of
this agreement shall not void the remaining provisions.

1.F.6. INDEMNITY - You agree to indemnify and hold the


Foundation, the trademark owner, any agent or employee of the
Foundation, anyone providing copies of Project Gutenberg™
electronic works in accordance with this agreement, and any
volunteers associated with the production, promotion and
distribution of Project Gutenberg™ electronic works, harmless
from all liability, costs and expenses, including legal fees, that
arise directly or indirectly from any of the following which you do
or cause to occur: (a) distribution of this or any Project
Gutenberg™ work, (b) alteration, modification, or additions or
deletions to any Project Gutenberg™ work, and (c) any Defect
you cause.

Section 2. Information about the Mission of


Project Gutenberg™
Project Gutenberg™ is synonymous with the free distribution of
electronic works in formats readable by the widest variety of
computers including obsolete, old, middle-aged and new
computers. It exists because of the efforts of hundreds of
volunteers and donations from people in all walks of life.

Volunteers and financial support to provide volunteers with the


assistance they need are critical to reaching Project
Gutenberg™’s goals and ensuring that the Project Gutenberg™
collection will remain freely available for generations to come. In
2001, the Project Gutenberg Literary Archive Foundation was
created to provide a secure and permanent future for Project
Gutenberg™ and future generations. To learn more about the
Project Gutenberg Literary Archive Foundation and how your
efforts and donations can help, see Sections 3 and 4 and the
Foundation information page at www.gutenberg.org.

Section 3. Information about the Project


Gutenberg Literary Archive Foundation
The Project Gutenberg Literary Archive Foundation is a non-
profit 501(c)(3) educational corporation organized under the
laws of the state of Mississippi and granted tax exempt status by
the Internal Revenue Service. The Foundation’s EIN or federal
tax identification number is 64-6221541. Contributions to the
Project Gutenberg Literary Archive Foundation are tax
deductible to the full extent permitted by U.S. federal laws and
your state’s laws.

The Foundation’s business office is located at 809 North 1500


West, Salt Lake City, UT 84116, (801) 596-1887. Email contact
links and up to date contact information can be found at the
Foundation’s website and official page at
www.gutenberg.org/contact

Section 4. Information about Donations to


the Project Gutenberg Literary Archive
Foundation
Project Gutenberg™ depends upon and cannot survive without
widespread public support and donations to carry out its mission
of increasing the number of public domain and licensed works
that can be freely distributed in machine-readable form
accessible by the widest array of equipment including outdated
equipment. Many small donations ($1 to $5,000) are particularly
important to maintaining tax exempt status with the IRS.

The Foundation is committed to complying with the laws


regulating charities and charitable donations in all 50 states of
the United States. Compliance requirements are not uniform
and it takes a considerable effort, much paperwork and many
fees to meet and keep up with these requirements. We do not
solicit donations in locations where we have not received written
confirmation of compliance. To SEND DONATIONS or
determine the status of compliance for any particular state visit
www.gutenberg.org/donate.

While we cannot and do not solicit contributions from states


where we have not met the solicitation requirements, we know
of no prohibition against accepting unsolicited donations from
donors in such states who approach us with offers to donate.

International donations are gratefully accepted, but we cannot


make any statements concerning tax treatment of donations
received from outside the United States. U.S. laws alone swamp
our small staff.

Please check the Project Gutenberg web pages for current


donation methods and addresses. Donations are accepted in a
number of other ways including checks, online payments and
credit card donations. To donate, please visit:
www.gutenberg.org/donate.

Section 5. General Information About Project


Gutenberg™ electronic works
Professor Michael S. Hart was the originator of the Project
Gutenberg™ concept of a library of electronic works that could
be freely shared with anyone. For forty years, he produced and
distributed Project Gutenberg™ eBooks with only a loose
network of volunteer support.

Project Gutenberg™ eBooks are often created from several


printed editions, all of which are confirmed as not protected by
copyright in the U.S. unless a copyright notice is included. Thus,
we do not necessarily keep eBooks in compliance with any
particular paper edition.

Most people start at our website which has the main PG search
facility: www.gutenberg.org.

This website includes information about Project Gutenberg™,


including how to make donations to the Project Gutenberg
Literary Archive Foundation, how to help produce our new
eBooks, and how to subscribe to our email newsletter to hear
about new eBooks.

You might also like