码迷,mamicode.com
首页 > 编程语言 > 详细

spring cloud feign+hystrix

时间:2018-03-13 01:10:32      阅读:208      评论:0      收藏:0      [点我收藏+]

标签:string   AC   nts   hystrix   local   class   print   localhost   server   

server:
  port: 8081
spring:
  application:
    name: spring-hy-sale
feign:
  hystrix:
    enabled: true
hystrix:
  command:
    HelloClient#toHello():
      execution:
        isolation:
          thread: 
            timeoutInMilliseconds: 500
      circuitBreaker:
        requestVolumeThreshold: 3
eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/

 

@FeignClient(name = "spring-hy-member", fallback = HelloClientFallback.class)
public interface HelloClient {

	@RequestMapping(method = RequestMethod.GET, value = "/hello")
	public String hello();
	
	@RequestMapping(method = RequestMethod.GET, value = "/toHello")
	public String toHello();
}

  

@Component
public class HelloClientFallback implements HelloClient {

	public String hello() {
		return "fallback hello";
	}

	public String toHello() {
		return "fallback timeout hello";
	}

}

  

@RestController
public class FeignController {
	
	@Autowired
	private HelloClient helloClient;

	@RequestMapping(method = RequestMethod.GET, value = "/hello")
	public String hello() {
		return helloClient.hello();
	}
	
	@RequestMapping(method = RequestMethod.GET, value = "/toHello")
	public String toHello() throws InterruptedException {
		Thread.sleep(500);
		String result = helloClient.toHello();
		HystrixCircuitBreaker breaker = HystrixCircuitBreaker.Factory
				.getInstance(HystrixCommandKey.Factory
						.asKey("HelloClient#toHello()"));	
		System.out.println("断路器状态:" + breaker.isOpen());
		return result;
	}


}

  

 

spring cloud feign+hystrix

标签:string   AC   nts   hystrix   local   class   print   localhost   server   

原文地址:https://www.cnblogs.com/zfzf1/p/8552512.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!