Reference books:
Spring Cloud Netflix: https://springcloud.ccIspring-cloud-netflix.html
Chinese API documents: Spring Cloud Dalston Chinese document reference manual Chinese version
SpringCloud Chinese website: Spring Cloud Chinese website - official document Chinese versionhttps://www.springcloud.cc/
catalogue
- 1. Getting started with spring cloud
- 3.Rest microservice construction
- 4.Eureka service registration and discovery
- 5.Ribbon load balancing (client based)
- 6.Feign load balancing
- 7.Hystrix circuit breaker, service fuse
- 8.Zuul routing gateway
preface
1.1 five common components of spring cloud
- Service discovery - Netflix Eureka
- Customer service end load balancing Netflix Ribbon
- Server load balancing: Feign
- Circuit breaker - Netflix Hystrix
- Service gateway - Netflix Zuul
- Distributed configuration - Spring Cloud Config
1.2 common interview questions
-
1. What is micro service?
-
2. How do microservices communicate independently?
-
3. What are the differences between spring cloud and Dubbo?
-
4. SpringBoot and SpringCloud, please talk about your understanding of them
-
5. What is service? What is service degradation
-
6. What are the advantages and disadvantages of microservices? Tell me about the pitfalls you encountered in project development
-
7. What do you know about the microservice technology stack? Please list one or two
-
8. eureka and zookeeper can both provide the functions of service registration and discovery. Please tell us the difference between the two?
Getting started with spring cloud
-
1. What is spring cloud
- SpringCloud provides a set of microservice solutions based on SpringBoot, including service registration and discovery, configuration center and full link monitoring
Control, service gateway, load balancing, fuse and other components. In addition to the highly abstract packaging of open-source components based on NetFlix, there are also some selection neutral open-source components. - Taking advantage of the development convenience of SpringBoot, SpringCloud cleverly simplifies the development of distributed system infrastructure. SpringCloud provides developers with some tools to quickly build distributed systems, including configuration management, service discovery, circuit breaker, routing, micro agent, event bus, global lock, decision campaign, distributed session, etc, They can all start and deploy with one click with the development style of SpringBoot.
- SpringBoot does not make wheels repeatedly. It just combines the service frameworks developed by various companies that are relatively mature and can withstand the actual postgraduate entrance examination, and repackages them through the SpringBoot style, shielding out the complex configuration and implementation principles, and finally leaving a set for developers
Easy to understand, easy to deploy and easy to maintain distributed system development kit - SpringCloud is a one-stop solution under the distributed microservice architecture. It is a collection of landing technologies of various microservice architectures, commonly known as the full barrel of microservices.
2. Spring cloud version
The version number of this thing is a little special
Instead of naming the version number by numerical number, SpringCloud uses the name of London underground station, and corresponds to the version time order according to the alphabet. For example, the earliest real version is Angel, the second real version is Brixton, then Camden, Dalton \ Edgware, and the latest is Hoxton SR4 CURRENT GA general stable version.
3, Rest microservice construction
Note: when creating a microservice project, you must pay great attention to the problem of version conflict. The versions of springboot and springcloud must choose the version you want to match, otherwise it will be prone to various problems!!!
3.1 introduction
We will use a Dept Department module as a general case of microservice
The Consumer consumer (Client) calls the service provided by the Provider (Server) through REST.
Recall the previous knowledge of Spring, Spring MVC, MyBatis and so on...
Review of Maven's subcontracting module architecture
A simple Maven module structure is as follows:
App parent: a parent project (APP parent) aggregates many child projects (APP util \ app Dao \ app Web...)
|— pom.xml
|
|— app-core
||- pom.xml
|
|— app-web
||- pom.xml
A parent project has multiple sub modules
Spring cloud has three sub modules under its parent Project for the first time
- Springcloud API [encapsulated overall entity / interface / public configuration, etc.]
- springcloud-provider-dept-8001 [service provider]
- springcloud-consumer-dept-80 [service consumer]
3.2. Spring cloud version selection
Large Version Description
3.3 create parent project
Create a spring cloud for the Maven project of the parent project. Remember that packaging is a pom mode
It is mainly to define POM files and uniformly extract jar packages common to subsequent sub modules, which is similar to an abstract parent class
pom.xml
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.gz</groupId> <artifactId>springcloud</artifactId> <version>1.0-SNAPSHOT</version> <modules> <module>springcloud-api</module> <module>springcloud-provider-dept-8001</module> <module>springcloud-consumer-dept-80</module> <module>springcloud-eureka-7001</module> <module>springcloud-eureka-7002</module> <module>springcloud-eureka-7003</module> <module>springcloud-consumer-dept-Ribbon-80</module> </modules> <!--Packaging method--> <packaging>pom</packaging> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> <!--The dependent version can be modified later--> <junit.version>4.12</junit.version> <lombok.version>1.18.20</lombok.version> <log4j.version>1.2.17</log4j.version> </properties> <dependencyManagement> <dependencies> <!--springcloud Dependence of--> <!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-dependencies --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>Greenwich.SR1</version> <type>pom</type> <scope>import</scope> </dependency> <!--springboot Dependence of--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>2.1.4.RELEASE</version> <type>pom</type> <scope>import</scope> </dependency> <!--database--> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.47</version> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>1.2.1</version> </dependency> <!--SpringBoot starter--> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>2.1.4</version> </dependency> <!--The following are mainly used for logging and testing--> <!--junit--> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>${junit.version}</version> </dependency> <!--lombok--> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>${lombok.version}</version> </dependency> <!--log4j--> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>${log4j.version}</version> </dependency> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-core</artifactId> <version>1.2.5</version> </dependency> </dependencies> </dependencyManagement> </project>
The above is the pom file of the parent project. There are many sub modules under the parent project
3.4 create api public module to store some public entity classes
pom.xml
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <artifactId>springcloud</artifactId> <groupId>com.gz</groupId> <version>1.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>springcloud-api</artifactId> <!--Current Module Dependence on your own needs,If the version has been configured in the parent dependency, there is no need to write here--> <dependencies> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> </dependency> </dependencies> </project>
3.5 creating a provider module
1. Write POM and XML
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <artifactId>springcloud</artifactId> <groupId>com.gz</groupId> <version>1.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>springcloud-provider-dept-8001</artifactId> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka</artifactId> <version>1.4.6.RELEASE</version> </dependency> <!--actuator Improve monitoring information--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <!--We need to get the entity class--> <dependency> <groupId>com.gz</groupId> <artifactId>springcloud-api</artifactId> <version>1.0-SNAPSHOT</version> </dependency> <!--junit--> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> </dependency> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-core</artifactId> </dependency> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> </dependency> <!--test--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-test</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!--jetty--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jetty</artifactId> </dependency> <!--Hot deployment--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> </dependency> </dependencies> </project>
2. Configure application.yml
server: port: 8001 mybatis: type-aliases-package: com.gz.springcloud.pojo config-location: classpath:mybatis/mybatis-config.xml mapper-locations: classpath:mybatis/mapper/*.xml #spring configuration spring: application: name: springcloud-provider-dept datasource: type: com.alibaba.druid.pool.DruidDataSource driver-class-name: org.gjt.mm.mysql.Driver url: jdbc:mysql://localhost:3306/db01?useUnicode=true&characterEncoding=utf-8 username: root password: root
3. Create a new mybatis-config.xml file according to the configuration
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration> <settings> <!--Enable L2 cache--> <setting name="cacheEnabled" value="true"/> </settings> </configuration>
4. Prepare Department dao and corresponding mapper
5. Write the service interface and implementation class
package com.gz.springcloud; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.netflix.eureka.EnableEurekaClient; import org.springframework.context.annotation.Configuration; /** * Created with IntelliJ IDEA. * * @Author: Gao Zhan * @Date: 2021/08/31/20:27 * @Description: */ //Main startup class @SpringBootApplication @EnableEurekaClient //Automatically register in eureka after the server starts! @EnableDiscoveryClient //Service discovery public class DeptProvider_8001 { public static void main(String[] args) { SpringApplication.run(DeptProvider_8001.class,args); } }
6. Write the controller class to provide Rest services
package com.gz.springcloud.controller; import com.gz.springcloud.pojo.Dept; import com.gz.springcloud.service.DeptService; import org.apache.ibatis.logging.stdout.StdOutImpl; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.client.ServiceInstance; import org.springframework.cloud.client.discovery.DiscoveryClient; import org.springframework.web.bind.annotation.*; import javax.sound.midi.Soundbank; import java.util.List; /** * Created with IntelliJ IDEA. * * @Author: Gao Zhan * @Date: 2021/08/31/20:19 * @Description: */ //Provide restful services! @RestController public class DeptController { @Autowired private DeptService deptService; //Get some configuration information and get specific micro services! @Autowired private DiscoveryClient client; @PostMapping("/dept/add") public boolean addDept(Dept dept){ return deptService.addDept(dept); } @GetMapping("/dept/get/{id}") public Dept get(@PathVariable("id")Long id){ return deptService.queryById(id); } @GetMapping("/dept/list") public List<Dept> queryAll(){ return deptService.queryAll(); } }
7. Write the main startup class of DeptProvider
package com.gz.springcloud; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.netflix.eureka.EnableEurekaClient; import org.springframework.context.annotation.Configuration; /** * Created with IntelliJ IDEA. * * @Author: Gao Zhan * @Date: 2021/08/31/20:27 * @Description: */ //Main startup class @SpringBootApplication @EnableEurekaClient //Automatically register in eureka after the server starts! @EnableDiscoveryClient //Service discovery public class DeptProvider_8001 { public static void main(String[] args) { SpringApplication.run(DeptProvider_8001.class,args); } }
3.6 creating a consumer module
It's roughly the same as the above. See the code for details
1. Write POM and XML
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <artifactId>springcloud</artifactId> <groupId>com.gz</groupId> <version>1.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>springcloud-consumer-dept-80</artifactId> <!--Entity class+web--> <dependencies> <dependency> <groupId>com.gz</groupId> <artifactId>springcloud-api</artifactId> <version>1.0-SNAPSHOT</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!--Hot deployment--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-autoconfigure</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-autoconfigure</artifactId> </dependency> </dependencies> </project>
2. Configure configBean
package com.gz.springcloud.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.client.RestTemplate; /** * Created with IntelliJ IDEA. * * @Author: Gao Zhan * @Date: 2021/08/31/22:30 * @Description: */ @Configuration public class ConfigBean { //Configuration -- spring applicationContext.xml @Bean public RestTemplate getRestTemplate(){ return new RestTemplate(); } }
3. Write the controller class to provide Rest services
DeptConsumerController:
package com.gz.springcloud.controller; import com.gz.springcloud.pojo.Dept; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.client.RestTemplate; import java.util.List; /** * Created with IntelliJ IDEA. * * @Author: Gao Zhan * @Date: 2021/08/31/22:28 * @Description: */ @RestController public class DeptConsumerController { //Consumers should not exist in the service layer //RestTemplate.. for us to call directly! Register in spring //(url, entity: map, class < T > responsetype) @Autowired private RestTemplate restTemplate;//It provides a variety of convenient methods to access remote http services and a simple restful service template private static final String RES_URL_PREFIX="http://localhost:8001"; @RequestMapping("consumer/dept/add") public boolean add(Dept dept){ return restTemplate.postForObject(RES_URL_PREFIX+"/dept/add",dept,Boolean.class); } @RequestMapping("consumer/dept/get/{id}") public Dept get(@PathVariable("id") Long id){ return restTemplate.getForObject(RES_URL_PREFIX+"/dept/get/"+id,Dept.class); } @RequestMapping("consumer/dept/list") public List<Dept> list(){ return restTemplate.getForObject(RES_URL_PREFIX+"/dept/list",List.class); } }
4. Configure main startup class
package com.gz.springcloud; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; /** * Created with IntelliJ IDEA. * * @Author: Gao Zhan * @Date: 2021/08/31/22:47 * @Description: */ @SpringBootApplication public class DeptConsumer_80 { public static void main(String[] args) { SpringApplication.run(DeptConsumer_80.class,args); } }
Learn about RestTemplate:
4.2 principle explanation
Eureka's basic architecture:
CAP principle means that these three elements can only achieve two points at most, and it is impossible to give consideration to the three.
Eureka is a sub module of Netflix and one of the core modules. Eureka is a REST based service. It is used to locate services to realize cloud middle tier service discovery and failover. Service registration and discovery are very important for microservices. With service discovery and registration, you can access services only by using the service identifier without modifying the service invocation configuration file, The function is similar to Dubbo's registry, such as Zookeeper;
- RestTemplate provides a variety of convenient methods to access remote Http services. It is a simple and convenient restful service template class. It is a client template tool set provided by Spring to access restful services. Using RestTemplate to access restful interface is very simple, rough and mindless (url, requsetMap, ResponseBean.class). These three parameters represent the rest request address respectively, Request parameters, Http response conversion, and the object type to which the conversion is converted
4, Eureka service registration and discovery
4.1 what is Eureka
Eureka: how do you read it?
Netflix followed the AP principle when designing Eureka
CAP principle, also known as CAP theorem, refers to in a distributed system - Consistency
- Availability
- Partition tolerance
-
SpringCloud The Eureka module developed by NetFlix company is encapsulated to realize service registration and discovery
-
Eureka adopts the C-S architecture design. Eureka server is the server of service registration function. It is the service registration center
- Other micro services in the system. A client using Eureka connects to Eureka server and maintains a heartbeat connection. In this way, the system maintenance personnel can monitor the normal operation of each micro service in the system through EurekaServer, and some other modules of spring cloud (such as Zuul) can discover other micro services in the system through EurekaServer and execute relevant logic;
Eureka consists of two components: Eureka Server and Eureka Client .
Eureka Server Service registration service is provided. After each node is started, it will be registered in EurekaServer. In this way, the service registry in EurekaServer will store the information of all available service nodes, and the information of service nodes can be seen intuitively in the interface.
Eureka Client is a Java client, which is used to simplify the interaction of Eureka Server. The client also has a built-in load balancer using polling load algorithm. After the application starts, a heartbeat will be sent to EurekaServer (the default cycle is 30 seconds). If Eureka Server does not receive the heartbeat of a node in multiple heartbeat cycles, Eureka Server will remove the service node from the service registry (the default cycle is 90 seconds)
Three roles
- Eureka Server: the service provided is registered at discovery.
- Service Provider: registers its own service in Eureka so that consumers can find it.
- Service Consumer: the Service Consumer obtains the registered service list from Eureka to find the consumer service.
4.3 service construction
1. Erueka server server
- Establish springcloud-eureka-7001 module
- Edit pom.xml
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <artifactId>springcloud</artifactId> <groupId>com.gz</groupId> <version>1.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>springcloud-eureka-7001</artifactId> <!--Guide Package--> <dependencies> <!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-eureka-server --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies> </project>
- application.yml
server: port: 7001 #Eureka configuration eureka: instance: hostname: eureka7001.com #Instance name of Eureka server client: register-with-eureka: false #Indicates whether to register yourself with the eureka registry fetch-registry: false #If fetch registry is false, it indicates that it is the registry service-url: #Monitoring page #stand-alone # defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/ # Setting the address query service and registration service interacting with Eureka Server need to rely on this defaultZone address # http://localhost:7001/eureka/ #Cluster (Association) defaultZone: http://eureka7002.com:7002/eureka/,http://eureka7003.com:7003/eureka/
Write the main startup class
package com.gz.springcloud; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; /** * Created with IntelliJ IDEA. * * @Author: Gao Zhan * @Date: 2021/08/31/23:46 * @Description: */ @SpringBootApplication @EnableEurekaServer //The startup class of EnableEurekaServer server can accept others to register public class EurekaServer_7001 { public static void main(String[] args) { SpringApplication.run(EurekaServer_7001.class,args); } }
Start, access test:
- System Status: system information
- DS Replicas: server replicas
- Instances currently registered with Eureka: list of registered microservices
- General Info: general information
- Instance Info: instance information
2. Erueka client client
Modify the previously created springcloud-provider-dept-8001 module
- Import Eureka dependencies
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka</artifactId> <version>1.4.6.RELEASE</version> </dependency>
2. eureka support is added in application.yml
#Eureka configuration, where to register eureka: client: service-url: defaultZone: http://localhost:7001/eureka/ instance: instance-id: springcloud-provider-dept-8001 #Modify the default description information on erueka
3. Add comments to the main startup class
@SpringBootApplication @EnableEurekaClient //After the service is started, it is automatically registered in eureka public class DeptProvider8001 { public static void main(String[] args) { SpringApplication.run(DeptProvider8001.class,args); } }
First start the 7001 server, then start the 8001 client for testing, and then access the monitoring page http://localhost:7001/ The production results are shown in the figure. It is successful
Actor and the improvement of registered micro service information
Modify application.yml in springcloud-provider-dept-8001 module
#Eureka's configuration, where is the service registered eureka: client: service-url: defaultZone: http://eureka7001.com:7001/eureka/ instance: instance-id: springclout-provider-dept8001 #Modify the default description information on eureka! #info configure default information (useless) info: app.name: gz-springcloud company.name: blog.gz.com
Restart 8001, refresh
If springcloud-provider-dept-8001 is stopped at this time, the monitoring will start the protection mechanism after 30s:
Configure monitoring information about service loading
Add dependency in pom.xml
<!--actuator Improve monitoring information--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>
Add configuration in application.yml
- #info configuration
- info:
- app.name: hejinjie-springcloud
- company.name: Fuyang Normal University - Planning and Information Institute
Click hereThe jump page is as follows
Eureka's self-protection mechanism
Self protection mechanism: living is better than dying
One sentence summary: when a micro service is unavailable at a certain time, eureka will not clean it immediately, but will still save the information of the micro service!
-
By default, if EurekaServer does not receive the heartbeat of a micro service instance within a certain period of time, EurekaServer will log off the instance (90 seconds by default). However, when the network partition fails, the microservice and Eureka cannot pass normally, and the above behavior may become very dangerous - because the microservice itself is actually healthy, and the service should not be cancelled at this time. Eureka solves this problem through self-protection mechanism - when Eureka server node loses too many clients in a short time (network partition failure may occur), the node will enter self-protection mode. Once in this mode, EurekaServer will protect the information in the service registry and will no longer delete the data in the service registry (that is, it will not log off any microservices). When the network fault recovers, the EurekaServer node will automatically exit the self-protection mode.
-
In self-protection mode, EurekaServer will protect the information in the service registry and will not unregister any service instances. When the number of heartbeats it receives recovers above the threshold, the EurekaServer node will automatically exit the self-protection mode. Its design philosophy is to retain the wrong service registration information rather than blindly cancel any possible healthy service instances. In a word: it's better to live than to die.
-
To sum up, self-protection mode is a security protection measure to deal with network abnormalities. Its architectural philosophy is that it would rather retain all micro services at the same time (both healthy and unhealthy micro services will be retained) than blindly cancel any healthy micro services. Using self-protection mode can make Eureka cluster more robust and stable. In spring cloud, you can use eureka.server.enable-self-preservation = false Disable self-protection mode [it is not recommended to turn off self-protection mechanism]
springcloud-provider-dept-8001 service Discovery (commonly used by team development)
For microservices registered in eureka, the service information can be obtained through service discovery. [external exposure services]
Modify the DeptController in the springcloud-provider-dept-8001 project
Add a new method
//Register the micro service and get some messages~ @GetMapping("dept/discovery") public Object discovery(){ //Get micro service list List<String> services = client.getServices(); System.out.println("discovery=>services:"+services); //Get a specific microservice information through the specific microservice id,applicationName; List<ServiceInstance> instances=client.getInstances("SPRINGCLOUD-PROVIDER-DEPT"); for (ServiceInstance instance:instances){ System.out.println( instance.getHost()+"\t"+ instance.getPort()+"\t"+ instance.getUri()+"\t"+ instance.getServiceId() ); } return this.client; }
Add a comment to the main startup class
package com.gz.springcloud; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.netflix.eureka.EnableEurekaClient; import org.springframework.context.annotation.Configuration; /** * Created with IntelliJ IDEA. * * @Author: Gao Zhan * @Date: 2021/08/31/20:27 * @Description: */ //Main startup class @SpringBootApplication @EnableEurekaClient //Automatically register in eureka after the server starts! @EnableDiscoveryClient //Service discovery public class DeptProvider_8001 { public static void main(String[] args) { SpringApplication.run(DeptProvider_8001.class,args); } }
Start Eureka service, start 8001 provider
Access test http://localhost:8001/dept/discovery
consumer access service
springcloud-consumer-dept-80
Modify DeptConsumerController and add a method
- @GetMapping("/consumer/dept/discovery")
- public Object discovery(){
- return
- restTemplate.getForObject(REST_URL_PREFIX+"/dept/discovery",Object.class);
- }
Start 80, access http://localhost/consumer/dept/discovery
4.4 Eureka: cluster environment configuration
- New projects springcloud-eureka-7002 and springcloud-eureka-7003
- Paste POM for template according to 7001
- Modify the main startup class of 7002 and 7003
- Modify the mapping configuration, windows domain name mapping
At the end of the hosts file, add the local name to access. The default is localhost
Modify the yaml folder of 3 eurekaservers
Associate springcloud-eureka-7001 with springcloud-eureka-7002 and springcloud-eureka-7003 in the cluster
7001
- server:
- port: 7001
- #Eureka configuration
- eureka:
- instance:
- Hostname: instance name of eureka7001.com #eureka server
- client:
- Register with eureka: false # indicates whether you want to register yourself in the eureka registry
- Fetch registry: false # if it is false, it means you are the registry. Just wait for others to connect
- Service URL: # monitoring page
- #Stand alone
- # defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
- #Setting the address query service and registration service interacting with Eureka Server need to rely on this defaultZone address
- # http://localhost:7001/eureka/
- #Cluster (Association)
- defaultZone: http://eureka7002.com:7002/eureka/,http://eureka7003.com:7003/eureka/
70027003 similar to above
Publish the 8001 microservice to one eureka cluster configuration. It is found that other registries in the cluster can also see it, but we usually
To be on the safe side, release it all!
Modify Eureka configuration through the yml configuration file under springcloud-provider-dept-8001: configure the service registry address
- #Eureka configuration, where to register
- eureka:
- client:
- service-url:
- #defaultZone: http://localhost:7001/eureka/
- defaultZone: http://eureka7001.com:7001/eureka/,http://eureka7002.com:7002/eureka/,http://eureka7003.com:7003/eureka/
- instance:
- Instance ID: springcloud-provider-dept-8001 # modify the default description information on erueka
Start cluster test
visit http://eureka7001.com:7001/
This is the simulation cluster. One project is mounted on three servers.
4.5 comparison and Zookeeper differences - important
1. Review CAP principles
RDBMS (Mysql,Oracle,sqlServer)===>ACID
NoSQL(redis,mongdb)===> CAP
2. What is acid?
- A (Atomicity)
- C (Consistency)
- I (Isolation)
- D (Durability)
3. What is cap?
- C (Consistency) strong Consistency
- A (Availability)
- P (Partition tolerance)
Three in two of CAP: CA, AP, CP
The core of CAP theory
A distributed system cannot meet the three requirements of consistency, availability and partition fault tolerance at the same time
According to CAP principle, NoSQL database is divided into three categories: meeting CA principle, meeting CP principle and meeting AP principle:
- CA: single point cluster. Systems that meet consistency and availability usually have poor scalability
- CP: a system that meets consistency and partition fault tolerance. Generally, the performance is not particularly high
- AP: a system that meets the requirements of availability and partition fault tolerance, and may generally have lower requirements for consistency
As a service registry, what's better about Eureka than Zookeeper?
The famous CAP theory points out that A distributed system cannot satisfy C (consistency), A (availability) and P (fault tolerance) at the same time.
Since partition fault tolerance P must be guaranteed in distributed systems, we can only trade off between A and C.
- Zookeeper guarantees CP;
- Eureka guarantees AP;
Zookeeper guarantees CP
When querying the service list from the registry, we can tolerate that the registry returns the registration information a few minutes ago, but we cannot accept that the service is directly down and unavailable. In other words, the service registration function requires higher availability than consistency. However zk, when the master node loses contact with other nodes due to network failure, the remaining nodes will be re elected as leaders. The problem is that the election leader takes too long, 30~120s, and the whole zk cluster is unavailable during the election, which leads to the paralysis of the registration service during the election. In the cloud deployment environment, the zk cluster loses the master node due to network problems. Although the service can be restored eventually, the long-term unavailability of registration caused by a long election time cannot be tolerated.
Eureka guarantees AP
Eureka understands this, so it gives priority to ensuring availability in design. Eureka's nodes are equal. The failure of several nodes will not affect the work of normal nodes, and the remaining nodes can still provide registration and query services. When registering with an Eureka client, if it finds that the connection fails, it will automatically switch to other nodes. As long as one Eureka is still there, the availability of the registration service can be maintained, but the information found may not be up-to-date. In addition, Eureka also has a self-protection mechanism. If more than 85% of the nodes do not have a normal heartbeat within 15 minutes, Eureka thinks that there is a network failure between the client and the registry. At this time, the following situations will occur:
-
- Eureka no longer removes services that should expire because they haven't received a heartbeat for a long time from the registration list
-
- Eureka can still accept the registration and query requests for new services, but it will not be synchronized to other nodes (that is, ensure that the current node is still available)
-
- When the network is stable, the new registration information of the current instance will be synchronized to other nodes
Therefore, Eureka can deal with the loss of contact of some nodes due to network failure without paralyzing the whole registration service like zookeeper
5, Ribbon load balancing (client based)
5.1 ribbon overview
What is Ribbon?
Spring Cloud Ribbon is a set of client-side load balancing tools based on Netflix Ribbon.
In short, Ribbon is an open source project released by Netflix. Its main function is to provide software load balancing algorithms for clients and connect Netflix's middle tier services together. The Ribbon client component provides a series of complete configuration items, such as connection timeout, Retry, and so on. Simply put, list all the machines behind the LoadBalancer (LB: load balancer for short) in the configuration file. The Ribbon will automatically help you connect these machines based on certain rules (such as simple polling, random connection, etc.). We can also easily use Ribbon to implement a custom load balancing algorithm!
What can Ribbon do?
LB, Load Balance, is an application often used in microservices or distributed clusters.
Load balancing simply means that users' requests are evenly distributed to multiple services, so as to achieve the HA (high availability) of the system. Common load balancing software include Nginx, Lvs and so on
Both Dubbo and spring cloud provide us with load balancing. Spring cloud's load balancing algorithm can customize the simple classification of load balancing:
- Centralized LB
- That is, independent LB facilities are used between consumers and providers of services
- Like Nginx, the facility is responsible for forwarding the access request to the service provider through some policy!
- Advance program LB
- Integrate LB logic into the consumer. The consumer knows which addresses are available from the service registry, and then selects an appropriate server from these addresses.
- Ribbon belongs to in-process LB. it is just a class library integrated into the consumer process. The consumer obtains the address of the service provider through it!
github address of Ribbon: GitHub - Netflix/ribbon: Ribbon is a Inter Process Communication (remote procedure calls) library with built in software load balancers. The primary usage model involves REST calls with various serialization scheme support.
5.2 Ribbon load balancing
Preliminary configuration of Ribbon
1. Copy the springcloud-consumer-dept-ribbon-80 project
2. Modify pom.xml and add Ribbon related configuration
<!--integrate Ribbon--> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-ribbon</artifactId> <version>1.4.6.RELEASE</version> </dependency> <!--eureka--> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka</artifactId> <version>1.4.6.RELEASE</version> </dependency>
3. Modify application.yml and add Eureka's service registration address
server: port: 80 # eureka configuration eureka: client: register-with-eureka: false #Do not register yourself with eureka service-url: defaultZone: http://eureka7001.com:7001/eureka/,http://eureka7002.com:7002/eureka/,http://eureka7003.com:7003/eureka/
4. Annotate the ConfigBean method inside @LoadBalanced When you get Rest, add the Ribbon configuration and start the Ribbon
package com.gz.springcloud.config; import org.springframework.cloud.client.loadbalancer.LoadBalanced; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.client.RestTemplate; /** * Created with IntelliJ IDEA. * * @Author: Gao Zhan * @Date: 2021/08/31/22:30 * @Description: */ @Configuration public class ConfigBean { //Configuration -- spring applicationContext.xml //Configure load balancing to implement RestTemplate @Bean //It was < bean > < / bean >, which was injected into Spring @LoadBalanced //Configure load balancing to implement RestTemplate public RestTemplate getRestTemplate(){ return new RestTemplate(); } }
5. Add main startup class @EnableEurekaClient , open Eureka client
package com.gz.springcloud; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.netflix.eureka.EnableEurekaClient; /** * Created with IntelliJ IDEA. * * @Author: Gao Zhan * @Date: 2021/08/31/22:47 * @Description: */ @SpringBootApplication @EnableEurekaClient //Open Eureka client public class DeptConsumer_ribbon_80 { public static void main(String[] args) { SpringApplication.run(DeptConsumer_ribbon_80.class,args); } }
6. Modify the DeptConsumerController client access class. The previously written address is dead and needs to be changed now!
package com.gz.springcloud.controller; import com.gz.springcloud.pojo.Dept; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.client.RestTemplate; import java.util.List; /** * Created with IntelliJ IDEA. * * @Author: Gao Zhan * @Date: 2021/08/31/22:28 * @Description: */ @RestController public class DeptConsumerController { //Consumers should not exist in the service layer //RestTemplate.. for us to call directly! Register in spring //(url, entity: map, class < T > responsetype) @Autowired private RestTemplate restTemplate;//It provides a variety of convenient methods to access remote http services and a simple restful service template //Through the Ribbon, this should be a variable accessed through the service name //private static final String RES_URL_PREFIX="http://localhost:8001"; private static final String RES_URL_PREFIX="http://SPRINGCLOUD-PROVIDER-DEPT"; @RequestMapping("consumer/dept/add") public boolean add(Dept dept){ return restTemplate.postForObject(RES_URL_PREFIX+"/dept/add",dept,Boolean.class); } @RequestMapping("consumer/dept/get/{id}") public Dept get(@PathVariable("id") Long id){ return restTemplate.getForObject(RES_URL_PREFIX+"/dept/get/"+id,Dept.class); } @RequestMapping("consumer/dept/list") public List<Dept> list(){ return restTemplate.getForObject(RES_URL_PREFIX+"/dept/list",List.class); } }
7. Start three Eureka clusters first. After starting springcloud-provider-dept-8001, register with Eureka and start springcloud-consumer-dept-ribbon-80
test
http://localhost/consumer/dept/list
Summary: after the integration of Ribbon and Eureka, the client can call directly without caring about the port number and ip address
Ribbon load balancing
Architecture diagram:
Ribbon doesn't have to register himself with Eureka. The figure above is wrong
Ribbon works in two steps
-
The first step is to select Eureka Server, which gives priority to servers with less load balancing in the same region.
-
The second step is to select an address in the service registration list from the server according to the policy specified by the user.
Among them, Ribbon provides a variety of strategies, such as polling (default), random and weighted according to response time,,, and so on
1. Refer to springcloud-provider-dept-8001 and create two new copies, 80028003 respectively!
2. Modify the port number
3. Create a new 8002 / 8003 database, connect their own microservices to their own databases, and copy DB1!
4. Modify their Yml files
-
port
-
Database connection
- The instance name also needs to be changed
- instance:
- Instance ID: springcloud provider dept-8002 # modify the default description information on erueka
- Unified instance names for external exposure must be consistent
- #Spring configuration
- spring:
- application:
- name: springcloud-provider-dept
test
Start three Eureka clusters, three provider microservices and consumer services
After passing all three tests
http://localhost:8001/dept/list
http://localhost:8002/dept/list
http://localhost:8003/dept/list
Retest
http://localhost/consumer/dept/list
Refresh several times and observe the results
Each access is a service provider in the cluster. This situation is called polling. The polling algorithm can also be customized
How to customize the polling algorithm
Ribbon core component IRule
IRule: select a service to access from the service list according to a specific algorithm!
- Roundrobin rule [polling]
- RandomRule [random]
- Availability filterrule [first filter out the services in circuit breaker tripping due to multiple access faults and the services with concurrent connections exceeding the threshold, and then access the remaining service list according to the polling strategy]
- WeightedResponseTimeRule [calculate the weight of all services according to the average response time. The faster the response time, the greater the service weight, and the higher the probability of being selected. If the statistical information is insufficient at the beginning of startup, use the roundrobin rule strategy. Wait until the statistical information is sufficient, and switch to WeightedResponseTimeRule]
- RetryRule [first obtain the service according to the roundrobin rule policy. If the service acquisition fails, it will retry within the specified time to obtain the available service]
- BestAvailableRule [first filter out the services in the circuit breaker tripping state due to multiple access faults, and then select a service with the least concurrency]
- ZoneAvoidanceRule [default rule, which is used to judge the performance of the region where the server is located and the availability of the server, and select the server]
View analysis source code:
- IRule
- ILoadBalancer
- AbstractLoadBalancer
- AbstractLoadBalancerRule: this abstract parent class is very important! core
- RoundRobinRule
Omit....
Switch to the implementation of random policy and add a method in ConfigBean
public IRule myRule(){ //Use our re selected random algorithm to replace the default polling! return new RandomRule(); }
6, Feign load balancing
6.1 Feign overview
feign is a declarative web service client, which makes it easier to call between microservices, similar to the controller calling a service.
Spring Cloud integrates Ribbon and Eureka to provide a load balanced http client when using Feign.
Just create an interface and add annotations!
feign, mainly the community, is used to interface oriented programming. This is the norm for many developers. There are two methods for invoking microservice access
-
- Microservice name [ribbon]
-
- Interface and notes [feign]
What can Feign do?
-
Feign aims to make it easier to write Java Http clients
-
Previously, when using Ribbon + RestTemplate, the RestTemplate is used to encapsulate Http requests to form a set of templated calling methods. However, in the actual development, because there may be more than one invocation of service dependencies, and often one interface will be invoked in multiple places, some client classes are usually encapsulated for each micro service to wrap the invocation of these dependent services. Therefore, Feign makes further encapsulation on this basis and helps us define and implement the definition of dependent service interface. Under the implementation of Feign, we only need to create an interface and configure it by annotation (similar to the Mapper annotation on Dao interface in the past, now it is a micro service interface, and a Feign annotation can be marked on it.) The interface binding to the service provider can be completed, which simplifies the development of automatically encapsulating the service call client when using the Spring Cloud Ribbon.
Feign integrates Ribbon
- The Ribbon is used to maintain the service list information of springcloud dept, and the load balancing of the client is realized through polling. Different from the Ribbon, Feign only needs to define the service binding interface and implement the service call in a declarative way, which is elegant and simple.
6.2 feign use steps
1. Refer to springcloud-consumer-dept-ribbon-80
2. Create a new springcloud-consumer-dept-feign-80
- Modify the name of the main startup class
- Copy the contents of spring cloud-consumer-dept-80 to the feign project
- Delete myrule folder
- Modify the name of the main startup class to DeptConsumerFeign80
3. springcloud-consumer-dept-feign-80 modify pom.xml and add Feign support.
<!--Feign relevant--> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-feign</artifactId> <version>1.4.6.RELEASE</version> </dependency>
4. Modify the spring cloud API project
- pom.xml adds feign support
- Create a new Service package
- Write the interface DeptClientService and add new annotations @FeignClient.
@Service //Inject into Spring for easy calling //Microservice client annotation, value: specify the name of the microservice, so that Feign client can directly find the corresponding microservice @FeignClient(value = "springcloud-provider-dept") public interface DeptClineService { @PostMapping("/dept/add") public boolean addDept(Dept dept); @GetMapping("/dept/get/{id}") public Dept queryById(Long deptno); @GetMapping("/dept/list") public List<Dept> queryAll(); }
5. Modify springcloud consumer dept feign
@RestController public class DeptCounsumerController { /** * Understanding: consumers should not have a service layer * RestTemplate....We can call it directly and register it in spring * (url,Entity: map, class < T > responsetype) * It provides a variety of convenient methods to access remote http services and a simple Restful service template * */ @Autowired private RestTemplate restTemplate; @Autowired DeptClineService service=null; /** * Service provider prefix * Through the Ribbon, this should be a variable accessed through the service name * */ private static final String REST_URL_PREFIX="http://springcloud-provider-dept"; // private static final String REST_URL_PREFIX="http://localhost:8001"; @RequestMapping("/consumer/dept/get/{id}") public Dept queryById(@PathVariable("id") Long id){ return this.service.queryById(id); } @RequestMapping("/consumer/dept/list") public List<Dept> queryAll(){ return this.service.queryAll(); } @RequestMapping("/consumer/dept/add") public boolean addDept(Dept dept){ return this.service.addDept(dept); } }
6. Modify the main startup class DeptConsumerFeign and add a comment
package com.gz.springcloud; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.netflix.eureka.EnableEurekaClient; import org.springframework.cloud.openfeign.EnableFeignClients; import org.springframework.context.annotation.ComponentScan; /** * Created with IntelliJ IDEA. * * @Author: Gao Zhan * @Date: 2021/08/31/22:47 * @Description: */ @SpringBootApplication @EnableEurekaClient //Open Eureka client @EnableFeignClients(basePackages = {"com.gz.springcloud"}) public class DeptConsumer_feign{ public static void main(String[] args) { SpringApplication.run(DeptConsumer_feign.class,args); } }
test
http://localhost/consumer/dept/list
Result: Feign has its own load balancing configuration item
Summary
Feign calls the Rest service through the method of the interface (previously Ribbon+RestTemplate)
The request is sent to Eureka server( http://MICROSERVICECLOUD-PROVIDER-DEPT/dept/list)
Find the service interface directly through Feign. Because the Ribbon technology is integrated during service invocation, it also supports load balancing!
Feign doesn't actually do load balancing. Load balancing is the function of ribbon. Feign only integrates ribbon, but the function of load balancing is to do it again with feign's built-in ribbon, not feign.
feign is an alternative to RestTemplate. Its performance is low, but it can make the code readable.
Comparison between Feign and Ribbon
Ribbon: ribbon is a load balancer based on http and TCP clients. It can configure the ribbon server list on the client Then, poll the request to achieve load balancing. When it is used in conjunction with Eureka, the ribbonServerList will be rewritten by DiscoveryEnabledNIWSServerList and expanded to obtain the server list from Eureka registry. At the same time, it will also replace IPing with NIWSDiscoveryPing, which delegates the responsibility to Eureka to determine whether the server has been started. Use HttpClient or RestTemplate Simulating http requests is quite tedious.
Usage:
1.RestTemplate is injected into the container, @LoadBalanced The annotation uses the default load balancing algorithm (you can use custom)
2. Use REST_URL_PREFIX Specify the request address and use restTemplate to simulate http requests. @RestController
Feign : It is an improvement based on the Ribbon. It is an http client that is more convenient to use. In the way of interface, you only need to create an interface and face the interface; then add comments on it, and define the methods of other services to be called as abstract methods, without building http requests. Then it is like calling your own project It is very easy to write the client, which is similar to mybatis @Mapper Notes.
7, Hystrix circuit breaker, service blown
What is Hystrix?
Hystrix is an open source library for dealing with delay and fault tolerance of distributed systems. In distributed systems, many dependencies inevitably fail to call, such as timeout, exception, etc. hystrix can ensure that when a dependency fails, it will not lead to overall service failure, avoid cascading failures, and improve the elasticity of distributed systems.
"Circuit breaker" itself is a kind of switching device. When a service unit fails, it returns a service expected and processable alternative response (FallBack) to the caller through the fault monitoring of the circuit breaker (similar to fusing fuse) Instead of waiting for a long time or throwing an exception that cannot be handled by the calling method, this can ensure that the thread of the service caller will not be occupied unnecessarily for a long time, so as to avoid the spread and even avalanche of faults in the distributed system
Service fuse
1. What is service?
Fusing mechanism is a microservice link protection mechanism corresponding to avalanche effect.
When a microservice on the fan out link is unavailable or the response time is too long, the service will be degraded, which will fuse the microservice call of the node and quickly return the wrong response information. When it is detected that the microservice call response of the node is normal, the call link will be restored. In the spring cloud framework, the fuse mechanism is implemented through hystrix. Hystrix will monitor the status of calls between microservices In addition, when the failed call reaches a certain threshold, the default is 20 calls in 5 seconds, and the fuse mechanism will be started if the call fails.
The annotation of the fuse mechanism is @HystrixCommand.
Problems that service can solve:
- When the dependent object is unstable, it can achieve the purpose of rapid failure;
- After rapid failure, it can dynamically try according to a certain algorithm
2. Service degradation
-
What is service degradation?
-
The overall resources are not enough. We have to close some services first, and then open them back after we get through the difficulties
Service degradation means that when the pressure on the server increases sharply, some services and pages are not handled strategically or handled in a simple way according to the actual business conditions and traffic, so as to release server resources to ensure the normal or efficient operation of core business. In other words, it is to give system resources to services with high priority as much as possible.
Resources are limited, but requests are unlimited. If you do not downgrade services during the concurrent peak period, on the one hand, it will certainly affect the performance of the overall service. If it is serious, it may lead to downtime and unavailability of some important services. Therefore, in order to ensure the availability of core function services, some services should be downgraded during the peak period. For example, when double 11 is active, the All services irrelevant to the transaction are degraded, such as viewing ant deep forest, viewing historical orders, etc.
What are the main scenarios for service degradation? When the overall load of the whole micro service architecture exceeds the preset upper threshold or the upcoming traffic is expected to exceed the preset threshold, in order to ensure the normal operation of important or basic services, some unimportant or non urgent services or tasks can be delayed or suspended.
The degradation method can be based on the business, and the service can be delayed. For example, the delay will increase the points for the user, but it will be put into a cache and executed after the service is stable; Or close the service within the granularity, such as the recommendation of relevant articles.
Whether the dependent object is recovered.
3. Service monitoring hystrixDashboard
In addition to isolating the calls of dependent services, hystrix also provides a quasi real-time call monitoring (Hystrix Dashboard). Hystrix will continuously record the execution information of all requests initiated through hystrix and display it to users in the form of statistical reports and graphics, including how many requests are executed, how many successes, how many failures, etc.
Netflix monitors the above indicators through the hystrix metrics event stream project. Spring cloud also provides the integration of hystrix dashboard to transform the monitoring content into a visual interface!
8, Zuul routing gateway
Zull overview It mainly requests address hiding
1. What is Zull
Zuul includes two main functions: Request Routing and filtering:
The routing function is responsible for forwarding external requests to specific micro service instances, which is the basis for realizing the unified entrance of external access, while the filter function is responsible for intervening in the request processing process, which is the basis for realizing request verification, service aggregation and other functions. Zuul and Eureka integrate, register zuul as an application under Eureka service governance, and obtain messages of other micro services from Eureka, that is, future access to micro services is obtained through zuul jump.
Note: Zuul service will eventually register with Eureka
It provides three functions: agent + routing + filtering!
2. What can Zull do
- route
- filter