Spring Microservices in Action
John Carnell
  • MEAP began September 2016
  • Publication in Summer 2017 (estimated)
  • ISBN 9781617293986
  • 375 pages (estimated)
  • printed in black & white

With microservices, you build applications from very small, loosely coupled, and distributed services. Spring Boot and Spring Cloud offer Java developers an easy migration path from traditional monolithic Spring applications to microservice-based applications that can be deployed to multiple cloud platforms. The Spring Boot and Spring Cloud frameworks let you quickly build microservices that are ready to be deployed to a private corporate cloud or a public cloud like Amazon Web Services (AWS) or Pivotal's CloudFoundry.

Spring Microservices in Action teaches you how to use the Spring Boot and Spring Cloud frameworks to build and deploy microservice-based cloud applications. You'll begin with an introduction to the microservice pattern and how to build microservices with Spring Boot and Spring Cloud. Then you'll get hands-on and discover how to configure Spring Boot. Using lots of real-world examples, you'll learn topics like service discovery with Spring Cloud, Netflix Eureka, and Ribbon. Next, you'll find out how to handle potential problems using client-side resiliency patterns with Spring and Netflix Hystrix. This book also covers implementing a service gateway with Spring Cloud and Zuul and event processing in the cloud with Spring Cloud Stream. Finally, you'll learn to deploy and push your application to cloud services, including AWS and CloudFoundry. By the end of this book, you'll not only be able to build your own microservice-based applications, but how operationalize and scale your microservices so they can deployed to a private or public cloud.

Table of Contents detailed table of contents

1. Welcome to the cloud, Spring

1.1. What is a microservice?

1.2. What is Spring and why is relevant to microservices?

1.3. What you will learn in this book

1.4. Why is this book relevant to you?

1.5. Building a microservice with Spring Boot

1.6. Why change the way we build applications?

1.7. What exactly is the cloud?

1.8. Why the cloud and microservices?

1.9. Microservices are more than just writing the code

1.9.1. Core microservice development pattern

1.9.2. Microservice routing patterns

1.9.3. Microservice client resiliency patterns

1.9.4. Microservice build/deployment patterns

1.10. Leveraging Spring Cloud in building your microservices

1.10.1. Spring Boot

1.10.2. Spring Cloud Config

1.10.3. Spring Cloud Service Discovery

1.10.4. Spring Cloud/Netflix Hystrix and Ribbon

1.10.5. Spring Cloud/Netflix Zuul

1.10.6. Spring Cloud Stream

1.10.7. What about Provisioning?

1.11. Spring Cloud by example

1.12. Making sure our examples are relevant

1.13. Summary

2. Building microservices with Spring Boot

2.1. The architect's story: designing the microservice architecture

2.1.1. Decomposing the business problem

2.1.2. Establishing Service Granularity

2.1.3. Talking to one another: service interfaces

2.2. When not to use microservices

2.2.1. Complexity of building distributed systems

2.2.2. Server sprawl

2.2.3. Type of application

2.2.4. Data Transformations and consistency

2.3. The developer's tale: building a microservice with Spring Boot and Java

2.3.1. Getting started with the skeleton project

2.3.2. Booting our Spring Boot application: writing the Bootstrap class

2.3.3. Building the doorway into the microservice: the Spring Boot controller

2.4. TheDevOps story: building for the rigors of runtime

2.4.1. Service assembly: packaging and deploying your microservices

2.4.2. Service Bootstrapping: Managing configuration of your microservices

2.4.3. Service registration and discovery: how clients communicate to your microservices

2.4.4. Communicating a microservice's health

2.5. Pulling the perspectives together

2.6. Summary

3. Controlling your configuration in the Cloud with Spring Cloud Config

3.1. On managing configuration (and complexity)

3.1.1. Our configuration management architecture

3.1.2. Implementation choices

3.2. Building our Spring Cloud Configuration Server

3.2.1. Using Spring Cloud Configuration Server with the filesystem

3.3. Integrating Spring Cloud Configuration with a Spring Boot Client

3.3.1. Setting up the Licensing Service Spring Cloud Config Server Dependencies

3.3.2. Configuring the Licensing Service to use Spring Cloud Config

3.3.3. Wiring in a data source using Spring Cloud Configuration Server

3.3.4. Directly Reading Properties using the @Value Annotation

3.3.5. Using Spring Cloud Configuration Server with Git

3.3.6. Refreshing your properties using Spring Cloud Configuration Server

3.4. Summary

4. On service discovery

4.1. Where's my Service?

4.2. On Service Discovery in the Cloud

4.2.1. The Architecture of Service Discovery

4.2.2. Service Discovery in Action Using Spring and Netflix Eureka

4.3. Building our Spring Eureka Service

4.4. Registering Services with Spring Eureka

4.5. Using Service Discovery to Look up a Service

4.5.1. Looking up Service Instances with Spring DiscoveryClient

4.5.2. Invoking Services with Spring RestTemplate

4.5.3. Invoking Services with Netflix Feign Client

4.6. Summary

5. When bad things happen: client resiliency patterns with Spring Cloud and Netflix Hystrix

5.1. What are client-side resiliency patterns

5.1.1. Client-side load balancing

5.1.2. Circuit breaker

5.1.3. Fallback processing

5.1.4. Bulkheads

5.2. Why client resiliency matters

5.3. Enter Hystrix

5.4. Setting up the licensing server to use Spring Cloud and Hystrix

5.5. Implementing a circuit breaker using Hystrix.

5.5.1. Timing out a call to the organization microservice

5.5.2. Customizing the timeout on a circuit breaker

5.6. Fallback processing

5.7. Implementing the Bulkhead Pattern

5.8. Getting beyond the basics, fine tuning Hystrix

5.8.1. Hystrix Configuration Revisited

5.9. Summary

6. Service routing with Spring Cloud and Zuul

6.1. What is a services gateway?

6.2. Introducing Spring Cloud and Netflix Zuul

6.2.1. Setting up Zuul Spring Boot Project

6.2.2. Using Spring Cloud Annotation for the Zuul Service

6.2.3. Configuring Zuul to communicate with Eureka

6.3. Configuring Routes in Zuul

6.3.1. Automated mapping routes via service discovery

6.3.2. Mapping routes manually using service discovery

6.3.3. Manual mapping of routes using static URLs

6.3.4. Dynamically reload route configuration

6.3.5. Zuul and Service timeouts

6.4. The Real Power of Zuul: Filters

6.5. Building our first Zuul pre-filter Generating Correlation Ids

6.5.1. Using the Correlation ID in your service calls

6.6. Building a Post Filter Receiving Correlation IDs

6.7. Building a Dynamic Route Filter

6.7.1. Building the skeleton of the routing filter

6.7.2. Implementing the run() method

6.7.3. Forwarding the route

6.7.4. Pulling it all together

6.8. Summary

7. Securing your microservices

7.1. Introduction to OAuth2

7.2. Starting small, using Spring and OAuth2 to protect a single endpoint

7.2.1. Setting up the EagleEye OAuth2 authentication service

7.2.2. Registering our client applications with the OAuth2 service

7.2.3. Configuring some EagleEye users

7.2.4. Authenticating the user

7.3. Protecting the Organization Service using OAuth2

7.3.1. Adding the Spring Security and OAuth2 jars to the individual services

7.3.2. Configuring the service to point to our OAuth2 authentication service

7.3.3. Defining who and what can access the service

7.3.4. Propagating the OAuth2 access token

7.4. JSON Web Tokens and OAuth2

7.4.1. Modifying the authentication service to issue JSON web tokens

7.4.2. Consuming JSON web tokens in your microservices

7.4.3. Extending the JWT Token

7.4.4. Parsing a custom field out of a JSON Token

7.5. Some closing thoughts on microservice security

7.6. Summary

8. Event Driven Architecture with Spring Cloud Stream

8.1. The case for messaging, EDA and microservices

8.1.1. Using synchronous request-response approach to communicate state change

8.1.2. Using messaging to communicate state changes between services

8.1.3. Downsides of a messaging architecture

8.2. Introducing Spring Cloud Stream

8.2.1. The Spring Cloud Stream architecture

8.3. Writing a simple message producer and consumer

8.3.1. Writing the message producer in the organization service

8.3.2. Writing the message consumer in the licensing service

8.3.3. Seeing the message service in action

8.4. A Spring Cloud Stream use case: distributed caching

8.4.1. Using Redis to cache lookups

8.4.2. Defining custom channels

8.4.3. Bringing it all together: Clearing the cache when a message is received

8.5. Summary

9. Debugging your services with Spring Cloud Sleuth and Zipkin

10. Getting ready to launch: getting your Spring Cloud application ready for deployment


Appendix A: Setting up a desktop cloud: using Docker Machine and Docker Compose

Appendix B: B OAuth2 Grant Types

What's inside

  • Core design principles of microservices
  • Building microservices using Spring boot
  • Intelligent routing through Spring Cloud and Netflix Zuul
  • Processing events within your cloud-based application
  • Deploying applications to AWS and Pivotal Cloud Foundry

About the reader

This book is for developers with some Java and Spring experience. Knowledge of building web-based services with SOAP or REST is helpful but not required.

About the author

John Carnell is a Java developer with a Clojure addiction. He's a Senior Cloud Engineer at Interactive Intelligence and a prolific speaker and writer with 20 years of experience in the software development field. John has authored, co-authored, and been a technical reviewer for a number of technology books and industry publications.

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.
MEAP combo $49.99 pBook + eBook
MEAP eBook $39.99 pdf + ePub + kindle

FREE domestic shipping on three or more pBooks