Table of contents
- Preface
- 1. Microservices
- 1.What is microservice?
- 2. What RPC frameworks do you know
- What's the difference between Dubbo
- 4. What does SpringCloud consist of
- 2.Spring Cloud Eureka
- Contains several components
- How it works
- 3. Tell me what is Eureka’s self-protection mechanism
- 4. What is the CAP principle
- 5. They are all service registration centers. What is better about Eureka than Zookeeper?
- The difference between Eureka
- 3.Spring Cloud Ribbon
- The role of
- Principle
- The difference between nginx
- Four.Spring Cloud Feign
- The role of
- There are several ways to call interfaces
- The difference between Feign calling services
- 5.Spring Cloud Hystrix
- 1. Say what a service avalanche is
- What is a circuit breaker
- 3. What is service downgrade, service circuit breaker, service isolation
- 4. The difference between service downgrade and service circuit breaker
- 6. Spring Cloud Zuul and Spring Cloud Gateway
- 1. What is Zuul Microservice Gateway
- Application scenarios
- 7.Spring Cloud Config
- 1.What is Spring Cloud Config
- 8.Spring Cloud Alibaba Nacos
- What can be done?
- It is guaranteed to be an AP, so what is Nacos guaranteed? What is the default?
Preface
The latest java interview questions (java basics, collections, multithreading, jvm, locks, algorithms, CAS, Redis, databases, mybatis, spring, springMVC, springBoot, microservices)
1. Microservices
1.What is microservice?
Distributed, multiple modules, each module is a separate system.
2. What RPC frameworks do you know
RPC (Remote Procedure Call): Remote procedure call.
Dubbo:The earliest open source RPC framework in China was developed by Alibaba and opened to the public at the end of 2011.
Spring Cloud:Foreign companies' open source RPC framework in 2014.
What's the difference between Dubbo
① Different positioning:A one-stop solution under springCloud microservice architecture; Dubbo is mainly used for service call and governance.
②Different ecological environment:springCloud relies on the spring platform to be more perfect; Dubbo is relatively scarce.
③The call method is different:springCloud uses the Http protocol for remote calls, and the interface is generally in Rest style and is relatively flexible; Dubbo uses the Dubbo protocol, and the interface is generally in Java Service interface, with a fixed format.
Simply put:springCloud is a brand machine, and Dubbo is an assembly machine.
4. What does SpringCloud consist of
Spring Cloud Eureka:Service registration and discovery.
Spring Cloud Feign:Service interface call.
Spring Cloud Ribbon:Client load balancing.
Spring Cloud Hystrix:breaker.
Spring Cloud Zuul:Service gateway.
Spring Cloud Config:Distributed unified configuration management.
etc.
2.Spring Cloud Eureka
Contains several components
Eureka Client:Responsible for registering the information of this service into Eureka Server.
Eureka Server (server):The registry center has a registry that stores the machine and port numbers of each service.
How it works
principle:Other services in the system use Eureka's client to connect it to the Eureka server and keep their heartbeat so that staff can monitor whether each microservice is running normally through the Eureka server.
3. Tell me what is Eureka’s self-protection mechanism
If the Eureka server does not receive the heartbeat of a microservice within a certain period of time (default 90s), the Eureka server will enter self-protection mode. In this mode, the Eureka server will protect the information in the service registry and will not delete the data in the registry. When the network failure is restored, the Eureka server node will automatically exit self-protection mode.
4. What is the CAP principle
CAP Principles:Also known as CAP theorem, it refers to strong consistency, availability, and partition tolerance in a distributed system. The CAP principle means that these three elements can only achieve two points at most at the same time, and it is impossible to take into account both of them.
Strong consistency:When accessing all nodes, the data results are the same.
Availability:Ensure that every request will be responded regardless of success or failure.
Partiton tolerance:The loss or failure of any information in the system will not affect the continued operation of the system.
5. They are all service registration centers. What is better about Eureka than Zookeeper?
In distributed systems, partition fault tolerance must be guaranteed, so only A or C can be guaranteed, only AP and CP can be guaranteed.
During the use of the service, we can tolerate the registration center returning the registration information a few minutes ago, but we cannot accept that the service will be directly down and unavailable.
Zookeeper:What is guaranteed is CP. When the host node has a network failure, a new master node will be selected, and the response time will be too long.
Eureka:What is guaranteed is that APs and Eureka's nodes are equal, and there is no host and slaves. Therefore, Eureka can deal with the situation where some nodes lose contact due to network failures, and will not be paralyzed like Zookeeper.
The difference between Eureka
Common points
① Both support the registration and pull of services.
② Both support service providers to use heartbeat detection to determine whether they are healthy (temporary example).
Differences
①Nacos supports the registration center to actively ask the service provider's status (non-temporary instance).
②Nacos supports active push of registration center message changes.
③ If the heartbeat is abnormal, it will be eliminated (temporary example).
3.Spring Cloud Ribbon
The role of
The main function is to provide the client's software load balancing algorithm, which is the polling algorithm by default.
Principle
Ribbon will obtain information about the service from the registry and select a machine from it through a polling algorithm.
The difference between nginx
nginx:The reverse proxy implements load balancing, which is equivalent to making request forwarding from the nginx server.
Ribbon:Client load balancing is all client operations.
Four.Spring Cloud Feign
The role of
Feign integrates Ribbon, a declared web service client, which makes writing web service clients easier and remote calls easier.
There are several ways to call interfaces
Feign
RestTemplate
The difference between Feign calling services
Ribbon:We need to build the http request ourselves and then send it to other services through RestTemplate, which is quite cumbersome.
Feign:You don't need to build your own Http request, just call the interface directly.
5.Spring Cloud Hystrix
1. Say what a service avalanche is
Service avalanche: When multiple services call each other, A calls B, B calls C, C, D and so on, so if the intermediate call takes a long time and then A is called, then the resources will be consumed more and more, causing the system to crash.
What is a circuit breaker
A tool to prevent service avalanches, which has technologies such as service downgrade, service circuit breaking (@HystrixCommand(fallbackMethod = "hystrixById") //The method called failed), service isolation, monitoring, etc. to prevent avalanches.
3. What is service downgrade, service circuit breaker, service isolation
Service downgrade:When the request timeout or the resources are insufficient (thread or semaphore), the service will be downgraded, which means returning the result of the fallback method.
Service circuit breaker:It is a special downgrade when the failure rate (caused by network failure or timeout) reaches the threshold.
Service Quarantine:Open an independent thread for the isolated service, so that the service will not be affected under high concurrency. Generally, it is implemented using thread pool (and semaphore method).
4. The difference between service downgrade and service circuit breaker
Difference: Each request for downgrading will be sent, and the circuit breaker is not necessarily reached, and the failure rate will be reached, so the request will not be sent again. When a request error occurs, the return fallback data is the flashback data, while the flashback will not be accessed for a period of time.
for example:
①Downgrade: A adjusts B, sends 10 requests, and even if each request timed out, you will request B.
② Fuse breaking: A adjusts B, sends 10 requests, and the failure rate is set to 50%. If 5 requests fail, the failure rate reaches 50%, then the next 5 requests will not reach B.
6. Spring Cloud Zuul and Spring Cloud Gateway
1. What is Zuul Microservice Gateway
Receive all requests and forward different requests to different microservice modules.
Application scenarios
① Filter
②Permission authentication
③Downgrade current limit
④Safety
It has powerful functions, good performance, good maintenance, asynchronous implementation, and can replace Zuul gateway.
7.Spring Cloud Config
1.What is Spring Cloud Config
Centrally manage configuration files, and each service does not need to write configuration files. The service will pull configurations from the configuration center.
Real-time refresh (requires spring cloud bus).
8.Spring Cloud Alibaba Nacos
What can be done?
Registration Center and Configuration Center.
It is guaranteed to be an AP, so what is Nacos guaranteed? What is the default?
Nacos can be an AP or a CP. The default is AP