Solving the avalanche problem by fusing Hystix

1. Thread isolation, service degradation (degradation by the consumer of the service)

When the service is busy, if there is an exception in the service, it is not a rude direct error report, but a friendly prompt will be returned. Although the user's access is denied, a result will be returned.

It's like going to buy fish. Usually the supermarket will give extra fish killing service. When the Spring Festival is over and busy, fish killing services may not be provided, which is the degradation of services.

When the system is very busy, some secondary services are temporarily interrupted, priority is given to ensuring the smooth flow of main services, and all resources are given priority to the use of main services. In the double 11 and 618, JD tmall will adopt such a strategy.



package cn.itcast.user;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.http.client.OkHttp3ClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

//@Enable circuit breaker / / service meltdown
@SpringCloudApplication //Spring cloud application can replace the above three
public class UserConsumerDemoApplication {

@LoadBalanced //load balancing
public RestTemplate restTemplate() {
// This time, we used the OkHttp client, which only needs to be injected into the factory
return new RestTemplate(new OkHttp3ClientHttpRequestFactory());

public static void main(String[] args) {, args);

Keywords: Java Spring xml OkHttp

Added by shab620 on Thu, 21 Nov 2019 21:45:39 +0200