Tải bản đầy đủ (.pdf) (480 trang)

Mastering spring cloud build self healing, microservices based, distributed systems using spring cloud

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (9.81 MB, 480 trang )


Mastering Spring Cloud

Build self-healing, microservices-based, distributed systems using Spring Cloud

Piotr Mińkowski


BIRMINGHAM - MUMBAI



Mastering Spring Cloud
Copyright © 2018 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means,
without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the
information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing or its
dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the
appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
Commissioning Editor: Richa Tripathi
Acquisition Editor: Karan Sadawana
Content Development Editor: Lawrence Veigas
Technical Editor: Adhithya Haridas
Copy Editor: Safis Editing
Project Coordinator: Prajakta Naik
Proofreader: Safis Editing
Indexer: Rekha Nair
Graphics: Jisha Chirayil
Production Coordinator: Arvindkumar Gupta


First published: April 2018
Production reference: 1250418
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham
B3 2PB, UK.
ISBN 978-1-78847-543-3
www.packtpub.com


mapt.io

Mapt is an online digital library that gives you full access to over 5,000 books and videos, as well as
industry leading tools to help you plan your personal development and advance your career. For more
information, please visit our website.


Why subscribe?
Spend less time learning and more time coding with practical eBooks and Videos from over
4,000 industry professionals
Improve your learning with Skill Plans built especially for you
Get a free eBook or video every month
Mapt is fully searchable
Copy and paste, print, and bookmark content


PacktPub.com
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files
available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you

are entitled to a discount on the eBook copy. Get in touch with us at for more
details.
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free
newsletters, and receive exclusive discounts and offers on Packt books and eBooks.


Contributors


About the author
Piotr Mińkowski has more than 10 years of experience working as a developer and an architect in
the banking and telecommunications sectors. He specializes in Java as well as in technologies, tools,
and frameworks associated with it. Now, he is working at Play, a mobile operator in Poland, where
he is responsible for the IT systems architecture. Here, he helps the organization migrate from
monoliths/SOA to a microservices-based architecture, and also helps set up full Continuous
Integration and Delivery environments.


About the reviewer
Samer ABDELKAFI has over 13 years of experience as a software architect and engineer, with a
major focus on open source technologies. He has contributed to numerous and diverse projects in
different sectors, such as banking, insurance, education, public services, and utility billing. In the end
of 2016, he created DEVACT, a company specializing in information technology consulting. He also
reviewed a book titled Spring MVC Blueprints. In addition to his day job, Samer shares his
experience in his blog, writing articles related to Java and web technologies.


Packt is searching for authors like you
If you're interested in becoming an author for Packt, please visit authors.packtpub.com and apply today.
We have worked with thousands of developers and tech professionals, just like you, to help them

share their insight with the global tech community. You can make a general application, apply for a
specific hot topic that we are recruiting an author for, or submit your own idea.


Table of Contents
Title Page
Copyright and Credits
Mastering Spring Cloud
Packt Upsell
Why subscribe?
PacktPub.com
Contributors
About the author
About the reviewer
Packt is searching for authors like you
Preface
Who this book is for
What this book covers
To get the most out of this book
Download the example code files
Conventions used
Get in touch
Reviews


1.

Introduction to Microservices
The blessings of microservices
Building microservices with Spring Framework

Cloud-native development
Learning the microservices architecture
Understanding the need for service discovery
Communication between services
Failures and circuit breakers
Summary


2.

Spring for Microservices
Introducing Spring Boot
Developing applications with Spring Boot
Customizing configuration files
Creating RESTful Web Services
API Documentation
Using Swagger 2 together with Spring Boot
Testing API with Swagger UI
Spring Boot Actuator features
Application information
Health information
Metrics
Developer tools
Integrating application with database
Building a sample application
Running the application
Summary


3.


Spring Cloud Overview
Beginning with the basics
Netflix OSS
Service discovery with Eureka
Routing with Zuul
Load balancing with Ribbon
Writing Java HTTP clients
Latency and fault tolerance with Hystrix
Configuration management with Archaius
Discovery and distributed configuration
An alternative – Consul
Apache Zookeeper
Miscellaneous projects
Distributed tracing with Sleuth
Messaging and integration
Cloud platform support
Other useful libraries
Security
Automated testing
Cluster features
Projects overview 
Release trains
Summary


4.

Service Discovery
Running Eureka on the server side

Enabling Eureka on the client side
Deregistration on shutdown
Using discovery client programmatically
Advanced configuration settings
Refreshing the registry
Changing the instance identificator 
Preferring the IP address
Response cache
Enabling secure communication between client and server
Registering a secure service
Eureka API
Replication and high availability
Architecture of the sample solution
Building the example application
Failover
Zones
Zones with a standalone server
Building an example application
Summary


5.

Distributed Configuration with Spring Cloud Config
Introduction to HTTP API resources
Native profile support
Building a server-side application
Building a client-side application
Adding a Eureka Server
Client-side bootstrap approaches

Config Server discovery
Repository backend types
Filesystem backend
Git backend
Different protocols
Using placeholders in URIs
Building a server application
Client-side configuration
Multiple repositories
Vault backend
Getting started with Vault
Integration with Spring Cloud Config
Client-side configuration
Additional features
Fail on start and retry
Secure client
Reload configuration automatically
Solution architecture
Reload configuration with @RefreshScope
Consuming events from a message broker
Monitoring repository changes on a Config Server
Simulating change events manually
Testing locally with a GitLab instance 
Summary


6.

Communication Between Microservices
Different styles of communication 

Synchronous communication with Spring Cloud
Load balancing with Ribbon
Enabling communication between microservices using the Ribbon client
Static load balancing configuration
Calling other services
Using RestTemplate together with service discovery
Building example application
Using Feign client
Support for different zones
Enabling Feign for an application
Building Feign interfaces
Launching microservices
Inheritance support
Creating a client manually
Client customization
Summary


7.

Advanced Load Balancing and Circuit Breakers
Load balancing rules
The WeightedResponseTime rule
Introducing Hoverfly for testing
Testing the rule
Customizing the Ribbon client
The circuit breaker pattern with Hystrix
Building an application with Hystrix
Implementing Hystrix's commands
Implementing fallback with cached data

The tripping circuit breaker
Monitoring latency and fault tolerance
Exposing Hystrix's metrics stream
Hystrix dashboard
Building an application with the dashboard
Monitoring metrics on the dashboard
Aggregating Hystrix's streams with Turbine
Enabling Turbine
Enabling Turbine with streaming
Failures and the circuit breaker pattern with Feign
Retrying the connection with Ribbon
Hystrix's support for Feign
Summary


8.

Routing and Filtering with API Gateway
Using Spring Cloud Netflix Zuul
Building a gateway application
Integration with service discovery
Customizing route configuration
Ignoring registered services
Explicity set service name 
Route definition with the Ribbon client
Adding a prefix to the path
Connection settings and timeouts
Secure headers
Management endpoints
Providing Hystrix fallback

Zuul filters
Predefined filters
Custom implementations
Using Spring Cloud Gateway
Enable Spring Cloud Gateway for a project
Built-in predicates and filters
Gateway for microservices
Integration with service discovery
Summary


9.

Distributed Logging and Tracing
Best logging practices for microservices
Logging with Spring Boot
Centralizing logs with ELK Stack
Setting up ELK Stack on the machine
Integrating an application with ELK Stack
Using LogstashTCPAppender
Using AMQP appender and a message broker
Spring Cloud Sleuth
Integrating Sleuth with an application
Searching events using Kibana
Integrating Sleuth with Zipkin
Running the Zipkin server
Building the client application
Analyze data with the Zipkin UI
Integration via message broker
Summary



10.

Additional Configuration and Discovery Features
Using Spring Cloud Consul
Running Consul agent
Integration on the client side
Service discovery
Health check
Zones
Client settings customization
Running in clustered mode
Distributed configuration
Managing properties in Consul
Client customization
Watching configuration changes
Using Spring Cloud Zookeeper
Running Zookeeper
Service discovery
Client implementation
Zookeeper dependencies
Distributed configuration
Summary


11.

Message-Driven Microservices
Learning about Spring Cloud Stream

Building a messaging system
Enabling Spring Cloud Stream
Declaring and binding channels
Customizing connectivity with the RabbitMQ broker
Integration with other Spring Cloud projects
The publish/subscribe model
Running a sample system
Scaling and grouping
Running multiple instances
Consumer groups
Partitioning
Configuration options
Spring Cloud Stream properties
Binding properties
The consumer
The producer
The advanced programming model
Producing messages
Transformation
Consuming messages conditionally
Using Apache Kafka
Running Kafka
Customizing application settings
Kafka Streams API support
Configuration properties
Multiple binders
Summary


12.


Securing an API
Enabling HTTPS for Spring Boot
Secure discovery
Registering a secure application
Serving Eureka over HTTPS
Keystore generation
Configurating SSL for microservices and Eureka server
Secure configuration server
Encryption and decryption
Configuring authentication for a client and a server
Authorization with OAuth2
Introduction to OAuth2
Building an authorization server
Client configuration
Using the JDBC backend store
Inter-service authorization
Enabling SSO on the API gateway
Summary


×