• spring cloud: Hystrix(四):feign类似于hystrix的断容器功能:fallback


    spring cloud: Hystrix(四):feign使用hystrix

    @FeignClient支持回退的概念:fallback方法,这里有点类似于:@HystrixCommand(fallbackMethod = "notfindback")的fallbackMethod 方法。

    fallback方法调用的是一个类.,feign也有:/health, /health.stream地址信息

    http://192.168.1.4:7601/health

    1.首先要在配置件开启hystrix配置

    #feign.hystrix
    feign.hystrix.enabled=true
    

      

    或者

    feign:
      hystrix:
        enabled: true
    

      

    2.在FeignClient客户端文件添加fallback

    @FeignClient(name="spring-boot-user", fallback=HystrixClientFallback.class)
    public interface UserFeignClient {
    
    	// 两个坑:1. @GetMapping不支持   2. @PathVariable得设置value
    	@RequestMapping(value="/simple/{id}", method=RequestMethod.GET)
    	public User findById(@PathVariable("id") Long id);
    	
    
    }
    

      

    3.HystrixClientFallback友好文件(当feignClient地址不通是,默认返回本类信息)

    @Component
    public class HystrixClientFallback  implements UserFeignClient{
    
    	@Override
    	public User findById(Long id) {
    		// TODO Auto-generated method stub
    		User user = new User();
    		user.setId(0L);
    		return user;
    	}
    
    }
    

      

    4.controller调用

    @RestController
    public class MovieController {
    
    	@Autowired
    	private UserFeignClient userFeignClient;
    	
    	@GetMapping("/movie/{id}")
    	public User findById(@PathVariable("id") Long id) {
    		return this.userFeignClient.findById(id);
    	}
    	
    	
    }
    

      

  • 相关阅读:
    大哥带的MSsql注入(SQL Server)--预习
    大哥带我们的mysql注入 基于时间的盲注
    大哥带我们的mysql注入 基于bool的盲注
    sqli-labs(22)
    sqli-labs(21)
    sqli-labs(20)
    sqli-labs(19)
    kali文件执行的权限不够解决办法
    DVWA--XSS(反射型)
    Updatexml函数再mysql中的作用
  • 原文地址:https://www.cnblogs.com/achengmu/p/9846464.html
Copyright © 2020-2023  润新知