Springcloud common interview questions (2023 latest)

foreword

The latest java interview questions (java basics, collections, multithreading, jvm, locks, algorithms, CAS, Redis, databases, mybatis, spring, springMVC, springBoot, microservices)

1. Microservices

1. What are microservices?

Distributed, multiple modules, each module is a separate system.

2. Which RPC frameworks do you know

RPC (Remote Procedure Call): remote procedure call.
Dubbo: The earliest open source RPC framework in China, developed by Alibaba and open sourced at the end of 2011.
Spring Cloud: The RPC framework open sourced by foreign companies in 2014.

3. What is the difference between springCloud and Dubbo

①Different positioning: a one-stop solution under the springCloud microservice architecture; Dubbo is mainly used for service invocation and governance.
②The ecological environment is different: springCloud relies on the spring platform and is more complete; Dubbo is relatively scarce.
③Different calling methods: springCloud uses the Http protocol for remote calls, and the interface is generally in the Rest style, which is relatively flexible; Dubbo uses the Dubbo protocol, and the interface is generally a Java Service interface with a fixed format.
**Simply put:**s springCloud is a brand machine, and Dubbo is an assembly machine.

4. What does Spring Cloud consist of

Spring Cloud Eureka: service registration and discovery.
Spring Cloud Feign: Service interface call.
Spring Cloud Ribbon: Client load balancing.
Spring Cloud Hystrix: Circuit Breaker.
Spring Cloud Zuul: Service Gateway.
Spring Cloud Config: distributed unified configuration management.
etc.

二.Spring Cloud Eureka

1. Eureka contains several components

Eurake Client (client): Responsible for registering the information of this service with Eureka Server.
Eureka Server (server): registry center, which has a registry, which saves the machine and port number of each service.

2. The working principle of Eureka

Principle: Other services in the system use the Eureka client to connect to the Eureka server and keep the heartbeat, so that the staff can monitor whether each microservice is running normally through the Eureka server.

3. Talk about 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 the self-protection mode. In this mode, the Eureka server will protect the information in the service registry and will not delete the registration For the data in the table, when the network failure is restored, the Eureka server node will automatically exit the self-protection mode.

4. What is the CAP principle

CAP principle: Also known as CAP theorem, it refers to the strong consistency (Consistency), availability (Availability), and partition tolerance (Partition tolerance) in a distributed system. The CAP principle means that these three elements can only achieve at most two points at the same time, and it is impossible to take care of all three.
Strong consistency (Consistency): When visiting all nodes, the data results obtained are the same.
Availability (Availability): To ensure that each request has a response whether it succeeds or fails.
Partition tolerance (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. How is Eureka better than Zookeeper?

Partition fault tolerance must be guaranteed in a distributed system, so only A or C, only AP and CP can be guaranteed.
Zookeeper: The CP is guaranteed. It can tolerate the registration center returning the registration information a few minutes ago, but it cannot accept the service to be directly down and unavailable. When the network failure occurs on the host node, a new master node will be selected, and the response time is too long.
Eureka: What is guaranteed is that the APs, Eureka's nodes are all equal, and there is no host and slave, so Eureka can well deal with the situation that some nodes lose contact due to network failures, and will not paralyze the entire registration center like Zookeeper .

6. The difference between Nacos and Eureka

The common point
① all support the registration and pull of services.
②Both support service providers to use heartbeat detection to determine whether they are healthy (temporary instance).

Differences
① nacos supports the registration center to actively ask the status of the service provider (not a temporary instance).
② nacos supports active push of registration center message changes.
③ Abnormal heartbeat will be removed (temporary instance).

三.Spring Cloud Ribbon

1. The role of Ribbon

The main function is to provide the client software load balancing algorithm, the default is the round robin algorithm.

2. The principle of Ribbon

Ribbon will obtain service information from the registration center, and then select a machine from it through a polling algorithm.

3. The difference between Ribbon and nginx

nginx: The reverse proxy implements load balancing, which is equivalent to request forwarding from the nginx server.
Ribbon: Client load balancing, the whole process is client-side operation.

四.Spring Cloud Feign

1. The role of Feign

Feign integrates Ribbon. Feign is a declarative web service client, which makes it easier to write web service clients and make remote calls easier.

2. SpringCloud has several calling interface methods

Feign
RestTemplate

3. The difference between Ribbon and Feign calling services

Ribbon: We need to build http requests ourselves, and then send them to other services through RestTemplate, which is cumbersome.
Feign: You don't need to build Http requests yourself, just call the interface directly.

五.Spring Cloud Hystrix

1. Talk about what is a service avalanche

Service avalanche: When multiple services call each other, A calls B, B calls C, C calls D, and so on. If the middle call takes a long time, and then calls A, the resources occupied will become more and more Too many, causing the system to crash.

2. What is a Hystrix circuit breaker

A tool to prevent service avalanche, with service degradation, service fusing (@HystrixCommand(fallbackMethod = "hystrixById") //failed call method), service isolation, monitoring and other technologies to prevent avalanche.

3. What are service downgrade, service interruption and service isolation?

Service degradation: When the resources are not enough, close the resources to ensure the operation of core services.
Service fusing: When the service fails, it will directly take the method of fusing.
Service isolation: Open an independent thread for the isolated service, so that the service will not be affected under high concurrency. It is generally implemented using a thread pool (and a semaphore implementation).

六.Spring Cloud Zuul 和 Spring Cloud Gateway

1. What is Zuul Microservice Gateway

Receive all requests and forward different requests to different microservice modules.

2. Zuul application scenarios

①Filter
②Permission authentication
③Downgrade current limit
④Security

3.Gateway

Powerful and rich, good performance, good maintainability, asynchronous, can replace Zuul gateway.

七.Spring Cloud Config

1. What is Spring Cloud Config

Centralized management of configuration files does not require each service to write a configuration file, and the service will pull the configuration from the configuration center.
Real-time refresh (requires spring cloud bus).

おすすめ

転載: blog.csdn.net/twotwo22222/article/details/129291109