Giter Club home page Giter Club logo

openfeign-strengthen-plugin's Introduction

openfeign-strengthen-plugin

顾名思义这是一个关于openfeign客户端的强化插件

本插件的作用在于 补全openfeign客户端在使用的默认代理和 Sentinel 代理 的过程中无法自定义单个接口或者单个方法级别的超时时间与重试的插件

本插件的优先级为:

服务消费者method配置 > 服务提供者method > 服务消费者interface级配置 > 服务提供者interface级配置 > 服务消费者全局配置

注意:重试以服务提供者注解标识为最高优先级

服务提供方 maven 引用:

            <dependency>
                <groupId>org.example</groupId>
                <artifactId>openfeign-strengthen-plugin-annotation</artifactId>
                <version>1.0-SNAPSHOT</version>
            </dependency>

java 代码书写方式(服务提供方使用注解形式):

            /**
             * 注解放在 interface 上,则该 interface 下所有的方法 共享该配置
             */
            @RpcInfo(connectTimeout = 2,connectTimeoutUnit = TimeUnit.SECONDS, readTimeout = 1, readTimeoutUnit = TimeUnit.SECONDS, followRedirects = false)
            public interface MemberService {
            
                /**
                 * 注解放在 method 上
                 * 则该 method  RPC调用 时使用该配置。
                 * 方法上的配置优先级大于 interface 级别,
                 * 同时存在时,以 method 上的为准
                 * connectTimeout 连接超时时间
                 * connectTimeoutUnit 连接超时时间的单位 默认为毫秒
                 * readTimeout 读取超时时间
                 * readTimeoutUnit 读取超时时间单位 默认为毫秒
                 * followRedirects 是否重定向 默认为否
                 * maxAutoRetriesNextServer 切换实例的重试次数 默认为 0 次 禁止重试
                 * maxAutoRetries 对当前实例的重试次数 默认为 0 次 禁止重试
                 * isAllowedRetry 是否允许重试 默认为 false 不允许
                 */
                @RequestMapping("/getUsers")
                @RpcInfo(connectTimeout = 2,connectTimeoutUnit = TimeUnit.SECONDS, 
                        readTimeout = 1, readTimeoutUnit = TimeUnit.SECONDS, followRedirects = false, 
                        maxAutoRetriesNextServer = 1, maxAutoRetries = 1, isAllowedRetry = true)
                List<User> getUsers(String name);
            
                @PostMapping(value = "/uploadFile", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
                @RpcInfo(connectTimeout = 5,connectTimeoutUnit = TimeUnit.SECONDS, readTimeout = 2, readTimeoutUnit = TimeUnit.SECONDS)
                String handleFileUpload(@RequestPart(value = "file") MultipartFile file);
            }

服务消费者引入 maven 依赖:

        <dependency>
             <groupId>org.example</groupId>
             <artifactId>openfeign-strengthen-plugin-start</artifactId>
             <version>1.0-SNAPSHOT</version>
        </dependency>

服务消费者方使用 application.yml 配置的形式使用,并且服务消费者超时时间配置优先级高于服务提供方配置

  feign:
    client:
      rpcConfig:
        #单个方法维度的配置
        #接口名称 + # + 方法名称 + (参数类型, 参数类型...)
        #包名 + 接口名称 + # + 方法名称 + (参数类型, 参数类型...) com.huihuang.service.MemberService#getUsers(String)
        MemberService#getUsers(String):
          connectTimeout: 1 #连接超时
          connectTimeoutUnit: SECONDS #超时时间单位
          readTimeout: 1 #读取超时
          readTimeoutUnit: SECONDS
          followRedirects: false #是否允许重定向
          maxAutoRetries: 2 # 对当前实例的重试次数
          maxAutoRetriesNextServer: 1 # 切换实例的重试次数
        #按接口维度配置 优先级低于 单个方法维度的配置
        #接口名称
        #包名 + 接口名称 com.huihuang.service.MemberService
        MemberService:
          connectTimeout: 1 #连接超时
          connectTimeoutUnit: SECONDS #超时时间单位
          readTimeout: 1 #读取超时
          readTimeoutUnit: SECONDS
          followRedirects: false #是否允许重定向
          maxAutoRetries: 2 # 对当前实例的重试次数
          maxAutoRetriesNextServer: 1 # 切换实例的重试次数
        #全局维度配置 优先级低于 单个方法维度 和 接口维度 的配置
        default:
          connectTimeout: 1 #连接超时
          connectTimeoutUnit: SECONDS #超时时间单位
          readTimeout: 1 #读取超时
          readTimeoutUnit: SECONDS
          followRedirects: false #是否允许重定向
          maxAutoRetries: 2 # 对当前实例的重试次数
          maxAutoRetriesNextServer: 1 # 切换实例的重试次数

openfeign-strengthen-plugin's People

Contributors

raidenxin avatar

Stargazers

 avatar

Watchers

 avatar  avatar

openfeign-strengthen-plugin's Issues

自动装配

image

自动装配这块为什么要这么,不大懂。 有相关学习资料推荐吗?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.