zoukankan      html  css  js  c++  java
  • feign结合Hystrix使用

    一导入依赖

    <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
            </dependency>
    
            <!--hystrix依赖,主要是用  @HystrixCommand -->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
            </dependency>
    
            <!--服务注册-->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
            </dependency>
            <!--服务调用-->
           <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-openfeign</artifactId>
            </dependency>

    在配置文件中添加hystrix配置

    #开启熔断机制
    feign.hystrix.enabled=true
    # 设置hystrix超时时间,默认1000ms
    hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=6000

    三在service-edu的client包里面创建熔断器的实现类

    package com.atguigu.eduservice.client;
    
    import com.atguigu.commonutils.R;
    import org.springframework.stereotype.Component;
    
    @Component
    public class VodFileDegradeFeignClient implements VodeClient {
        //删除一个视频,出错之后会执行
        @Override
        public R removeAlyVideo(String id) {
            return R.error().message("视频出错了" );
        }
    }

    四修改VodClient接口的注解

    package com.atguigu.eduservice.client;
    
    import com.atguigu.commonutils.R;
    import org.springframework.cloud.openfeign.FeignClient;
    import org.springframework.stereotype.Component;
    import org.springframework.web.bind.annotation.DeleteMapping;
    import org.springframework.web.bind.annotation.PathVariable;
    
    @Component
    @FeignClient(name = "service-vod",fallback = VodFileDegradeFeignClient.class)
    public interface VodeClient {
    
        @DeleteMapping("/eduvod/video/removeAlyVideo/{id}")
        public R removeAlyVideo(@PathVariable("id") String id);
    }
  • 相关阅读:
    前端模块化开发的价值
    Promise对象
    avalon define新老风格对比
    jQuery知识点1
    SASS
    HTML5
    JSON
    css垂直居中
    maven nexus 部署
    Linux 平台下 lzo和hadoop-lzo安装与集成
  • 原文地址:https://www.cnblogs.com/lzq210288246/p/13304228.html
Copyright © 2011-2022 走看看