Hello, today I’m going to share with you Spring Cloud interview exercises. Please take out your notebook and write them down
1. What is Spring Cloud?
The Spring Cloud Streaming application launcher is a Spring integration application based on Spring Boot that provides integration with external systems. Spring Cloud Task, a microservices framework with a short life span, is used to quickly build applications that perform limited data processing.
2. What are microservices?
Microservices architecture is an architectural pattern, or architectural style, that advocates partitioning a single application into a set of small services, each running in its own independent process, that coordinate with each other to provide ultimate value to users. Services communicate with each other through lightweight communication mechanisms (usually RESTful apis based on HTTP). Each service is built around a specific business and can be independently built in a production environment, a production environment, and so on. In addition, should avoid to unified, centralized service management mechanism, for a specific service, should be based on the business context, select the appropriate language, tools, and to construct, there can be a very lightweight centralized management to coordinate these services, you can use different language to write the service, also can use different data storage.
In layman’s terms:
A microservice is a single service application with a single responsibility. In the Intellij IDEA tool is the use of Maven development of a separate module, specifically is the use of Springboot development of a small module, dealing with a single professional business logic, a module only do one thing.
Microservice emphasizes the size of service and focuses on a certain point. A service application corresponding to a specific problem/landing can be regarded as a Module in IDEA.
3. What are the advantages of Spring Cloud
When developing distributed micro-services using Spring Boot, we face the following issues
Complexity associated with distributed systems – this overhead includes network issues, latency costs, bandwidth issues, and security issues.
Service discovery – The service discovery tool manages how processes and services in the cluster look up and talk to each other. It involves a catalog of services in which you can register services and then be able to find and connect to services in that catalog.
Redundancy – The problem of 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 – Issues Performance issues due to various operational overhead.
Deployment complexity -Devops skills required.
4. How do micro services communicate independently?
Synchronous communication: Dobbo via RPC remote procedure call, SpringCloud via REST INTERFACE JSON call, etc.
Asynchronous: Message queues, such as RabbitMq, ActiveM, and Kafka message queues.
5. What is service circuit breaker? What is service degradation?
Circuit breaker mechanism is a kind of micro – service link protection mechanism to deal with avalanche effect. When a microservice is unavailable or the response time is too long, the service will be degraded, and the invocation of the microservice on this node will be interrupted, and an “error” response message will be quickly returned. Restore the call link after detecting that the microservice invocation response of this node is normal. In the Spring Cloud framework, the circuit breaker mechanism is implemented through Hystrix, which monitors the status of calls between microservices. When the failed calls reach a certain threshold, the default is 20 calls within 5 seconds, and if they fail, the circuit breaker mechanism will be activated.
Service degradation is generally considered from the overall load. When a service is blown down and the server is no longer called, the client can prepare a local fallback callback to return a default value. This way, although the level drops, but at least usable, rather than just dead.
Hystrix related notes @enableHystrix: Turn on the fuse @hystrixCommand (fallbackMethod= “XXX”) and declare a failback handler XXX. When the annotated method times out (default: 1000 ms), fallback will be executed with an error message.
6. What is the difference between Eureka and Zookeeper?
Zookeeper guarantees CP, Eureka guarantees AP.
A: High availability
C: Consistency
P: fault tolerance of partitions
1. When we query the registry for a list of services, we can tolerate the registry to return information a few minutes ago, but cannot tolerate the direct down unavailable. In other words, the service registration function has high requirements for high availability, but zK will have such a situation that when the master node loses contact with other nodes due to network failure, the remaining nodes will choose the leader again. The problem is that it takes a long time to select a leader (30 to 120s), and the ZK cluster is unavailable during the selection period. As a result, the registration service will be broken during the selection period. In a cloud deployment environment, it is highly likely that the ZK cluster will lose its master node due to network problems. Although the service can be restored, the long selection time resulting in long-term registration unavailability cannot be tolerated.
2.Eureka ensures availability. All Eureka nodes are equal. The failure of several nodes will not affect the work of normal nodes. When Eureka’s client fails to register or discover a Eureka, it will automatically switch to other nodes. As long as one Eureka is still available, the registration service can be guaranteed, but the information found may not be the latest. In addition, Eureka also has a self-protection mechanism. If more than 85% of the nodes have no normal heartbeat within 15 minutes, Eureka considers that there is a network failure between the client and the registry, and the following situations may occur:
Eureka does not remove services from the register that should expire because they have not received a heartbeat for a long time.
Eureka can still accept new service registration and query requests, but will not be synchronized to other nodes (that is, the current node is still available).
3. 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 situation that some nodes lose contact due to network failure, rather than the whole microservice breakdown like Zookeeper
7. The difference between SpringBoot and SpringCloud?
SpringBoot focuses on developing individual microservices quickly and easily.
SpringCloud is a global microservices coordination and consolidation governance framework, which integrates and manages individual microservices developed by SpringBoot.
Provide integrated services for configuration management, service discovery, circuit breakers, routing, micro proxy, event bus, global lock, decision campaign, distributed session, and so on between microservices
SpringBoot can be independently used for development projects without SpringCloud, but SpringCloud is dependent on SpringBoot.
SpringBoot focuses on developing individual microservices quickly and easily, while SpringCloud focuses on a global service governance framework.
What is the significance of load balancing?
In computing, load balancing can improve workload distribution across multiple 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. Load balancing with multiple components rather than a single component may improve reliability and availability through redundancy. Load balancing typically involves proprietary software or hardware, such as multi-tier switches or domain name system server processes.
9. What is Hystrix? How does it achieve fault tolerance?
Hystrix is a delay and fault tolerant library designed to isolate access points to remote systems, services and third party libraries, stopping cascading failures when failures are unavoidable and enabling resilience in complex distributed systems.
Typically for systems developed using a microservice architecture, many microservices are involved. These microservices work with each other.
Consider the following microservices
Suppose that if microservice 9 in the figure above fails, we will propagate an exception using traditional methods. But it can still cause the whole system to crash.
The problem becomes more complicated as the number of microservices increases. The number of microservices can be as high as 1000. This is where Hystrix comes in and we will use hystrix’s Fallback method functionality in this case. We have two services employee-Consumer that use services exposed by Employee-Consumer.
The simplified figure is shown below
Now suppose that for some reason the employee-producer exposed service throws an exception. We defined a fallback method in this case using Hystrix. This backup method should have the same return type as the exposed service. If an exception occurs in the exposed service, the fallback method returns some values.
What is Hystrix circuit breaker? Do we need it?
For some reason, the Employee-Consumer exposure service 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 users will collectively skip the firtsPage method and call the fallback method directly. The purpose of a circuit breaker is to allow time for the first page method or other methods that the first page method might call and cause an abnormal recovery. What may happen is that, with a low load, the problem that caused the exception has a better chance of recovery.
Talk about the implementation principle of RPC
First of all, there is a module to deal with network connection communication, which is responsible for connection establishment, management and message transmission. Second, we need to have codec modules, because network communication is all bytecode transmission, we need to serialize and de-serialize the objects we use. The rest is client-side and server-side, where the server exposes the service interface to be exposed, and the client invokes a proxy implementation of the service interface that collects data, encodes it, and transmits it to the server, then waits for the results to return.
12. What is the Eureka self-protection mechanism?
When the Eureka Server node loses too many instances in a short period of time (for example, when the network fails or the client is frequently started and closed), the node enters the self-protection mode to protect the registration information and not delete the registration data. When the fault is recovered, the Eureka Server node automatically exits the self-protection mode.
13. What is the Ribbon?
The Ribbon is a load balancing client that controls HTT and TCP behavior. Feign integrates the ribbon by default.
14. What is Netflix Feign? What are its advantages?
Feign is a Java client interprogramming inspired by Retrofit, JAXRS-2.0, and WebSocket.
Feign’s first goal was to unify the complexity of the constraint denominator into the HTTP apis, regardless of its stability.
Features:
Feign uses interface-based annotations
Feign integrates the Ribbon with load balancing capabilities
Integrated with Hystrix, with fuse breaker capability
use
Add POM dependencies.
Add @enableFeignClients to the start class
Define an interface @feignClient (name= “XXX”) to specify which service to call
15. What is the difference between the Ribbon and Feign?
1. The Ribbon calls other services, but in different ways. 2. The Ribbon is @ribbonClient feign and the Ribbon is @enableFeignClients 3. The Ribbon is declared on the @RibbonClient annotation, while Feign uses the @FeignClient declaration in the interface that defines the abstract method. 4. Different invocation methods. The Ribbon needs to build HTTP requests itself to simulate HTTP requests.
16. What are the core components of Spring Cloud?
Eureka: Service registered at Discovery.
Feign: Based on dynamic proxy mechanism, concatenate request URL address according to annotation and selected machine, initiate request.
Ribbon: Implements load balancing by selecting one machine for a service.
Hystrix: Provides thread pools so that different services can go through different thread pools to achieve the isolation of different service calls and avoid the problem of service avalanche.
Zuul: Gateway management. The Zuul gateway forwards requests to the corresponding service.
17, Talk about Spring Boot and Spring Cloud
Spring Boot is a Maven-based solution launched by Spring to solve the traditional framework configuration file redundancy and complex assembly components, aiming to quickly build a single micro-service, while Spring Cloud focuses on solving the coordination and configuration between micro-services, communication between services, fuse, load balancing and so on The technical dimensions are not the same, and Spring Cloud is dependent on Spring Boot, which is not dependent on Spring Cloud, and can even be well integrated with Dubbo
conclusion
SpringBoot focuses on developing individual microservices quickly and easily
SpringCloud is a global microservices coordination governance framework that integrates and manages various microservices, providing integrated services such as configuration management, service discovery, circuit breakers, routing, event bus, etc
Spring Boot does not depend on Spring Cloud, but Spring Cloud depends on Spring Boot
Spring Boot focuses on developing individual microservices quickly and easily, while Spring Cloud focuses on a global service governance framework
18. How do microservices communicate independently?
Remote Procedure Invocation
This is often referred to as the registration and discovery of services, directly accessing other services through remote procedure calls.
Advantages: Simple, common, simpler system because there is no middleware proxy
Disadvantages: Only request/response mode is supported and nothing else, such as notification, request/asynchronous response, publish/subscribe, publish/asynchronous response, reduces availability because both client and server must be available during the request process.
The message
Use asynchronous messaging for inter-service communication. Services communicate by exchanging messages through message pipes.
Advantages: Decoupled client and server, looser coupling, improved availability because messaging middleware caches messages until consumers can consume them, supports many communication mechanisms such as notification, request/asynchronous response, publish/subscribe, and publish/asynchronous response.
Disadvantages: Messaging middleware has additional complexity.
19. How does Spring Cloud implement service registration?
When a service is published, specify the corresponding service name and register the service with the registry (Eureka and Zookeeper).
The registry uses @enableeurekaserver, the service uses @enableDiscoveryClient, and then uses the Ribbon or Feign for direct service discovery.
This topic is inclined to actual combat, see you are the reverse test questions, the person without actual combat does not know.
20. What is service circuit breaker?
In the complicated distributed system, the interaction between the micro service calls, may appear all sorts of reasons lead to the blocking of the service, the high concurrency scenarios, the blocking of the service means that the thread blocking, causes the current thread is not available, the server thread blocked, cause server crash, because the relationship between the invocation of the service are synchronous, interfere with the whole service system Service avalanche
In order to solve the avalanche effect caused by the invocation response time of a micro-service being too long or unavailable, more and more system resources are occupied, service fusing and service degradation are needed.
A service fuse is a service failure or exception that fuses the entire service when an exception condition is triggered, rather than waiting until the service times out.
A service meltdown is the equivalent of a fuse on our power switch. Once a service avalanche occurs, it will blow down the entire service, by maintaining a pool of its own threads that initiate degradation when threads reach a threshold and return the default value of the Fallback if other requests continue
21. Do you understand the Eureka self-protection mechanism?
When the Eureka Server node loses too many instances in a short period of time (for example, when the network fails or the client is frequently started and closed), the node enters the self-protection mode to protect the registration information and not delete the registration data. When the fault is recovered, the Eureka Server node automatically exits the self-protection mode.
Are you familiar with Spring Cloud Bus?
Spring Cloud Bus connects distributed nodes with lightweight message brokers that can be used to broadcast configuration file changes or direct communication with services, as well as for monitoring. If you change the configuration file, send a request and all clients re-read the configuration file.
23. What does Spring Cloud circuit breaker do?
When a service calls another service due to network or its own problems, the caller will wait for the response of the called, and when more services request these resources, more requests wait, resulting in a chain effect (avalanche effect). A certain number of times that the service cannot be called for a certain period of time and the repeated monitoring shows no signs of recovery, when the circuit breaker is fully open the next request will not be requested to the service.
Half-open: The circuit breaker will send partial requests to the service if there are signs of recovery within a short period of time. The circuit breaker will close when it is called normally. Off: The service can be invoked when it is in the normal state.
Do you know Spring Cloud Config?
In a distributed system, due to a large number of services, a distributed configuration center is required to facilitate unified management and real-time update of service configuration files. In Spring Cloud, there is a distributed configuration center component, Spring Cloud Config, which enables configuration services to be placed in the memory of the configuration service (that is, locally) as well as in a remote Git repository.
In the Spring Cloud Config component, there are two roles: Config Server and Config client.
Usage:
Add POM dependencies
Configuration file Add related configurations
The start class adds an annotation @enableconFigServer
25. Tell me what you understand about Spring Cloud Gateway
Spring Cloud Gateway is the second generation of Spring Cloud’s official Gateway framework, replacing Zuul Gateway. As a traffic, the gateway plays a very important role in the micro-service system. The common functions of the gateway include routing and forwarding, permission verification, and traffic limiting control.
The RouteLocatorBuilder allows you to add various predicates and filters, based on the rules of the specific request. Filters are the kinds of filters used to make various judgments and changes to the request, processed by a specific route.
Well, this is the end of today’s article, I hope to help you confused in front of the screen