SpringCloud interview topics and answers

The question: What is the Spring Cloud?

Spring Cloud stream is based on the application launcher Spring Spring integration of the Boot application, provide integration with external systems. Spring cloud Task, a short life cycle of the micro-services framework for rapidly building applications to perform a limited data processing.

Question two: Use Spring Cloud What are the advantages?

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

  • The complexity associated with distributed systems - such overhead include network problems, latency overhead, bandwidth issues, security issues.

  • Service discovery - how service discovery tool for managing a cluster of processes and services to find and talk to each other. It involves a service catalog, registration services in the directory, and then be able to find and connect to the directory service.

  • Redundancy - redundancy in distributed systems.

  • Load balancing - to improve load balancing workloads across multiple computing resources, such as a distributed computer, a computer cluster, a network link, a central processing unit, or a disk drive.

  • Performance - problems due to performance issues caused by a variety of operating expenses.

  • The complexity of the deployment requirements -Devops skills.

Question three: Service registration and discovery What does it mean? Spring Cloud how to achieve?

When we start a project, we usually perform all configuration properties file. As more and more services development and deployment, add and modify these properties become more complex. Some services may decline, while some locations may vary. Manually change the properties can be problematic. Eureka service registration and discovery can help in this case. Since all services are registered on the server by calling Eureka Eureka server to complete the look, there is no need to deal with any changes and processing services locations.

Question 4: What is the significance of load balancing?

In computing, load balancing can improve the cross-machine, a variety of computing resources workload cluster of computers, network links, central processing unit or disk drives distribution. Load balancing to optimize resource utilization, maximize throughput, minimize response time and avoid overloading any single resource. A plurality of load balancing components rather than a single component may be used to improve the reliability and availability through redundancy. Load balancing often involves special software or hardware, such as multi-layer switch or domain name system server process.

Question 5: What is Hystrix? How does it achieve fault tolerance?

Hystrix is a delay and fault-tolerant database, designed to isolate remote access point systems, services and third-party libraries, when failure is inevitable failure to stop the cascading failures and to achieve flexibility in complex distributed systems.
Usually for systems using micro-service architecture development, involving many micro-services. These micro-services cooperate with each other.
Consider these micro-services
Here Insert Picture Description
assume that if the figure above 9 micro service fails, using traditional methods we will spread an exception. But this will still cause the entire system to crash.
With the increase in the number of micro service, this problem becomes more complicated. The number of micro-services up to 1000. This is where hystrix appears we will use Hystrix Fallback method function in this case. We have two public service employee-consumer use by the employee-consumer services.
Simplified as shown in FIG.
Here Insert Picture Description
Assuming now that for some reason, employee-producer disclosed in service will throw an exception. We use Hystrix define a fallback method in this case. This backup method should have the same return type of public service. An exception occurred in the service if exposed, the fallback method will return some value.

Question six: What is Hystrix breaker? We need it?

For some reason, employee-consumer public service throws an exception. Use Hystrix In this case we define a fallback method. If an exception occurs in the public service, the fallback method returns some default values.
Here Insert Picture Description
If firstPage method () anomalies continued to occur, Hystrix circuit is interrupted, and the user will staff jumped over firtsPage method, and directly call fallback method. The purpose of the circuit breaker is the first page to the other method or methods that may be called the first page of a method to allow time and cause abnormal recovery. That could happen is that in the case of small loads, resulting in abnormal problems have a better chance of recovery.
Here Insert Picture Description

Seven questions: What is Netflix Feign? What advantage is that?

Feign is subject Retrofit, JAXRS-2.0 and WebSocket inspired java client binder. Feign first goal is to unify the denominator of the complexity of the constraints to http apis, regardless of its stability. In the case of employee-consumer, we use the employee-producer templates using REST REST public service.
But we have to write a lot of code to perform the following steps

  • Use ribbon for load balancing.
  • Examples of access to services, and access to basic URL.
  • Use templates to use REST service. The preceding 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();
 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()); 
 }

Before code, there are exceptions such as NullPointer opportunity, not optimal. We will see how to use Netflix Feign make calls easier and cleaner. If Netflix Ribbon class path dependencies are, then Feign default will be responsible for load balancing.

Question eight: What is Spring Cloud Bus? We need it?

Consider the following situation: We have multiple applications using the Spring Cloud Config read the property, while Spring Cloud Config reads these attributes from GIT.
The following example module producers obtain multiple employees Eureka property registration from Employee Config Module.
Here Insert Picture Description
If it is assumed Eureka property registration GIT in Eureka changed to point to another server, what happens. In this case, we will have to restart the service in order to get updated properties.
There is another way to use actuator endpoint / refresh. But we will have to call this url for each module separately. For example, if the Employee Producer1 deployed on port 8080, a call to http: // localhost: 8080 / refresh . Also for Employee Producer2 http: // localhost: 8081 / refresh , and so on. This is very troublesome. This is where Spring Cloud Bus play.
Here Insert Picture Description
Spring Cloud Bus provides functionality across multiple instances refresh configuration. Thus, in the above example, if we refresh the Employee producerl , it will automatically refresh all the other necessary modules. If we have multiple micro service up and running, which is particularly useful. This is achieved by connecting all the micro-service message to a single Agent. Whenever refresh instances, this event will be a subscription service listens to all this micro-agents, and they will be refreshed. By using endpoint / bus / refresh refresh to achieve any single instance.

Published 74 original articles · won praise 232 · views 20000 +

Guess you like

Origin blog.csdn.net/qq_43107323/article/details/104866862