preface

Spring Cloud is an ordered collection of frameworks. It takes advantage of the development convenience of Spring Boot to subtly simplify the development of distributed system infrastructure, such as service discovery registry, configuration center, message bus, load balancing, circuit breakers, data monitoring, etc., which can be started and deployed with one click using Spring Boot’s development style. Instead of reinventing the wheel, Spring Cloud simply combines mature, proven service frameworks developed by various companies and encapsulates them in Spring Boot style, eliminating complex configuration and implementation principles. Finally, a simple and easy to understand, easy to deploy and easy to maintain distributed system development kit was set aside for developers.

Spring Cloud has the following features:

  • Convention over configuration;
  • Suitable for all environments. Develop and deploy PC Server or various cloud environments (such as Ali Cloud and AWS);
  • Hides component complexity and provides declarative, XML-free configuration;
  • Out of the box, fast start;
  • Lightweight components. Spring Cloud integrates components that are mostly lightweight. Eureka, Zuul, etc., are lightweight implementations of their own domains;
  • Rich components, complete functions. Spring Cloud provides very complete support for microservice architectures. For example, configuration management, service discovery, circuit breakers, microservice gateways, etc.
  • Selection of neutral, rich. For example, Spring Cloud supports service discovery using Eureka, Zookeeper, or Consul;
  • Flexible. The components of Spring Cloud are decoupled, giving developers the flexibility to pick and choose technologies on demand.

The knowledge of Spring Cloud micro-service architecture is summarized in a mind map to share with you

Spring Cloud interview question

1. What is Spring Cloud?

2. What are the advantages of using Spring Cloud?

3. What does service registration and discovery mean? How is Spring Cloud implemented?

4. What’s the difference between Spring Cloud and Dubbo?

5. The difference between SpringBoot and SpringCloud?

What is the significance of load balancing?

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

8. What is Hystrix circuit breaker? Do we need it?

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

What is Spring Cloud Bus? Do we need it?

11. The role of Spring Cloud circuit breaker

12. What is SpringCloudConfig?

13, Spring Cloud Gateway?

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 the advantages of using Spring Cloud?

When developing distributed micro-services using Spring Boot, we face the following issues

(1) Complexity associated with distributed systems – this overhead includes network issues, latency costs, bandwidth issues, and security issues.

(2) 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.

(3) redundancy – the redundancy problem in distributed system.

(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 overhead.

(6) Deployment complexity -Devops skill requirements.

3. What does service registration and discovery mean? How is Spring Cloud implemented?

When we start a project, we usually do all the configuration in the properties file. As more services are developed and deployed, adding and modifying these properties becomes more complex. Some services may decline and some locations may change. Manually changing properties can cause problems. Eureka service registration and discovery can help in this situation. 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’s the difference between Spring Cloud and Dubbo?

Dubbo is RPC SpringCloud Rest Api

(2) Registry, Dubbo is ZooKeeper, SpringCloud is Eureka, and it can also be ZooKeeper

(3) Service gateway,dubbo itself is not implemented, can only be integrated through other third-party technologies, SpringCloud has Zuul routing gateway, as a routing server, for consumer request distribution, SpringCloud supports circuit breakers, perfect integration with Git configuration file support version control, The transaction bus implements a series of microservice architecture elements such as configuration file update and automatic service assembly.

5. 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.

7. 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.

8. 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.

9. 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.

In the Employee-consumer example, we use the Employee-Producer REST service exposed using the REST template.

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

(1) Use functional zones for load balancing.

(2) Get the service instance, and then get the base URL.

(3) Use REST templates to use services. The previous code is as follows

@Controller
public class ConsumerControllerClient {
    @Autowired
    private LoadBalancerClient loadBalancer;
    public void getEmployee(a) throws RestClientException, IOException {
        ServiceInstance serviceInstance=loadBalancer.choose("employee-producer");
        System.out.println(serviceInstance.getUri());
        String baseUrl=serviceInstance.getUri().toString();
        baseUrl=baseUrl+"/employee";
        RestTemplate restTemplate = new RestTemplate();
        ResponseEntity<String> response=null;
        try{
            response=restTemplate.exchange(baseUrl,
                        HttpMethod.GET, getHeaders(),String.class);
        }
        catch (Exception ex)
            {
            System.out.println(ex);
        }
        System.out.println(response.getBody());
    }Copy the code
The previous code, with opportunities for exceptions like NullPointer, was not optimal. We’ll see how Netflix Feign can be used to make calling easier and cleaner. If the Netflix Ribbon dependency is also in the classpath, then Feign is also responsible for load balancing by default.

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 those properties from GIT.

The following example shows multiple Employee producer modules fetching Eureka registered properties from the Employee Config Module.



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

There is another way to use executor endpoints/flushes. 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, etc. That’s a hassle. This is where Spring Cloud Bus comes in.

Spring Cloud Bus provides the ability to refresh configurations across multiple instances. Therefore, in the example above, if we refresh Employee Producer1, all other required modules are automatically refreshed. 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 an instance is refreshed, this event subscribes to all microservices listening to this agent, and they are refreshed as well. The refresh of any single instance can be achieved by using endpoint/bus/refresh.

11. Role of SpringCloud circuit breaker

When a service calls another service due to network or its own problems, the caller will wait for the response of the called service. When more services request these resources, more requests wait, resulting in a chain effect (avalanche effect).

The circuit breaker has a fully open state: it cannot be called for a certain number of times within a period of time and there is no sign of recovery after repeated monitoring. The circuit breaker is fully open and the next request will not request 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

12. What is SpringCloudConfig?

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.

Use:

(1) Add POM dependencies

(2) Add related configurations to the configuration file

(3) Add the @enableconFigServer annotation to the start class

13, 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.



Welcome everyone to pay attention to my public account [programmer Chase wind], 2019 many companies Java interview questions sorted out more than 1000 400 pages of PDF documents, articles will be updated in it, sorted information will also be placed in it.

The last

Welcome everyone to exchange, like the article remember to pay attention to my like yo, thank you for your support!