A confused program dog

This afternoon, a programmer friend asked me if I had ever used springCloud. I answered decisively: no. SpringCloud is said to be popular, so check it out.

One look at the Spring website made me blush up to my thighs. Eureka, Zuul, Hystrix, Feign, Ribbon, etc., are components of SpringCloud. I’ve been using these for months. I am stupid.

What is SpringCloud?

SpringCloud is a combination of those components and provides very complete support for microservices architecture. Here is an overview of some of the components.

  • Eureka: Service registration and discovery for service management.
  • Feign: Web call client that simplifies HTTP interface calls.
  • Ribbon: Client-based load balancing.
  • Hystrix: Fuse downgrading prevents service avalanches.
  • Zuul/Gateway: indicates the Gateway route, which provides route forwarding, request filtering, and traffic limiting degradation functions.
  • Config: configuration center for distributed configuration management.
  • Sleuth: service link tracing
  • Admin: Health management

So let’s expand it out.

Feign

There must be a connection between microservices. How do these services call each other? Cloud uses Feign to simplify HTTP interface calls. It just needs to be added before the interface being called

@ FeignClient (name = "service - the name")Copy the code

Ribbon

Is client-based load balancing, where each client node has a list of the server addresses it visits, which is retrieved from the service registry. When the Ribbon works with Eureka, the Ribbon automatically obtains the service provider address list from the Eureka Server and requests one service provider instance based on the load balancing algorithm. Ribbon Debt balancing can be calculated based on the Ribbon’s load balancing policies and principles

Zuul

Gateway routing, Zuul is essentially a filter that distributes external requests to other services via configured path addresses.

Eureka

Feign, Ribbon, Zuul are all based on the Eureka registry.

Hystrix

Little not call each other between micro services, each service is possible abnormal condition, once one of the service does not provide services (network service hang up and too much debt, etc.), can affect calls its service, produce a chain reaction, an avalanche effect (by the underlying service failure resulting in failure of league level), really is not a snowflake (service) is innocent. Just like the burning ships in red Cliff, not one of them could escape, resulting in the entire army being destroyed.

** Service unavailable Possible causes: **

  • Server Breakdown
  • Network fault
  • Abnormal program
  • Excessive load or overload

Hystrix is designed to tackle avalanches and isolate bad services without affecting other services. The function of the isolated service is replaced by another service, which is service degradation. Originally fan Bingbing, now can only use Sister Feng.

Its design is based on the bulkhead pattern:

The Bulkhead pattern isolates critical resources for each workload or service, such as connection pools, memory, and CPUS. The use of bulkheads avoids a scenario where a single workload (or service) consumes all resources, causing other services to fail. This pattern increases the resiliency of the system by preventing cascading failures caused by one service.Copy the code

Simply put, each request is set to a separate connection pool, the number of connections, does not affect the other corresponding, like a waterproof tank.

A service invokes two services a and B. If you call the a service and it times out. It takes up a lot of resources. Call B also fails. If you give call A a separate resource, call B will not be affected.

** Fault tolerance mechanism **

  1. Set a timeout for the network service
  2. Use circuit breaker mode, like a fuse in your home.
  • For error-prone agents. Check whether the request is normal or failed
  • Implementation of fast failure, if many similar errors are detected in a period of time, will force a direct return for the service fast failure in the future.
  • Automatically diagnose whether dependent services are restored. The request is rerequested at a later time, and if the service is restored, the request is resumed.

That’s self-healing.

So that’s a brief introduction. More on that later.