Spring Microservices in Action, Second Edition
John Carnell, Illary Huaylupo Sánchez
  • MEAP began November 2019
  • Publication in December 2020 (estimated)
  • ISBN 9781617296956
  • 453 pages (estimated)
  • printed in black & white
free previous edition eBook included
An eBook copy of the previous edition of this book is included at no additional cost. It will be automatically added to your Manning Bookshelf within 24 hours of purchase.

The must-have guide for microservices designers and developers that use Spring.

Gilberto Taccari
By dividing large applications into separate self-contained units, Microservices are a great step toward reducing complexity and increasing flexibility. Spring Microservices in Action, Second Edition teaches you how to build microservice-based applications using Java and the Spring platform. This second edition is fully updated for the latest version of Spring, with expanded coverage of API routing with Spring Cloud Gateway, logging with the ELK stack, metrics with Prometheus and Grafana, security with the Hashicorp Vault, and modern deployment practices with Kubernetes and Istio.

About the Technology

Microservices break up your code into independent interconnected services that require careful forethought and design. Fortunately, Spring Boot, Spring Cloud, and Spring Cloud Gateway simplify the tedious plumbing and infrastructure setup required for microservice applications. Spring Boot removes the boilerplate code involved with writing a REST-based service. Spring Cloud provides a suite of tools for the discovery, routing, and deployment of microservices to the enterprise and the cloud. Spring Cloud Gateway provides a clear and effective routing to APIs, with a single entry point into a system. Together, they make it a snap to spin up Spring applications as microservices and wire them together into a reliable, scalable system.

About the book

Fully updated and upgraded for the latest version of Spring, Spring Microservices in Action, Second Edition is an expanded revision of a Manning bestseller. In it, you’ll learn how to build microservice-based applications using Java and the Spring platform and how to efficiently monitor and log your microservices operations. Throughout the book, carefully selected real-life examples expose microservice-based patterns for configuring, routing, scaling, and deploying your services. You'll see how Spring's intuitive tooling can help augment and refactor existing applications with microservices and how Spring Cloud Gateway makes it easy to handle multiple APIs with a single tool. You’ll also pick up best practices for using Spring with modern deployment platforms based on Kubernetes and Istio.
Table of Contents detailed table of contents

1 Welcome to the cloud, Spring

1.1 The evolution towards a microservices architecture

1.1.1 What’s a monolithic architecture?

1.1.2 What’s a microservice?

1.1.3 Why change the way we build applications?

1.2 Microservices with Spring

1.3 What is this book about?

1.3.1 What you’ll learn in this book

1.3.2 Why is this book relevant to you?

1.4 Cloud and microservice-based applications

1.4.1 Building a microservice with Spring Boot

1.4.2 What exactly is cloud computing?

1.4.3 Why the cloud and microservices?

1.5 Microservices are more than writing the code

1.6 Core microservice development pattern

1.7 Microservice routing patterns

1.8 Microservice client resiliency

1.9 Microservice security patterns

1.10 Microservice logging and tracing patterns

1.11 Application metrics pattern

1.12 Microservice build/deployment patterns

1.13 Summary

2 Exploring the microservices world with Spring Cloud

2.1 What is Spring Cloud

2.1.1 Spring Cloud Config

2.1.2 Spring Cloud Service Discovery

2.1.3 Spring Cloud Load Balance and Resilience4j

2.1.4 Spring Cloud API Gateway

2.1.5 Spring Cloud Stream

2.1.6 Spring Cloud Sleuth

2.1.7 Spring Cloud Security

2.2 Spring Cloud by example

2.3 How to build a cloud-native microservice?

2.3.1 Code Base

2.3.2 Dependencies

2.3.3 Config

2.3.4 Backing services

2.3.5 Build, release, run

2.3.6 Processes

2.3.7 Port binding

2.3.8 Concurrency

2.3.9 Disposability

2.3.10 Dev/prod parity

2.3.11 Logs

2.3.12 Admin processes

2.4 Making sure our examples are relevant

2.5 Building microservice with Spring Boot and Java

2.5.1 Setting up the environment

2.5.2 Getting started with the skeleton project

2.5.3 Booting your Spring Boot application: Writing the Bootstrap class

2.6 Summary

3 Building microservices with Spring Boot

3.1 Making sure our examples are relevant

3.2 The architect’s story: designing the microservice architecture

3.2.1 Decomposing the business problem

3.2.2 Establishing service granularity

3.2.3 Defining the service interfaces

3.3 When not to use microservices

3.3.1 Complexity of building distributed systems

3.3.2 Server sprawl

3.3.3 Type of application

3.3.4 Data transactions and consistency

3.4 The developer’s tale: building a microservice with Spring Boot and Java

3.4.1 Setting up the environment

3.4.2 Getting started with the skeleton project

3.4.3 Booting your Spring Boot application: Writing the Bootstrap class

3.4.4 Building the doorway into the microservice: The Spring Boot controller

3.4.5 Applying internationalization into the licensing service

3.5 The DevOps story: building for the rigors of runtime

3.5.1 Service assembly: packaging and deploying your microservices

3.5.2 Service bootstrapping: managing configuration of your microservices

3.5.3 Service registration and discovery: how clients communicate with your microservices

3.5.4 Communicating a microservice’s health

3.6 Pulling the perspectives together

3.7 Summary

4 Welcome to Docker

4.1 Containers or virtual machines?

4.2 What is Docker?

4.3 Dockerfiles

4.3.1 Dockerfile commands

4.4 Docker compose

4.4.1 Docker-compose commands

4.5 Integrating docker with our microservices

4.5.1 Building the Docker Image

4.5.2 Launching the services with Docker Compose

4.6 Summary

5 Controlling your configuration with Spring Cloud configuration server

5.1 On managing configuration (and complexity)

5.1.1 Your configuration management architecture

5.1.2 Implementation choices

5.2 Building our Spring Cloud configuration server

5.2.1 Setting up the Spring Cloud Config Bootstrap class

5.2.2 Using Spring Cloud configuration server with the filesystem

5.2.3 Setting up the configuration files for a service

5.3 Integrating Spring Cloud Config with a Spring Boot client

5.3.1 Setting up the licensing service Spring Cloud Config service dependencies

5.3.2 Configuring the licensing service to use Spring Cloud Config

5.3.3 Wiring in a data source using Spring Cloud configuration server

5.3.4 Directly reading properties using the @Value annotation

5.3.5 Refreshing your properties using Spring Cloud configuration server

5.3.6 Using Spring Cloud configuration server with Git

5.3.7 Integrating Vault with Spring Cloud Config service

5.3.8 Vault UI

5.4 Protecting sensitive configuration information

5.4.1 Setting up a symmetric encryption key

5.4.2 Encrypting and decrypting a property

5.5 Closing thoughts

5.6 Summary

6 On service discovery

6.1 Where’s my service?

6.2 On service discovery in the cloud

6.2.1 The architecture of service discovery

6.2.2 Service discovery in action using Spring and Netflix Eureka

6.3 Building our Spring Eureka Service

6.4 Registering services with Spring Eureka

6.4.1 Eureka’s REST API

6.4.2 Eureka dashboard

6.5 Using service discovery to look up a service

6.5.1 Looking up service instances with Spring Discovery Client

6.5.2 Invoking services with a LoadBalancer-aware Spring RestTemplate

6.5.3 Invoking services with Netflix Feign client

6.6 Summary

7 When bad things happen: resiliency patterns with Spring Cloud and Resilience4j

7.1 What are client-side resiliency patterns?

7.1.1 Client-side load balancing

7.1.2 Circuit Breaker

7.1.3 Fallback processing

7.1.4 Bulkheads

7.2 Why client resiliency matters?

7.3 Implementing Resilience4j

7.4 Setting up the licensing server to use Spring Cloud and Resilience4j

7.5 Implementing a circuit breaker

7.5.1 Adding the circuit breaker to the organization microservice

7.5.2 Customizing the circuit breaker

7.6 Fallback processing

7.7 Implementing the bulkhead pattern

7.8 Implementing the retry pattern

7.9 Implementing the rate limiter pattern

7.10 ThreadLocal and Resilience4j

7.11 Summary

8 Service routing with Spring Cloud Gateway

8.1 What is a services gateway?

8.2 Introducing Spring Cloud Gateway

8.2.1 Setting up the Gateway Spring Boot project

8.2.2 Configuring the Spring Cloud Gateway to communicate with Eureka

8.3 Configuring routes in Spring Cloud Gateway

8.3.1 Automated mapping of routes via service discovery

8.3.2 Mapping routes manually using service discovery

8.3.3 Dynamically reload route configuration

8.4 The real power of the Spring Cloud Gateway: predicate and filters factories

8.4.1 Built-in Predicates Factories

8.4.2 Built-in Filters Factories

8.4.3 Custom Filters

8.5 Building the pre-filter

8.5.1 Using the correlation ID in the services

8.6 Building a post filter receiving correlation IDs

8.7 Summary

9 Securing your microservices

9.1 Introduction to OAuth2

9.2 Starting small: using Spring and OAuth2 to protect a single endpoint

9.2.1 Setting up the Ostock OAuth2 authentication service

9.2.2 Registering client applications with the OAuth2 service

9.2.3 Configuring Ostock users

9.2.4 Authenticating the user

9.3 Protecting the organization service using OAuth2

9.3.1 Adding the Spring Security and OAuth2 jars to the individual services

9.3.2 Configuring the service to point to our OAuth2 authentication service

9.3.3 Defining who and what can access the service

9.3.4 Propagating the OAuth2 access token

9.4 JSON Web Tokens and OAuth2

9.4.1 Modifying the authentication service to issue JWT

9.4.2 Consuming JWT in our microservices

9.4.3 Parsing a custom filed out of a JWT

9.5 Some closing thoughts on microservice security

9.6 Summary

10 Event-driven architecture with Spring Cloud Stream

10.1 The case for messaging, EDA, and microservices

10.1.1 Using synchronous request-response approach to communicate state change

10.1.2 Using messaging to communicate state changes between services

10.1.3 Downsides of a messaging architecture

10.2 Introducing Spring Cloud Stream

10.3 Writing a simple message producer and consumer

10.3.1 Writing the message producer in the organization service

10.3.2 Writing the message consumer in the licensing service

10.3.3 Seeing the message service in action

10.4 A Spring Cloud Stream use case: distributed caching

10.4.1 Using Redis to cache lookups

10.4.2 Defining custom channels

10.5 Summary

11 Distributed tracing with Spring Cloud Sleuth and Zipkin

11.1 Spring Cloud Sleuth and the correlation IDs

11.1.1 Adding Spring Cloud sleuth to licensing and organization

11.1.2 Anatomy of a Spring Cloud Sleuth trace

11.2 Log aggregation and Spring Cloud Sleuth

11.2.1 A Spring Cloud Sleuth/ELK stack implementation in action

11.2.2 Configure logback in our services.

11.2.3 Define and run ELK stack applications in Docker

11.2.4 Configuring Kibana

11.2.5 Searching for Spring Cloud Sleuth Trace IDs in Kibana

11.2.6 Adding the correlation ID to the HTTP response with Spring Cloud Gateway

11.3 Distributed tracing with Open Zipkin

11.3.1 Setting up the Spring Cloud Sleuth and Zipkin dependencies

11.3.2 Configuring the services to point to Zipkin

11.3.3 Configuring a Zipkin Server

11.3.4 Setting tracing levels

11.3.5 Using Zipkin to trace transactions

11.3.6 Visualizing a more complex transaction

11.3.7 Capturing messaging traces

11.3.8 Adding custom spans

11.4 Summary

12 Deploying your microservices

12.1 Ostock: setting up the core infrastructure in the cloud

12.1 1 Creating the PostgreSQL database using Amazon RDS

12.1 2 Creating the Redis cluster in Amazon

12.2 Beyond the infrastructure: deploying OStock and ELK

12.2.1 Creating an EC2 with the ELK Services

12.2.2 Deploying the ELK stack in the EC2 instance

12.2.3 Creating an EKS Cluster

12.3 The architecture of a build/deployment pipeline

12.4 Your build and deployment pipeline in action

12.5 Beginning our build deploy/pipeline: Github and Jenkins

12.5.1 Setting up Github

12.5.2 Enabling our services to build in Jenkins

12.5.3 Understanding and generating the pipeline script

12.5.4 Creating the Kubernetes pipeline scripts

12.6 Closing thoughts on the build/deployment pipeline

12.7 Summary

Appendix A: Microservice Architecture Best Practices

A.1 Microservice Architecture best practices

A.1.1 Richardson level of maturity

A.1.2 Spring HATEOAS

A.1.3 Externalized configuration

A.1.4 Continuous Integration and Continuous delivery

A.1.5 Monitoring

A.1.6 Logging

A.1.7 API Gateways

A.2 Summary

Appendix B: OAuth2 grant types

B.1 Password grants

B.2 Client credential grants

B.3 Authorization code grants

B.4 Implicit grant

B.5 How tokens are refreshed

Appendix C: Monitoring your microservices

C.1 Introduction to monitoring with Spring Boot Actuator

C.2 Setting up micrometer and Prometheus

C.2.1 Understanding Micrometer and Prometheus

C.2.2 Implementing Micrometer and Prometheus

C.3 Configuring Grafana

What's inside

  • Core microservice design principles
  • Microservices best practices
  • Using docker containers to run microservices
  • Managing configuration with Spring Cloud Config and Hashicorp Vault for sensitive information
  • Client-side resiliency with Hystrix, and Ribbon
  • Managing application metrics with Prometheus and Grafana
  • Intelligent routing using Spring Cloud Gateway
  • Distributed tracing with Spring Cloud Sleuth, Zipkin and ELK Stack
  • Deploying Spring Cloud applications with Kubernetes and Istio

About the reader

This book is written for developers with Java and Spring experience.

About the authors

John Carnell is a senior cloud engineer with twenty years of experience in Java. Illary Huaylupo Sánchez is a software engineer with an MBA in IT management and over twelve years of experience in Java.

placing your order...

Don't refresh or navigate away from the page.
Manning Early Access Program (MEAP) Read chapters as they are written, get the finished eBook as soon as it’s ready, and receive the pBook long before it's in bookstores.
print book $24.99 $49.99 pBook + eBook + liveBook
includes previous edition eBook
Additional shipping charges may apply
Spring Microservices in Action, Second Edition (print book) added to cart
continue shopping
go to cart

eBook $19.99 $39.99 3 formats + liveBook
includes previous edition eBook
Spring Microservices in Action, Second Edition (eBook) added to cart
continue shopping
go to cart

Prices displayed in rupees will be charged in USD when you check out.
customers also reading

This book 1-hop 2-hops 3-hops

FREE domestic shipping on three or more pBooks