0%

Spring Microservices in Action, Second Edition teaches you to build microservice-based applications using Java and Spring. You’ll start by creating basic services, then move to efficient logging and monitoring. Learn to refactor Java applications with Spring’s intuitive tooling, and master API management with Spring Cloud Gateway. You’ll even deploy Spring Cloud applications with AWS and Kubernetes.

Table of Contents

  1. inside front cover
  2. Spring Microservices in Action
  3. Copyright
  4. dedication
  5. brief contents
  6. contents
  7. front matter
    1. preface
    2. acknowledgments
    3. about this book
    4. Who should read this book
    5. How this book is organized: A roadmap
    6. About the code
    7. liveBook discussion forum
    8. about the authors
    9. About the cover illustration
  8. 1 Welcome to the cloud, Spring
    1. 1.1 The evolution towards a microservices architecture
    2. 1.1.1 N-tier architecture
    3. 1.1.2 What’s a monolithic architecture?
    4. 1.1.3 What’s a microservice?
    5. 1.1.4 Why change the way we build applications?
    6. 1.2 Microservices with Spring
    7. 1.3 What are we building?
    8. 1.4 What is this book about?
    9. 1.4.1 What you’ll learn in this book
    10. 1.4.2 Why is this book relevant to you?
    11. 1.5 Cloud and microservice-based applications
    12. 1.5.1 Building a microservice with Spring Boot
    13. 1.5.2 What exactly is cloud computing?
    14. 1.5.3 Why the cloud and microservices?
    15. 1.6 Microservices are more than writing the code
    16. 1.7 Core microservice development pattern
    17. 1.8 Microservice routing patterns
    18. 1.9 Microservice client resiliency
    19. 1.10 Microservice security patterns
    20. 1.11 Microservice logging and tracing patterns
    21. 1.12 Application metrics pattern
    22. 1.13 Microservice build/deployment patterns
    23. Summary
  9. 2 Exploring the microservices world with Spring Cloud
    1. 2.1 What is Spring Cloud?
    2. 2.1.1 Spring Cloud Config
    3. 2.1.2 Spring Cloud Service Discovery
    4. 2.1.3 Spring Cloud LoadBalancer and Resilience4j
    5. 2.1.4 Spring Cloud API Gateway
    6. 2.1.5 Spring Cloud Stream
    7. 2.1.6 Spring Cloud Sleuth
    8. 2.1.7 Spring Cloud Security
    9. 2.2 Spring Cloud by example
    10. 2.3 How to build a cloud-native microservice
    11. 2.3.1 Codebase
    12. 2.3.2 Dependencies
    13. 2.3.3 Config
    14. 2.3.4 Backing services
    15. 2.3.5 Build, release, run
    16. 2.3.6 Processes
    17. 2.3.7 Port binding
    18. 2.3.8 Concurrency
    19. 2.3.9 Disposability
    20. 2.3.10 Dev/prod parity
    21. 2.3.11 Logs
    22. 2.3.12 Admin processes
    23. 2.4 Making sure our examples are relevant
    24. 2.5 Building a microservice with Spring Boot and Java
    25. 2.5.1 Setting up the environment
    26. 2.5.2 Getting started with the skeleton project
    27. 2.5.3 Booting your Spring Boot application: Writing the bootstrap class
    28. Summary
  10. 3 Building microservices with Spring Boot
    1. 3.1 The architect’s story: Designing the microservice architecture
    2. 3.1.1 Decomposing the business problem
    3. 3.1.2 Establishing service granularity
    4. 3.1.3 Defining the service interfaces
    5. 3.2 When not to use microservices
    6. 3.2.1 Complexity when building distributed systems
    7. 3.2.2 Server or container sprawl
    8. 3.2.3 Application type
    9. 3.2.4 Data transactions and consistency
    10. 3.3 The developer’s tale: Building a microservice with Spring Boot and Java
    11. 3.3.1 Building the doorway into the microservice: The Spring Boot controller
    12. 3.3.2 Adding internationalization into the licensing service
    13. 3.3.3 Implementing Spring HATEOAS to display related links
    14. 3.4 The DevOps story: Building for the rigors of runtime
    15. 3.4.1 Service assembly: Packaging and deploying your microservices
    16. 3.4.2 Service bootstrapping: Managing configuration of your microservices
    17. 3.4.3 Service registration and discovery: How clients communicate with your microservices
    18. 3.4.4 Communicating a microservice’s health
    19. 3.5 Pulling the perspectives together
    20. Summary
  11. 4 Welcome to Docker
    1. 4.1 Containers or virtual machines?
    2. 4.2 What is Docker?
    3. 4.3 Dockerfiles
    4. 4.4 Docker Compose
    5. 4.5 Integrating Docker with our microservices
    6. 4.5.1 Building the Docker Image
    7. 4.5.2 Creating Docker images with Spring Boot
    8. 4.5.3 Launching the services with Docker Compose
    9. Summary
  12. 5 Controlling your configuration with the Spring Cloud Configuration Server
    1. 5.1 On managing configuration (and complexity)
    2. 5.1.1 Your configuration management architecture
    3. 5.1.2 Implementation choices
    4. 5.2 Building our Spring Cloud Configuration Server
    5. 5.2.1 Setting up the Spring Cloud Config bootstrap class
    6. 5.2.2 Using the Spring Cloud Config Server with a filesystem
    7. 5.2.3 Setting up the configuration files for a service
    8. 5.3 Integrating Spring Cloud Config with a Spring Boot client
    9. 5.3.1 Setting up the licensing service Spring Cloud Config Service dependencies
    10. 5.3.2 Configuring the licensing service to use Spring Cloud Config
    11. 5.3.3 Wiring in a data source using Spring Cloud Config Server
    12. 5.3.4 Directly reading properties using @ConfigurationProperties
    13. 5.3.5 Refreshing your properties using Spring Cloud Config Server
    14. 5.3.6 Using Spring Cloud Configuration Server with Git
    15. 5.3.7 Integrating Vault with the Spring Cloud Config service
    16. 5.3.8 Vault UI
    17. 5.4 Protecting sensitive configuration information
    18. 5.4.1 Setting up a symmetric encryption key
    19. 5.4.2 Encrypting and decrypting a property
    20. 5.5 Closing thoughts
    21. Summary
  13. 6 On service discovery
    1. 6.1 Where’s my service?
    2. 6.2 Service discovery in the cloud
    3. 6.2.1 The architecture of service discovery
    4. 6.2.2 Service discovery in action using Spring and Netflix Eureka
    5. 6.3 Building our Spring Eureka service
    6. 6.4 Registering services with Spring Eureka
    7. 6.4.1 Eureka’s REST API
    8. 6.4.2 Eureka dashboard
    9. 6.5 Using service discovery to look up a service
    10. 6.5.1 Looking up service instances with Spring Discovery Client
    11. 6.5.2 Invoking services with a Load Balancer–aware Spring REST template
    12. 6.5.3 Invoking services with Netflix Feign client
    13. Summary
  14. 7 When bad things happen: Resiliency patterns with Spring Cloud and Resilience4j
    1. 7.1 What are client-side resiliency patterns?
    2. 7.1.1 Client-side load balancing
    3. 7.1.2 Circuit breaker
    4. 7.1.3 Fallback processing
    5. 7.1.4 Bulkheads
    6. 7.2 Why client resiliency matters
    7. 7.3 Implementing Resilience4j
    8. 7.4 Setting up the licensing service to use Spring Cloud and Resilience4j
    9. 7.5 Implementing a circuit breaker
    10. 7.5.1 Adding the circuit breaker to the organization service
    11. 7.5.2 Customizing the circuit breaker
    12. 7.6 Fallback processing
    13. 7.7 Implementing the bulkhead pattern
    14. 7.8 Implementing the retry pattern
    15. 7.9 Implementing the rate limiter pattern
    16. 7.10 ThreadLocal and Resilience4j
    17. Summary
  15. 8 Service routing with Spring Cloud Gateway
    1. 8.1 What is a service gateway?
    2. 8.2 Introducing Spring Cloud Gateway
    3. 8.2.1 Setting up the Spring Boot gateway project
    4. 8.2.2 Configuring the Spring Cloud Gateway to communicate with Eureka
    5. 8.3 Configuring routes in Spring Cloud Gateway
    6. 8.3.1 Automated mapping of routes via service discovery
    7. 8.3.2 Manually mapping routes using service discovery
    8. 8.3.3 Dynamically reloading route configuration
    9. 8.4 The real power of Spring Cloud Gateway: Predicate and Filter Factories
    10. 8.4.1 Built-in Predicate Factories
    11. 8.4.2 Built-in Filter Factories
    12. 8.4.3 Custom filters
    13. 8.5 Building the pre-filter
    14. 8.6 Using the correlation ID in the services
    15. 8.6.1 UserContextFilter: Intercepting the incoming HTTP request
    16. 8.6.2 UserContext: Making the HTTP headers easily accessible to the service
    17. 8.6.3 Custom RestTemplate and UserContextInterceptor: Ensuring that the correlation ID gets propagated
    18. 8.7 Building a post-filter receiving correlation ID
    19. Summary
  16. 9 Securing your microservices
    1. 9.1 What is OAuth2?
    2. 9.2 Introduction to Keycloak
    3. 9.3 Starting small: Using Spring and Keycloak to protect a single endpoint
    4. 9.3.1 Adding Keycloak to Docker
    5. 9.3.2 Setting up Keycloak
    6. 9.3.3 Registering a client application
    7. 9.3.4 Configuring O-stock users
    8. 9.3.5 Authenticating our O-stock users
    9. 9.4 Protecting the organization service using Keycloak
    10. 9.4.1 Adding the Spring Security and Keycloak JARs to the individual services
    11. 9.4.2 Configuring the service to point to our Keycloak server
    12. 9.4.3 Defining who and what can access the service
    13. 9.4.4 Propagating the access token
    14. 9.4.5 Parsing a custom field in a JWT
    15. 9.5 Some closing thoughts on microservice security
    16. 9.5.1 Use HTTPS secure sockets layer (SSL) for all service communication
    17. 9.5.2 Use a service gateway to access your microservices
    18. 9.5.3 Zone your services into a public API and private API
    19. 9.5.4 Limit the attack surface of your microservices by locking down unneeded network ports
    20. Summary
  17. 10 Event-driven architecture with Spring Cloud Stream
    1. 10.1 The case for messaging, EDA, and microservices
    2. 10.1.1 Using a synchronous request-response approach to communicate state change
    3. 10.1.2 Using messaging to communicate state changes between services
    4. 10.1.3 Downsides of a messaging architecture
    5. 10.2 Introducing Spring Cloud Stream
    6. 10.3 Writing a simple message producer and consumer
    7. 10.3.1 Configuring Apache Kafka and Redis in Docker
    8. 10.3.2 Writing the message producer in the organization service
    9. 10.3.3 Writing the message consumer in the licensing service
    10. 10.3.4 Seeing the message service in action
    11. 10.4 A Spring Cloud Stream use case: Distributed caching
    12. 10.4.1 Using Redis to cache lookups
    13. 10.4.2 Defining custom channels
    14. Summary
  18. 11 Distributed tracing with Spring Cloud Sleuth and Zipkin
    1. 11.1 Spring Cloud Sleuth and the correlation ID
    2. 11.1.1 Adding Spring Cloud Sleuth to licensing and organization
    3. 11.1.2 Anatomy of a Spring Cloud Sleuth trace
    4. 11.2 Log aggregation and Spring Cloud Sleuth
    5. 11.2.1 A Spring Cloud Sleuth/ELK Stack implementation in action
    6. 11.2.2 Configuring Logback in our services
    7. 11.2.3 Defining and running ELK Stack applications in Docker
    8. 11.2.4 Configuring Kibana
    9. 11.2.5 Searching for Spring Cloud Sleuth trace IDs in Kibana
    10. 11.2.6 Adding the correlation ID to the HTTP response with Spring Cloud Gateway
    11. 11.3 Distributed tracing with Zipkin
    12. 11.3.1 Setting up the Spring Cloud Sleuth and Zipkin dependencies
    13. 11.3.2 Configuring the services to point to Zipkin
    14. 11.3.3 Configuring a Zipkin server
    15. 11.3.4 Setting tracing levels
    16. 11.3.5 Using Zipkin to trace transactions
    17. 11.3.6 Visualizing a more complex transaction
    18. 11.3.7 Capturing messaging traces
    19. 11.3.8 Adding custom spans
    20. Summary
  19. 12 Deploying your microservices
    1. 12.1 The architecture of a build/deployment pipeline
    2. 12.2 Setting up O-stock’s core infrastructure in the cloud
    3. 12.2.1 Creating the PostgreSQL database using Amazon RDS
    4. 12.2.2 Creating the Redis cluster in Amazon
    5. 12.3 Beyond the infrastructure: Deploying O-stock and ELK
    6. 12.3.1 Creating an EC2 with ELK
    7. 12.3.2 Deploying the ELK Stack in the EC2 instance
    8. 12.3.3 Creating an EKS cluster
    9. 12.4 Your build/deployment pipeline in action
    10. 12.5 Creating our build/deploy pipeline
    11. 12.5.1 Setting up GitHub
    12. 12.5.2 Enabling our services to build in Jenkins
    13. 12.5.3 Understanding and generating the pipeline script
    14. 12.5.4 Creating the Kubernetes pipeline scripts
    15. 12.6 Closing thoughts on the build/deployment pipeline
    16. Summary
  20. appendix A. Microservices architecture best practices
    1. A.1 Richardson Maturity Model
    2. A.2 Spring HATEOAS
    3. A.3 Externalized configuration
    4. A.4 Continuous integration (CI) and continuous delivery (CD)
    5. A.5 Monitoring
    6. A.6 Logging
    7. A.7 API gateways
  21. appendix B. OAuth2 grant types
    1. B.1 Password grant types
    2. B.2 Client credential grant type
    3. B.3 Authorization grant type
    4. B.4 Implicit grant type
    5. B.5 How tokens are refreshed
  22. appendix C. Monitoring your microservices
    1. C.1 Introducing monitoring with Spring Boot Actuator
    2. C.1.1 Adding Spring Boot Actuator
    3. C.1.2 Enabling Actuator endpoints
    4. C.2 Setting up Micrometer and Prometheus
    5. C.2.1 Understanding Micrometer and Prometheus
    6. C.2.2 Implementing Micrometer and Prometheus
    7. C.3 Configuring Grafana
    8. C.4 Summarizing our discussion
  23. index
  24. inside back cover
54.166.170.195