• spring cloud feign+hystrix


    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;
    	}
    
    
    }
    

      

     

  • 相关阅读:
    PHP的资源类型
    windows 配置 apache的多个站点
    php 压缩数据存储
    php统计图类库JpGraph
    php之ThinkPHP的memcached类的修改
    linux 安装报错:pkg-config not found
    Mysql清空表(truncate)与删除表中数据(delete)的区别
    【MySQL】查看MySQL配置文件路径及相关配置
    phper
    http 同步异步请求
  • 原文地址:https://www.cnblogs.com/zfzf1/p/8552512.html
Copyright © 2020-2023  润新知