Spring Cloud学习笔记:Hystrix使用

基础配置

开发工具 :IDEA
MAVEN :3.6
JDK : 1.8
Spring boot :1.5.9.RELEASE
Spring cloud : Edgware.RELEASE

pox配置信息

 		<dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
        </dependency>
在上的篇基础上给cloud_client2添加熔断回掉
  1. 给cloud_client2的pox中添加上述配置信息
  2. application.properties,中添加:
feign.hystrix.enabled=true
  1. 接口CloudClient1Feign的@FeignClient中添加fallback = “接口的实现”
package com.cloud.client2.feign;

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@FeignClient(name = "cloud-client1",fallback = CloudClient1Hystrix.class)
public interface CloudClient1Feign {

   @RequestMapping(value = "/show/hello",method = RequestMethod.GET)
   String  showHello();
   @RequestMapping(value = "/show/noHello",method = RequestMethod.GET)
   String  showNoHello();

}
  1. 接口CloudClient1Feign的实现方法,返回自己设置的参数
package com.cloud.client2.feign;

import org.springframework.stereotype.Component;

@Component
public class CloudClient1Hystrix implements CloudClient1Feign {
    @Override
    public String showHello() {
        return "get show Hello,回掉了";
    }

    @Override
    public String showNoHello() {
        return "get no show hello,回掉了";
    }
}

分别启动cloud_eureka,cloud_client1,cloud_client2,按上篇操作进行,Feign的调用没问题后,关闭cloud_client1
再次访问http://localhost:8082/to/getShow
在这里插入图片描述

得到的接口实现中的内容

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值