SpringCloud entry 4 --- Hystrix (fuse assembly)

SpringCloud Getting Started 1 Introduction ---

SpringCloud entry 2 --- Eureka (service discovery component)

SpringCloud Getting Started 3 --- Feign (service call component)

SpringCloud entry 4 --- Hystrix (fuse assembly)

SpringCloud entry-5 --- Zuul (Serving Gateway)

Title IV, we do the right SpringCloud in Hystrix (fuse assembly) a brief description:

1. Why use a fuse

       Here we must first understand what is at the service avalanche effect ? In the micro-services architecture usually have multiple service layer calls, failure of basic services could lead to cascading failures, and cause the entire system is unavailable, a phenomenon called avalanche effect service. Services avalanche effect is a result of "service provider" of unavailability "service consumer" is not available and unavailable gradually enlarge the process.

       If it is shown below: as a service provider A, B is the service consumer A, C and D are B Service Consumers. A Not available due to unusable B, and is not available to an enlarged snowball C and D, the avalanche effect is formed.

   How to avoid this avalanche effect it? We can use Hystrix be achieved fuse.

2, Hystrix Profile

Hystrix [hɪst'rɪks] the Chinese meaning porcupine, its back covered with thorns, and have the ability to protect themselves.

Hystrix make your system dependent services in times of failure, by isolation system relies on service, service to prevent cascading failures, while providing a fallback mechanism fails, the failure to respond more gracefully and make your system more quickly recover from the exception.
Learn fuse mode see below:


 

4, Hystrix integration

Feign itself supports Hystrix, there is no need to introduce additional dependent.

  (1) modified tensquare_qa module application.yml, open hystrix

feign:
  hystrix:
    enabled: true

  (2) create a packet at com.test.client impl package, the package created fuse implementation class, from the interface to realize LabelClient 

@Component
public class TestClientImpl implements TestClient {

    @Override
    public Result findById(String id) {
        return new Result(false, StatusCode.ERROR,"熔断器启动了");
    }
}

  (3) modify TestClient comments 

@FeignClient(value="test‐base",fallback = TestClientImpl.class)

  (4) Test Run

Restart micro-services, test to see if the fuse start, postman test returns fuse content Result (false, StatusCode.ERROR, "Fuse started").

So far the fuse has been introduced Hystrix completed, simply is a circuit breaker in order to prevent the emergence of avalanche server, similar to fuse the gates of home appliances in order to prevent the collapse of the entire circuit is damaged.

 

Published 41 original articles · won praise 47 · views 30000 +

Guess you like

Origin blog.csdn.net/u014526891/article/details/87447406