sprinboot系列八——微服务二——Ribbon使用hystrix熔断

继续用上文testBoot这个项目

pom

        <!-- hystrix 熔断器-->
        <dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
		</dependency>

java

启动类新增注解

//服务熔断
@EnableHystrix

编写callback函数

    @HystrixCommand(fallbackMethod = "fallback")
    @RequestMapping(value = "/getH" ,method = RequestMethod.GET)
    public String testGetNameOfBlogWithHistrix(){
        String url="http://ONE-MILLION/one-million-dev/redisTest1";
        
        return restTemplate.getForObject(url,String.class);
    }
    
    public String fallback()
    {
        return "fallback";
    }

http://ONE-MILLION/one-million-dev/redisTest1 不存在,则抛出错误,进行回调处理
sprinboot系列八——微服务二——Ribbon使用hystrix熔断