Introduction to Spring Cloud micro-service architecture

Source: Internet
Author: User
Tags representational state transfer svn using git

The recent reading of Li's Spring cloud and Docker has been very rewarding, taking a moment to summarize the contents of the book. Get a quick overview of what Spring cloud,spring Cloud's main features and spring cloud service governance are. The contents of the following blog are from this book.
What is Micro service

The MicroServices architecture style is a way to develop a single application into a small set of services, each running in its own process, with a lightweight communication mechanism (typically with an HTTP resource API) for inter-service communication. These services are built around business capabilities and can be deployed independently through a fully automated deployment mechanism. These services share one of the smallest centralized management services that can be developed in different languages using different data storage technologies.
MicroServices architectures should have the following features:

    • Each micro-service can run independently in its own process.

    • A series of independently running microservices to build the entire system together.

    • Each service is a standalone business development, and a microservices focus on a specific function, such as order management, user management, etc.

    • MicroServices communicate through a number of lightweight communication mechanisms, such as calls through RESTful APIs.

    • can use different languages and data storage technologies

    • Fully automated deployment mechanism

Benefits of MicroServices Architecture
Easy to develop and maintain

    • A microservices will only focus on a particular business function, so it has a clear business and a small amount of code.

A single micro-service starts faster

    • The number of individual microservices code is small, so the startup is faster.

Local modifications are easy to deploy

    • Single application as long as there are changes, you have to redeploy the entire application, microservices solve the problem.

The technology stack is not limited

    • In the micro-service architecture, the technology stack can be selected rationally, combining with the characteristics of the project business and the team.

On-demand scaling

    • Fine-grained scaling can be achieved on demand.

The challenges of the micro-service architecture
High requirements for operation and maintenance

    • More services means more operational inputs.

The inherent complexity of distribution

    • Using a microservices architecture is a distributed system. For a distributed system, system fault tolerance, network delay, distributed transactions and so on will bring great challenges.

High interface adjustment costs

    • The microservices communicate with each other through an interface. If you modify the API for a microservices, it is possible that all microservices that use the interface need to be adjusted.

Repetitive Labor

    • Many services may use the same functionality, which does not break down into a micro-service, which may be developed by each service, leading to duplication of code.

Micro-service Overall architecture diagram

Services registered in Discovery

When each service starts, it registers its own network address and other information into the service discovery component, and the service Discovery component stores the information.

The service consumer can query the service provider's network address from the service Discovery component and use that address to invoke the interface of the service provider.

Each microservices and Service discovery component uses certain mechanisms, such as heartbeat, to communicate. The service Discovery component logs off the instance if it cannot communicate with a service instance for a long time.

The service discovery component is re-registered when the Micro-service network address changes, such as when an instance increases or decreases, or if the IP port is changed. In this way, the service consumer is not required to manually modify the provider's network address.

Fegion Implementing declarative Rest calls
REST (representational state Transfer), translated in Chinese as "Representational status Transfer" (also: "Representational State transfer"). was a term presented in an academic paper by Roy Thomas Fielding during his 2000 study at the University of California, Irvine. REST defines a set of architectural principles that you can base on, including how clients written in different languages process and transport resource states over HTTP. Feign is a declarative webservice client. Using feign can make it easier to write WebService clients by defining an interface and then adding annotations on the interface, as well as supporting JAX-RS standard annotations. The feign also supports pluggable encoders and XXX. The Springcloud feign is encapsulated so that it supports SPRINGMVC standard annotations and httpmessageconverters. The feign can be used in combination with the Eureka and ribbon to support load balancing.

Using Hystrix to implement fault-tolerant processing of microservices
Hystrix is a latency and fault-tolerant library of Netflix open source for isolating access to remote systems, services, or third-party libraries to prevent cascading failures and thereby improve system availability and fault tolerance. Hystrix mainly through the following points to achieve delay and fault tolerance.
Parcel Request: Use the Hystrixcommand package for dependent invocation logic, where each command executes in a separate thread. This uses the "command mode" in design mode.

    • Tripping mechanism: When the error rate of a service exceeds a certain threshold, hystrix can automatically or manually trip and stop requesting the service for a period of time.
    • Resource isolation: Hystrix maintains a small thread pool (or semaphore) for each dependency. If the thread pool is full, requests destined for that dependency are immediately rejected instead of queued, speeding up the failure decision.
    • Monitoring: Hystrix can monitor running metrics and configuration changes in near real-time, such as successes, failures, timeouts, and rejected requests.
    • Fallback mechanism: The fallback logic is performed when the request fails, times out, is rejected, or when the breaker is open. Fallback logic can be provided by the developer itself, such as returning a default value.
    • Self-repair: The circuit breaker opens for a period of time and automatically enters the "half open" state.

If there is no fault-tolerant processing, the "Underlying service failure" causes cascading failures to create the right avalanche effect

Building a microservices gateway using Zuul
Zuul is the Netflix open source MicroServices gateway that works with components such as Eureka,ribbon,hystrix. The core of Zuul is a series of filters that can perform the following functions.

    • Identity authentication and security
    • Dynamic routing
    • Pressure test
    • Load distribution
    • Static response processing
    • Multi-Zone elasticity

Zuul Most of the functionality is implemented through filters, as shown in the figure on the right.

Unified management of MicroServices configuration using spring Cloudconfig
Spring Cloud Config supports versioning in git, svn and local storage, using Git or svn repositories, and spring's default configuration is to use a git repository. Has the following advantages:
Centralized management configuration: An application system that uses a microservices architecture may contain hundreds or thousands of microservices, so several management configurations are necessary.
Different configurations for different environments: for example, the data source configuration is different in different environments (development, testing, pre-release, production, etc.).
Dynamic adjustment during Runtime: for example, the data source connection pool size or the fuse threshold can be dynamically adjusted based on the workload of each microservices, and the configuration is not stopped when the microservices are adjusted.
The configuration changes are automatically updated. If the configuration changes, the microservices can automatically update the configuration.

Spring Cloud service Governance
Registration Center Monitoring

Fault-tolerant processing monitoring

Micro-service Health Check

Micro service call Tracking

Introduction to Spring Cloud micro-service architecture

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.