O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Mastering Spring Cloud

Book Description

Learn how to build, test, secure, deploy, and efficiently consume services across distributed systems.

About This Book
  • Explore the wealth of options provided by Spring Cloud for wiring service dependencies in microservice systems.
  • Create microservices utilizing Spring Cloud's Netflix OSS
  • Architect your cloud-native data using Spring Cloud.
Who This Book Is For

This book appeals to developers keen to take advantage of Spring cloud, an open source library which helps developers quickly build distributed systems. Knowledge of Java and Spring Framework will be helpful, but no prior exposure to Spring Cloud is required.

What You Will Learn
  • Abstract Spring Cloud's feature set
  • Create microservices utilizing Spring Cloud's Netflix OSS
  • Create synchronous API microservices based on a message-driven architecture.
  • Explore advanced topics such as distributed tracing, security, and contract testing.
  • Manage and deploy applications on the production environment
In Detail

Developing, deploying, and operating cloud applications should be as easy as local applications. This should be the governing principle behind any cloud platform, library, or tool. Spring Cloud–an open-source library–makes it easy to develop JVM applications for the cloud. In this book, you will be introduced to Spring Cloud and will master its features from the application developer's point of view.

This book begins by introducing you to microservices for Spring and the available feature set in Spring Cloud. You will learn to configure the Spring Cloud server and run the Eureka server to enable service registration and discovery. Then you will learn about techniques related to load balancing and circuit breaking and utilize all features of the Feign client. The book now delves into advanced topics where you will learn to implement distributed tracing solutions for Spring Cloud and build message-driven microservice architectures. Before running an application on Docker container s, you will master testing and securing techniques with Spring Cloud.

Style and approach

This comprehensive guide covers the advanced features of Spring Cloud and communicates them through a practical approach to explore the underlying concepts of how, when, and why to use them.

Downloading the example code for this book You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

Table of Contents

  1. Title Page
  2. Copyright and Credits
    1. Mastering Spring Cloud
  3. Packt Upsell
    1. Why subscribe?
    2. PacktPub.com
  4. Contributors
    1. About the author
    2. About the reviewer
    3. Packt is searching for authors like you
  5. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Download the example code files
      2. Conventions used
    4. Get in touch
      1. Reviews
  6. Introduction to Microservices
    1. The blessings of microservices
    2. Building microservices with Spring Framework
    3. Cloud-native development
    4. Learning the microservices architecture
      1. Understanding the need for service discovery
      2. Communication between services
      3. Failures and circuit breakers
    5. Summary
  7. Spring for Microservices
    1. Introducing Spring Boot
    2. Developing applications with Spring Boot
      1. Customizing configuration files
      2. Creating RESTful Web Services
    3. API Documentation
      1. Using Swagger 2 together with Spring Boot
      2. Testing API with Swagger UI
    4. Spring Boot Actuator features
      1. Application information
      2. Health information
      3. Metrics
    5. Developer tools
    6. Integrating application with database
      1. Building a sample application
    7. Running the application
    8. Summary
  8. Spring Cloud Overview
    1. Beginning with the basics
      1. Netflix OSS
        1. Service discovery with Eureka
        2. Routing with Zuul
        3. Load balancing with Ribbon
        4. Writing Java HTTP clients
        5. Latency and fault tolerance with Hystrix
        6. Configuration management with Archaius
    2. Discovery and distributed configuration
      1. An alternative – Consul
      2. Apache Zookeeper
      3. Miscellaneous projects
    3. Distributed tracing with Sleuth
    4. Messaging and integration
    5. Cloud platform support
    6. Other useful libraries
      1. Security
      2. Automated testing
      3. Cluster features
    7. Projects overview 
    8. Release trains
    9. Summary
  9. Service Discovery
    1. Running Eureka on the server side
    2. Enabling Eureka on the client side
      1. Deregistration on shutdown
      2. Using discovery client programmatically
    3. Advanced configuration settings
      1. Refreshing the registry
      2. Changing the instance identificator 
      3. Preferring the IP address
      4. Response cache
    4. Enabling secure communication between client and server
      1. Registering a secure service
    5. Eureka API
    6. Replication and high availability
      1. Architecture of the sample solution
      2. Building the example application
      3. Failover
    7. Zones
      1. Zones with a standalone server
      2. Building an example application
    8. Summary
  10. Distributed Configuration with Spring Cloud Config
    1. Introduction to HTTP API resources
      1. Native profile support
    2. Building a server-side application
    3. Building a client-side application
      1. Adding a Eureka Server
    4. Client-side bootstrap approaches
      1. Config Server discovery
    5. Repository backend types
      1. Filesystem backend
      2. Git backend
        1. Different protocols
        2. Using placeholders in URIs
        3. Building a server application
        4. Client-side configuration
        5. Multiple repositories
      3. Vault backend
        1. Getting started with Vault
        2. Integration with Spring Cloud Config
          1. Client-side configuration
    6. Additional features
      1. Fail on start and retry
      2. Secure client
    7. Reload configuration automatically
      1. Solution architecture
      2. Reload configuration with @RefreshScope
      3. Consuming events from a message broker
      4. Monitoring repository changes on a Config Server
        1. Simulating change events manually
        2. Testing locally with a GitLab instance 
    8. Summary
  11. Communication Between Microservices
    1. Different styles of communication 
    2. Synchronous communication with Spring Cloud
    3. Load balancing with Ribbon
      1. Enabling communication between microservices using the Ribbon client
        1. Static load balancing configuration
        2. Calling other services
    4. Using RestTemplate together with service discovery
      1. Building example application
    5. Using Feign client
      1. Support for different zones
      2. Enabling Feign for an application
        1. Building Feign interfaces
        2. Launching microservices
      3. Inheritance support
      4. Creating a client manually
      5. Client customization
    6. Summary
  12. Advanced Load Balancing and Circuit Breakers
    1. Load balancing rules
      1. The WeightedResponseTime rule
        1. Introducing Hoverfly for testing
        2. Testing the rule
    2. Customizing the Ribbon client
    3. The circuit breaker pattern with Hystrix
      1. Building an application with Hystrix
        1. Implementing Hystrix's commands
        2. Implementing fallback with cached data
      2. The tripping circuit breaker
    4. Monitoring latency and fault tolerance
      1. Exposing Hystrix's metrics stream
      2. Hystrix dashboard
        1. Building an application with the dashboard
        2. Monitoring metrics on the dashboard
        3. Aggregating Hystrix's streams with Turbine
          1. Enabling Turbine
          2. Enabling Turbine with streaming
    5. Failures and the circuit breaker pattern with Feign
      1. Retrying the connection with Ribbon
      2. Hystrix's support for Feign
    6. Summary
  13. Routing and Filtering with API Gateway
    1. Using Spring Cloud Netflix Zuul
      1. Building a gateway application
      2. Integration with service discovery
      3. Customizing route configuration
        1. Ignoring registered services
        2. Explicity set service name 
        3. Route definition with the Ribbon client
        4. Adding a prefix to the path
        5. Connection settings and timeouts
        6. Secure headers
      4. Management endpoints
      5. Providing Hystrix fallback
      6. Zuul filters
        1. Predefined filters
        2. Custom implementations
    2. Using Spring Cloud Gateway
      1. Enable Spring Cloud Gateway for a project
      2. Built-in predicates and filters
      3. Gateway for microservices
      4. Integration with service discovery
    3. Summary
  14. Distributed Logging and Tracing
    1. Best logging practices for microservices
    2. Logging with Spring Boot
    3. Centralizing logs with ELK Stack
      1. Setting up ELK Stack on the machine
      2. Integrating an application with ELK Stack
        1. Using LogstashTCPAppender
        2. Using AMQP appender and a message broker
    4. Spring Cloud Sleuth
      1. Integrating Sleuth with an application
      2. Searching events using Kibana
      3. Integrating Sleuth with Zipkin
        1. Running the Zipkin server
        2. Building the client application
          1. Analyze data with the Zipkin UI
          2. Integration via message broker
    5. Summary
  15. Additional Configuration and Discovery Features
    1. Using Spring Cloud Consul
      1. Running Consul agent
      2. Integration on the client side
      3. Service discovery
        1. Health check
        2. Zones
        3. Client settings customization
        4. Running in clustered mode
      4. Distributed configuration
        1. Managing properties in Consul
        2. Client customization
        3. Watching configuration changes
    2. Using Spring Cloud Zookeeper
      1. Running Zookeeper
      2. Service discovery
        1. Client implementation
        2. Zookeeper dependencies
      3. Distributed configuration
    3. Summary
  16. Message-Driven Microservices
    1. Learning about Spring Cloud Stream
    2. Building a messaging system
      1. Enabling Spring Cloud Stream
      2. Declaring and binding channels
      3. Customizing connectivity with the RabbitMQ broker
      4. Integration with other Spring Cloud projects
    3. The publish/subscribe model
      1. Running a sample system
      2. Scaling and grouping
        1. Running multiple instances
        2. Consumer groups
        3. Partitioning
    4. Configuration options
      1. Spring Cloud Stream properties
      2. Binding properties
        1. The consumer
        2. The producer
    5. The advanced programming model
      1. Producing messages
      2. Transformation
      3. Consuming messages conditionally
    6. Using Apache Kafka
      1. Running Kafka
      2. Customizing application settings
      3. Kafka Streams API support
      4. Configuration properties
    7. Multiple binders
    8. Summary
  17. Securing an API
    1. Enabling HTTPS for Spring Boot
    2. Secure discovery
      1. Registering a secure application
      2. Serving Eureka over HTTPS
        1. Keystore generation
        2. Configurating SSL for microservices and Eureka server
    3. Secure configuration server
      1. Encryption and decryption
      2. Configuring authentication for a client and a server
    4. Authorization with OAuth2
      1. Introduction to OAuth2
      2. Building an authorization server
      3. Client configuration
      4. Using the JDBC backend store
      5. Inter-service authorization
      6. Enabling SSO on the API gateway
    5. Summary
  18. Testing Java Microservices
    1. Testing strategies
    2. Testing Spring Boot applications
      1. Building the sample application
      2. Integration with the database
    3. Unit tests
    4. Component tests
      1. Running tests with an in-memory database
      2. Handling HTTP clients and service discovery
      3. Implementing sample tests
    5. Integration tests
      1. Categorizing tests
      2. Capturing HTTP traffic
    6. Contract tests
      1. Using Pact
        1. Consumer side
        2. Producer side
      2. Using Spring Cloud Contract
        1. Defining contracts and generating stubs
        2. Verifying a contract on the consumer side
        3. Scenarios
    7. Performance testing
      1. Gatling
        1. Enabling Gatling
        2. Defining the test scenario
        3. Running a test scenario
    8. Summary
  19. Docker Support
    1. Introducing Docker
    2. Installing Docker
    3. Commonly used Docker commands
      1. Running and stopping a container
      2. Listing and removing containers
      3. Pulling and pushing images
      4. Building an image
      5. Networking
    4. Creating a Docker image with microservices
      1. Dockerfiles
      2. Running containerized microservices
      3. Building an image using the Maven plugin
      4. Advanced Docker images
    5. Continuous Delivery
      1. Integrating Jenkins with Docker
      2. Building pipelines
    6. Working with Kubernetes
      1. Concepts and components
      2. Running Kubernetes locally via Minikube
      3. Deploying an application
      4. Maintaining a cluster
    7. Summary
  20. Spring Microservices on Cloud Platforms
    1. Pivotal Cloud Foundry
      1. Usage models
      2. Preparing the application
      3. Deploying the application
        1. Using CLI
        2. Binding to services
        3. Using the Maven plugin
      4. Maintenance
        1. Accessing deployment details
        2. Managing application life cycles
        3. Scaling
        4. Provisioning brokered services
    2. The Heroku platform
      1. Deployment methods
        1. Using the CLI
        2. Connecting to the GitHub repository
        3. Docker Container Registry
      2. Preparing an application
      3. Testing deployments
    3. Summary
  21. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think