Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the necessary interview questions for SpringCloud?

2025-01-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly explains "what are the interview questions that SpringCloud must know". Interested friends might as well take a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "what are the interview questions that SpringCloud must know"?

1. What is Spring Cloud?

The Spring cloud streaming Application launcher is a Spring Boot-based Spring integration application that provides integration with external systems. Spring cloud Task, a short-lived micro-service framework, is used to quickly build applications that perform limited data processing.

2. What are the advantages of using Spring Cloud?

When using Spring Boot to develop distributed microservices, we are faced with the following problems:

Complexity associated with distributed systems-this overhead includes network problems, delay overhead, bandwidth issues, and security issues.

Service Discovery-the service discovery tool manages how processes and services in the cluster find and talk to each other. It involves a service directory in which services are registered, and then you can find and connect to services in that directory.

Redundancy-redundancy in distributed systems.

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.

Performance-A performance problem caused by various operational overhead. Deployment complexity-requirements for Devops skills.

3. What does service registration and discovery mean? How to implement Spring Cloud?

When we start a project, we usually do all the configuration in the properties file. As more and more services are developed and deployed, adding and modifying these properties becomes more complex. Some services may decline, while some locations may change. Manually changing properties can cause problems. Eureka service registration and discovery can help in this case. Because all services are registered on the Eureka server and lookup is done by calling the Eureka server, there is no need to handle any changes and processing of the service location.

4. What is the significance of load balancing?

In computing, load balancing can improve workload distribution across a variety of computing resources, such as computers, computer clusters, network links, central processing units or disk drives. Load balancing is designed to optimize resource usage, maximize throughput, minimize response time, and avoid overloading any single resource. Using multiple components for load balancing rather than a single component may improve reliability and availability through redundancy. Load balancing usually involves specialized software or hardware, such as multilayer switches or domain name system server processes.

5. What is Hystrix? How does it achieve fault tolerance?

Hystrix is a delay and fault-tolerant library designed to isolate access points of remote systems, services and third-party libraries, stop cascading failures and achieve resilience in complex distributed systems when failures are inevitable.

Usually for systems developed using micro-service architecture, many micro-services are involved. These microservices collaborate with each other.

Consider the following microservices:

Suppose that if the microservice 9 in the figure above fails, then using the traditional method we will propagate an exception. But this can still cause the whole system to crash.

With the increase in the number of microservices, the problem becomes more complicated. The number of microservices can be as high as 1000. This is where hystrix appears and we will use the Fallback method functionality of Hystrix in this case. We have two services employee-consumer that use services exposed by employee-consumer.

The simplified figure is as follows:

Now suppose that for some reason, the service exposed by employee-producer throws an exception. We define a fallback method using Hystrix in this case. This fallback method should have the same return type as the exposed service. If an exception occurs in the exposure service, the fallback method returns some values.

What is a Hystrix circuit breaker? Do we need it?

For some reason, employee-consumer exposes a service that throws an exception. Using Hystrix in this case, we define a fallback method. If an exception occurs in the exposed service, the fallback method returns some default values.

If the exception in firstPage method () continues, the Hystrix circuit will break and the employee user will skip the firtsPage method together and call the fallback method directly. The purpose of the circuit breaker is to allow time for the first page method or other methods that may be called by the first page method, and to cause an abnormal recovery. What may happen is that the problem that causes the exception has a better chance of recovery when the load is low.

7. What is Netflix Feign? What are its advantages?

Feign is a java client binder inspired by Retrofit,JAXRS-2.0 and WebSocket. The first goal of Feign is to unify the complexity of the constraint denominator to http apis, regardless of its stability. In the case of employee-consumer, we use the REST service that employee-producer exposes using the REST template.

But we have to write a lot of code to perform the following steps:

1. Use the ribbon for load balancing.

2. Get the service instance and get the basic URL.

3. Use REST template to use the service. The previous code is as follows:

@ Controller public class ConsumerControllerClient {@ Autowired private LoadBalancerClient loadBalancer; public void getEmployee () throws RestClientException, IOException {ServiceInstance serviceInstance=loadBalancer.choose ("employee-producer"); System.out.println (serviceInstance.getUri ()); String baseUrl=serviceInstance.getUri (). ToString (); baseUrlbaseUrl=baseUrl+ "/ employee"; RestTemplate restTemplate = new RestTemplate (); ResponseEntity response=null; try {response=restTemplate.exchange (baseUrl, HttpMethod.GET, getHeaders (), String.class) } catch (Exception ex) {System.out.println (ex);} System.out.println (response.getBody ());}

Previous code, with exceptions like NullPointer, was not optimal. We'll see how to use Netflix Feign to make calls easier and cleaner. If the Netflix Ribbon dependency is also in the classpath, then Feign is also responsible for load balancing by default.

8. What is Spring Cloud Bus? Do we need it?

Consider the following situation: we have multiple applications that use Spring Cloud Config to read properties, and Spring Cloud Config reads these properties from GIT.

In the following example, multiple employee producer modules obtain Eureka registered property from Employee Config Module.

What happens if the Eureka registration property in GIT changes to point to another Eureka server. In this case, we will have to restart the service to get the updated properties.

There is another way to use the actuator endpoint / refresh. But we will have to call this url separately for each module. For example, if Employee Producer1 is deployed on port 8080, http:// localhost:8080 / refresh is called. Also for Employee Producer2 http:// localhost:8081 / refresh and so on. This is troublesome again. This is where Spring Cloud Bus plays a role.

Spring Cloud Bus provides the ability to refresh configurations across multiple instances. Therefore, in the above example, if we refresh the Employee Producer1, we will automatically refresh all other necessary modules. This is especially useful if we have multiple microservices up and running. This is achieved by connecting all microservices to a single message broker. Whenever the instance is refreshed, this event subscribes to all microservices that listen on the agent, and they are refreshed as well. You can refresh any single instance by using endpoint / bus / refresh.

9. SpringCloud and Dubbo

Both SpringCloud and Dubbo are the mainstream microservice architectures.

SpringCloud is a micro-service solution under the Spring system of Apache.

Dubbo is the distributed service governance framework of Ali system.

From a technical point of view, SpringCloud is far more than Dubbo,Dubbo itself only to implement service governance, and SpringCloud will have more now and after 21 sub-projects.

So in fact, many people will say that Dubbo and SpringCloud are unfair.

However, due to RPC and registry metadata and other reasons, we can only choose one of the two in technology selection, so we often use them to compare.

The service is invoked by Dubbo using RPC remote calls, while SpringCloud uses Rest API, which is more in line with the official definition of microservices.

From the point of view of the registry of the service, Dubbo uses the third-party ZooKeeper as its underlying registry to realize the registration and discovery of the service. SpringCloud uses SpringCloud Netflix Eureka to implement the registry. Of course, SpringCloud can also be implemented using ZooKeeper, but we generally do not do so.

Service gateway, Dubbo does not have its own implementation, can only through the integration of other third-party technologies, while SpringCloud has Zuul routing gateway, as a routing server for consumer request distribution, SpringCloud also supports circuit breakers, perfect integration with git distributed configuration files to support version control, transaction bus to achieve configuration file updates and service automatic assembly and a series of micro-service architecture elements.

10. Technology selection

At present, the domestic distributed system selection is mainly Dubbo, after all, and the domestic engineers have high technical proficiency, and the defects of Dubbo in other dimensions can be made up by other third-party frameworks.

At present, SpringCloud is more popular abroad, of course, I think the domestic market will slowly favor SpringCloud. Even Liu Jun, as the person in charge of the restart of Dubbo, has expressed his view that the development direction of Dubbo is to actively adapt to the ecology of SpringCloud, not conflict.

11. Comparison between Rest and RPC

In fact, if you carefully read the paper of Martin Fowler, the microservice proposer, you can find that the defined communication mechanism between services is Http Rest.

The main defect of RPC is that the dependence between the service provider and the invocation method is too strong. We need to define the interface for each microservice, and through continuous inheritance and release, we need strict version control to avoid the conflict between service provision and invocation due to different versions.

While REST is a lightweight interface, there is no code coupling between service provision and invocation, but it is only regulated by a convention, but there may be service integration problems caused by inconsistent documents and interfaces, but it can be integrated by swagger tools, which can be solved by the integration of code and documents, so REST is more flexible than RPC in a distributed environment.

This is also the reason why DubboX of Dangdang has added support for REST in the enhancement of Dubbo.

12. Document quality and community activity

The activity of the SpringCloud community is much higher than that of Dubbo. After all, because of Liang Fei's team, Dubbo stopped updating and iterating for five years, while small and medium-sized companies could not afford the cost of technology development, which led to a serious decline in the Dubbo community, while SpringCloud quickly occupied the market of micro-services, relying on the wind and water mixed with Spring.

After years of accumulated documentation, Dubbo is quite mature, and companies also have a stable status quo for the architecture of micro-services.

13, SpringBoot and SpringCloud

SpringBoot is a Maven-based solution introduced by Spring to solve the redundancy of traditional framework configuration files and complex assembly components, which aims to quickly build a single micro-service.

While SpringCloud focuses on the coordination and configuration of various micro-services, communication between services, circuit breakers, load balancing, etc., the technical dimensions are not the same, and SpringCloud depends on SpringBoot, while SpringBoot does not rely on SpringCloud, and can even carry out excellent integrated development with Dubbo.

Summary:

1. SpringBoot focuses on the rapid and convenient development of individual micro-services

2. SpringCloud is a global micro-service coordination governance framework, integrates and manages various micro-services, and provides integrated services for micro-services, such as configuration management, service discovery, circuit breaker, routing, event bus, etc.

3. SpringBoot does not depend on SpringCloud,SpringCloud, depends on SpringBoot, and belongs to dependency relationship.

4. SpringBoot focuses on the rapid and convenient development of individual micro-services, while SpringCloud focuses on the global service governance framework.

14. Both Eureka and ZooKeeper can provide the functions of service registration and discovery. Please tell me the difference between them.

1.ZooKeeper guarantees CP,Eureka guarantees AP.

ZooKeeper registration service was paralyzed during the election, although the service will eventually be restored, but not available during the election.

Each node of Eureka is equal. As long as there is an Eureka, the service is available, and the data queried is not up-to-date.

Self-protection mechanisms can lead to:

Eureka no longer removes services from the registration list that should expire because they have not received a heartbeat for a long time.

Eureka can still accept registration and query requests for new services, but will not be synchronized to other nodes (highly available)

When the network is stable, the new registration information of the current instance will be synchronized to other nodes (final consistency)

Eureka can well deal with the situation that some nodes lose contact due to network failure, instead of paralyzing the whole registration system like ZooKeeper.

2.ZooKeeper has Leader and Follower roles, and all nodes of Eureka are equal.

3.ZooKeeper adopts the principle of more than half survival, and Eureka adopts self-protection mechanism to solve the zoning problem.

4.Eureka is essentially a project, while ZooKeeper is just a process.

15. How do microservices communicate independently

Microservice communication mechanism:

Each micro-service in the system can be deployed independently, and each micro-service is loosely coupled. Each microservice focuses only on completing a task and accomplishing that task well.

Organize services, automated deployment, intelligent endpoints, and decentralized control of language and data around business capabilities.

Components are defined as software units that can be replaced and upgraded independently.

The strategy of organizing services based on business capabilities.

Advocate the integrated method of development, operation and maintenance of who develops and operates.

RESTful HTTP protocol is the most commonly used communication mechanism in micro-service architecture.

Each microservice can be done with the best tool (such as a different programming language).

Different microservices are allowed to adopt different data persistence technologies.

Micro-services attach great importance to the establishment of real-time monitoring and logging mechanisms for architecture and business-related indicators, and the failure-tolerant mechanism of each service must be considered.

Focus on rapid updates, so the system will change and evolve over time. Replaceable modular design.

Micro-service communication mode:

Synchronization: RPC,REST, etc.

Async: message queue. Consider reliable message delivery, high performance, and changes in the programming model.

How to select message queuing middleware:

1. Protocols: AMQP, STOMP, MQTT, private protocols, etc.

two。 Whether the message needs to be persisted.

3. Throughput.

4. Highly available support, whether single point or not.

5. Distributed scalability.

6. Message stacking ability and playback ability.

7. Easy to develop and easy to maintain.

8. Community maturity.

RabbitMQ is a message queuing middleware that implements AMQP (Advanced message queuing Protocol) protocol. RabbitMQ supports both at most and at least once. The service architecture of NetEase Honeycomb platform, the communication between services is realized through RabbitMQ.

16. What is a service breaker? What is service degradation?

In complex distributed systems, the mutual calls between micro services may lead to service blocking for a variety of reasons. in high concurrency scenarios, service blocking means thread blocking, resulting in the unavailability of the current thread. All the threads of the server are blocked, causing the server to crash. Because the invocation relationship between services is synchronous, it will cause a service avalanche to the entire micro-service system. In order to solve the avalanche effect caused by the call response time of a micro-service is too long or unavailable, it is necessary to deal with service breaker and service degradation.

The so-called service circuit breaker refers to a service failure or exception that is similar to the "fuse" in the world when an abnormal condition is triggered, instead of waiting for the service to time out.

A service fuse is the fuse of our switch. Once a service avalanche occurs, it will fuse the entire service. By maintaining its own thread pool, when the thread reaches the threshold, the service will be started and degraded. If other requests continue to access, the default value of fallback will be returned directly.

17. What are the advantages and disadvantages of microservices? Tell me about the hole you encountered in the project development.

Advantages:

Each service is sufficiently cohesive and the code is easy to understand

The development efficiency is improved, and a service only does one thing.

Micro services can be developed separately by small teams.

Micro-service is loosely coupled and has functional meaning.

Can be developed in different languages and interface-oriented programming

Easy to integrate with third parties

Microservices are just code for business logic and will not be combined with HTML,CSS or other interfaces.

In development, two development modes

Front and rear end separation

Full stack engineer

Can be flexibly matched to connect common libraries / independent libraries

Disadvantages:

The responsibility of distributed system, the difficulty of multi-service operation and maintenance, the pressure of operation and maintenance increases with the increase of service, system deployment dependence, inter-service communication cost, data consistency, system integration testing, performance monitoring.

18. What are the micro-service technology stacks you know? Please list one or two

A collection of technologies

We are talking about what dimensions are needed for a distributed micro-service architecture.

Dimension (SpringCloud)

Service development SpringBoot Spring SpringMVC service configuration and management Netfilx's Archaiusm, Ali's Diamond service registration and discovery Eureka,ZooKeeper service invocation Rest,RPC,gRPC service fuse Hystrix service load balancing Ribbon Nginx service interface invokes Feign message queue Kafka,RabbitMq,ActiveMq service configuration center manages SpringCloudConfing service routing (API gateway) Zuul event message bus SpringCloud Bus to this I believe that everyone has a deeper understanding of "what are the interview questions that SpringCloud must know?" you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report