The SpringBoot+SpringCloud interview summary is here

The SpringBoot+SpringCloud interview summary is here
insert image description here
. Everyone should know that SpringBoot is currently the most popular microservice framework, and SpringCloud is also the most popular microservice governance framework. So how much do you know about these two frameworks? Below is what I have organized.

microservice

1. What is a microservice?

Microservice architecture is an architectural pattern or an architectural style, which advocates dividing a single application into a set of small services, each service runs in its own independent process, and the services coordinate and coordinate with each other , and finally provide external services. Services communicate with each other using a lightweight communication mechanism (usually an HTTP-based RESTful API). Each service is built around a specific business and can be independently deployed to production environments, production-like environments, etc. In addition, a unified and centralized service management mechanism should be avoided as much as possible. For a specific service, appropriate language and tools should be selected according to the business context to construct it, and a very lightweight centralized management can be achieved. To coordinate these services, the services can be written in different languages ​​and can use different data stores.
From a technical perspective:
the core of micro-service is to split the traditional one-stop application into independent services one by one according to the business, and completely decouple them. Each micro-service provides a single business function service, and one service does One thing, from a technical point of view, is a small and independent process, similar to the concept of a process, that can be started or destroyed independently.
2. How do microservices communicate with each other?

The first type: remote procedure call, that is, RPC (Remote Procedure Invocation)
directly accesses other services through remote procedure call, such as: REST, Apache.
The second type: Messages
use asynchronous messages for inter-service communication. Services communicate through message pipes to exchange messages. Such as: Apache Kafka, RabbitMQ
SpringBoot

1. What is Spring Boot?

Spring Boot is a sub-project under the Spring open source organization. It is a one-stop solution for Spring components. It mainly simplifies the difficulty of using Spring, saves heavy configuration, and provides various starters so that developers can get started quickly.

2. What are the advantages of Spring Boot?

-Quickly create independent running spring projects and integrate with mainstream frameworks
-Using embedded servlet containers, applications do not need to be packaged into war packages
-Automatic dependencies and version control for starters
-A large number of automatic configurations, simplifying development, and can also modify default values ​​-Quasi
-production Operational application monitoring of the environment
- natural integration with cloud computing

3. What are the formats of Spring Boot configuration files?

***.properties and ***.yml, the difference between them is mainly in the different writing formats.
.yml is a human-readable data serialization language.
properties is the properties configuration file;
yml files are more structured and less confusing than properties files if we want to add complex properties in configuration files. It can be seen that YAML has hierarchical configuration data.
The .yml format does not support @PropertySource annotation import configuration
4. Which is the core annotation of Spring Boot? Which annotations does it mainly consist of?
The startup class annotation is @SpringBootApplication, which is also the core annotation of Spring Boot. The main combination includes the following three annotations:
1. @SpringBootConfiguration: combines the @Configuration annotation to realize the function of the configuration file.
2. @EnableAutoConfiguration: Turn on the automatic configuration function, or turn off an automatic configuration option, such as turning off the data source automatic configuration function: @SpringBootApplication(exclude = { DataSourceAutoConfiguration.class }).
3. @ComponentScan: Spring component scanning.

5. What are the ways to run Spring Boot?

1), package with commands or run in a container

2), use the Maven/Gradle plug-in to run
3), directly execute the main method to run
6, the logging framework supported by Spring Boot?

Spring Boot supports Java Util Logging, Log4j2, Lockback as the log framework, and if you use the Starters starter, Spring Boot will use Logback as the default log framework.

7. How many ways does SpringBoot implement hot deployment?

There are two main ways:

Spring Loaded

Spring-boot-devtools

8. How does Spring Boot configure multiple environments?

Multiple sets of configuration files are provided:

applcation.yml
application-dev.yml
application-test.yml
application-pro.yml

Load the corresponding environment by changing the profiles.active value in applcation.
spring:
profiles:
active: dev
Spring Cloud

1. What is Spring Cloud?
The Spring Cloud Stream Application Enabler is a Spring Integration application based on Spring Boot that provides integration with external systems. Spring cloud Task, a short-lived microservice framework for quickly building applications that perform limited data processing.

2. What are the advantages of Spring Cloud?
When using Spring Boot to develop distributed microservices, we face the following problems

1. Complexity associated with distributed systems - this overhead includes network issues, latency overhead, bandwidth issues, security issues.

2. Service Discovery - Service discovery tools manage how processes and services in the cluster find and talk to each other. It involves a service directory, registering services in that directory, and then being able to find and connect to services in that directory.

3. Redundancy - Redundancy issues in distributed systems.

4. Load Balancing - Load balancing improves the distribution of workloads across multiple computing resources, such as computers, computer clusters, network links, central processing units, or disk drives.

5. Performance-issues Performance issues due to various operational overheads.

6. Deployment complexity - requirements for Devops skills.

3. How does Spring Cloud implement service registration and discovery?
When the service is published, specify the corresponding service name (the service name includes the IP address and port) Register the service to the registration center (eureka)

This process is automatically implemented by Springcloud. You only need to add @EnableDiscoveryClient in the main method to modify the port of the same service to start multiple instances.

Calling method: Pass the service name Get all available instances through the registry Call the corresponding service through the load balancing strategy (ribbon and feign)

4. As a service registry, how is Eureka better than Zookeeper? The
famous CAP theory points out that it is impossible for a distributed system to satisfy C (consistency), A (availability) and P (partition fault tolerance) at the same time. Since the partition fault tolerance P must be guaranteed in a distributed system, we can only make a trade-off between A and C.

Therefore, Zookeeper guarantees CP, and Eureka is AP.

5. What are ribbon and feign, and their difference?
SpringCloud's Netflix provides two components to implement soft load balancing calls: ribbon and feign.

Both Ribbon and Feign are used to call other services, but in different ways

Ribbon uses @RibbonClient(value="service name") to use RestTemplate to call the method corresponding to the remote service

Feign uses @FeignClient ("specified service name") to call the provider to provide an external interface;

The difference between Ribbon and Feign:

1), the startup class uses different annotations, Ribbon uses @RibbonClient, and Feign uses @EnableFeignClients.

2), the specified location of the service is different, Ribbon is declared on the @RibbonClient annotation, and Feign is declared using @FeignClient in the interface defining the abstract method.

3), the calling method is different, Ribbon needs to construct the http request by itself, simulate the http request and then use the RestTemplate to send it to other services, the steps are quite cumbersome.

Feign is an improvement on the basis of Ribbon, using the interface method to define the methods of other services that need to be called as abstract methods.

6. What is a service circuit breaker? What is service degradation?
Direct service calls, such as process blocking in high concurrency situations, make the current thread unavailable, and slowly all threads are blocked, causing the server to avalanche.

Service blowing: It is equivalent to a fuse. If an exception occurs, the entire service will be blown directly instead of waiting until the service times out. By maintaining its own thread pool, when the thread reaches the threshold, service degradation will be initiated, and if other requests continue to access, it will directly return to the default value of fallback.

7. What is Hystrix (circuit breaker)? How does it achieve fault tolerance?

Hystrix is ​​a latency and fault tolerance library designed to isolate access points to remote systems, services, and third-party libraries, stop cascading failures and achieve resilience in complex distributed systems when inevitable failures occur.

In a distributed system, many dependencies will inevitably fail to call, such as timeouts, exceptions, etc. Hystrix can ensure that in the case of a dependency problem, it will not cause the overall service to fail, avoid cascading failures, and improve distributed systems. flexibility.

8. What is zuul routing gateway?
Zuul includes two main functions of request routing and filtering:

Among them, the routing function is responsible for forwarding external requests to specific microservice instances, which is the basis for realizing the unified entrance of external access, while the filter function is responsible for intervening in the processing of requests, which is the basis for realizing functions such as request verification and service aggregation. .Zuul and Eureka are integrated, and Zuul itself is registered as an application under the Eureka service management, and at the same time, other microservice news is obtained from Eureka, that is, future access to microservices is obtained after jumping through Zuul.

Note: Zuul service will eventually be registered into Eureka

Provide = proxy + routing + filtering three major functions

9. What is the SpringCloud Config distributed configuration center?

Spring Cloud Config provides centralized external configuration support for microservices in the microservice architecture, and the configuration server provides a centralized external configuration for all environments of different microservice applications.

10. What can the distributed configuration center do?
1), centralized management of configuration files with different configurations in different environments, dynamic configuration updates, deployment in different environments such as dev/test/prod/beta/release

2), dynamically adjust the configuration during operation, no longer need to write configuration files on the machine where each service is deployed, and the service will uniformly pull and configure its own information from the configuration center

3), when the configuration changes, the service does not need to be restarted to perceive the configuration change and apply the new configuration to expose the configuration information in the form of a REST interface

Guess you like

Origin blog.csdn.net/m0_54861649/article/details/126648787