Fourth Circuit breaker (Hystrix)--idea Springcloud All-in-one pro-test available

Source: Internet
Author: User

Write at the beginning

In the Springcloud project, calls are made between services (RPC remote Procedure call-Remote Procedure calls), and when a service that is at the bottom of the calling link becomes unavailable, the request generates a heap that blocks the server thread and even causes the server to crash. A circuit breaker is a way to solve a service unavailability problem.

Body Start

This article is based on the third piece of code, the introduction of circuit breaker is based on the Ribbon type of circuit breaker

Users of new projects can check the following components when building a project

Users who have already built the project can add

    <!--circuit Breaker plug-in        <dependency>            <groupId>org.springframework.cloud</groupId>            <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>        </dependency>

In addition, we need to do a bit of configuration

Application increase

@EnableHystrix

method to add failure annotations

  @RequestMapping (value = "/invokeservice", method = requestmethod.get)  = "Hierror")    public String Invokeservice (@RequestParam (value = "Name") string name) {    System.out.println ("Enter parameter name") : "+ name")    ; = Resttemplate.getforobject ("http://CLOUD-SERVICE/getServiceNameAndPort?name=" + Name, String.  Class);    SYSTEM.OUT.PRINTLN (JSON);     return json;  }

Defining methods when calling a method fails

 Public string Hierror (string name) {    return "--------------Hi," + name + "microservices down--------------"; c5/>}

---------------------------------------------------configuration is complete Let's do two Tests-------------------------------------------------------

1 Start service center, S end, C end

Interface Request HTTP://LOCALHOST:8003/INVOKESERVICE?NAME=TIANMH return result Hello tianmh Serviceport 8001

2 Stop the S-end

Interface Request HTTP://LOCALHOST:8003/INVOKESERVICE?NAME=TIANMH return results--------------hi,tianmh microservices down--------------

Written in the last

This article introduces the circuit breaker, which guarantees the orderly operation of the caller in the event of an exception. In addition, Springcloud provides a graphical management interface for this function, which is presented in the next article.

Fourth Circuit breaker (Hystrix)--idea Springcloud All-in-one pro-test available

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.