spring cloud第四步: 断路器Hystrix(基于fein)

编程入门 行业动态 更新时间:2024-10-04 17:20:39

spring cloud第四步: <a href=https://www.elefans.com/category/jswz/34/1751155.html style=断路器Hystrix(基于fein)"/>

spring cloud第四步: 断路器Hystrix(基于fein)

一、Feign是自带断路器的,只需在yml配置文件加以下代码:


feign:
  hystrix:
    enabled: true




二、基于前面第三步中feign_test工程进行改造,只需要在IHiService接口的注解中加上fallback的指定类就行了


@FeignClient(value = "serviceHii" ,fallback = HiServiceHystric.class)
public interface IHiService {
    @RequestMapping(value = "/hi",method = RequestMethod.GET)
    String sayHii(@RequestParam(value = "name") String name);
}


三、新增HiServiceHystric实现类,需要实现IHiServcie接口


@Component
public class HiServiceHystric implements IHiService {
    @Override
    public String sayHii(String name) {
        return  "Sorry,"+name+",server is disconnect!";
    }
}


四、关闭服务提供者serverHi工程,启动feign_test工程,浏览器打开http://localhost:8765/hello?name=czy,网页显示:

Sorry,czy,server is disconnect!


打开service-hi工程,再次访问,浏览器显示:

hi czy(from port:7072)


这就证明断路器起作用了。
 
 
          

更多推荐

spring cloud第四步: 断路器Hystrix(基于fein)

本文发布于:2024-02-28 04:08:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1767897.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:断路器   第四步   cloud   spring   Hystrix

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!