Dynamic Feign


License

License

Categories

Categories

Feign Net HTTP Clients
GroupId

GroupId

com.github.linyuzai
ArtifactId

ArtifactId

dynamic-feign
Last Version

Last Version

0.4.0
Release Date

Release Date

Type

Type

jar
Description

Description

Dynamic Feign
Dynamic Feign
Project URL

Project URL

https://github.com/Linyuzai/dynamic-feign
Source Code Management

Source Code Management

https://github.com/Linyuzai/dynamic-feign

Download dynamic-feign

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.linyuzai/dynamic-feign/ -->
<dependency>
    <groupId>com.github.linyuzai</groupId>
    <artifactId>dynamic-feign</artifactId>
    <version>0.4.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.linyuzai/dynamic-feign/
implementation 'com.github.linyuzai:dynamic-feign:0.4.0'
// https://jarcasting.com/artifacts/com.github.linyuzai/dynamic-feign/
implementation ("com.github.linyuzai:dynamic-feign:0.4.0")
'com.github.linyuzai:dynamic-feign:jar:0.4.0'
<dependency org="com.github.linyuzai" name="dynamic-feign" rev="0.4.0">
  <artifact name="dynamic-feign" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.linyuzai', module='dynamic-feign', version='0.4.0')
)
libraryDependencies += "com.github.linyuzai" % "dynamic-feign" % "0.4.0"
[com.github.linyuzai/dynamic-feign "0.4.0"]

Dependencies

runtime (1)

Group / Artifact Type Version
org.springframework.cloud : spring-cloud-starter-openfeign jar

Project Modules

There are no modules declared in this project.

dynamic-feign

implementation 'com.github.linyuzai:dynamic-feign:0.3.1'

@EnableFeignClients替换成@EnableDynamicFeignClients来支持动态配置

动态配置类

public static class ConfigurableFeignClientEntity {
        /**
         * 微服务名称
         */
        private String key;
        /*
         * 格式为http://key,相当于feign的默认实现,支持负载均衡
         */
        private String inUrl;
        /**
         * 指定的url
         */
        private String outUrl;
        /**
         * 是否使用指定outUrl
         */
        private boolean feignOut;
        /**
         * 是否映射方法指定url
         */
        private boolean feignMethod;
        /**
         * 方法与url的映射关系
         */
        private Map<String, String> methodUrls;
        
        /*
         * get set
         * ......
         */
}

动态配置接口

功能 方式 代码 必传字段 其他
查询配置 代码 DynamicFeignClientMapper.getFeignClientEntities();
更新配置 代码 DynamicFeignClientMapper.update(ConfigurableFeignClientEntity); key 只能修改outUrlfeignOutfeignMethod
添加方法对应的url 代码 DynamicFeignClientMapper.addMethodUrl(key, methodName, url); keymethodNameurl 相同的methodName会覆盖
移除方法对应的url 代码 DynamicFeignClientMapper.removeMethodUrl(key, methodName); keymethodName
清空方法对应的url 代码 DynamicFeignClientMapper.clearMethodUrl(key); key
查询配置 接口 /dynamic-feign/config[GET]
更新配置 接口 /dynamic-feign/config[POST] key 只能修改outUrlfeignOutfeignMethod
添加方法对应的url 接口 /dynamic-feign/method-url/add[POST] keymethodNameurl 相同的methodName会覆盖
移除方法对应的url 接口 /dynamic-feign/method-url/remove[POST] keymethodName
清空方法对应的url 接口 /dynamic-feign/method-url/clear[POST] key

@EnableDynamicFeignClients的额外属性

  • @EnableDynamicFeignClients(outUrl = "http/https://ip:port/prefix")用于统一配置outUrl
  • @EnableDynamicFeignClients(feignOut = true)用于统一配置feignOut,为true时需要同时配置outUrl,默认为false
  • @EnableDynamicFeignClients(feignMethod = true)用于统一配置feignMethod,默认为false
  • @EnableDynamicFeignClients(urlConcat = UrlConcat)用于配置outUrl的拼接规则,NONE不拼接,SERVICE_LOWER_CASE拼接小写服务名,SERVICE_UPPER_CASE拼接大写服务名,默认SERVICE_LOWER_CASE
  • @EnableDynamicFeignClients(encoderWrapper = EncoderWrapper)用于配置EncoderWrapper
  • @EnableDynamicFeignClients(decoderWrapper = DecoderWrapper)用于配置DecoderWrapper

配置文件属性

  • 优先级大于@EnableDynamicFeignClients
  • dynamic-feign.out-url可代替@EnableDynamicFeignClients(outUrl = "http/https://ip:port/prefix")
  • dynamic-feign.feign-out可代替@EnableDynamicFeignClients(feignOut = true)
  • dynamic-feign.feign-method可代替@EnableDynamicFeignClients(feignMethod = true)
  • dynamic-feign.encoder-wrapper="com.github.linyuzai.dynamicfeign.wrapper.EncoderWrapper"可代替@EnableDynamicFeignClients(encoderWrapper = EncoderWrapper)
  • dynamic-feign.decoder-wrapper="com.github.linyuzai.dynamicfeign.wrapper.DecoderWrapper"可代替@EnableDynamicFeignClients(decoderWrapper = DecoderWrapper)

Version logs

v0.3.2(unpublished)

  • 将lambda模块移出至单独的项目

v0.3.1

  • 修复0.3.0版本的jar包问题
  • 添加EncoderWrapperDecoderWrapper
  • 支持lambda配置methodUrl

v0.3.0

  • 新增配置文件代替@EnableDynamicFeignClients统一配置outUrlfeignOutfeignMethod
  • 新增根据class获得feign和更新feign
  • 获得feign由通过实例方法改为通过静态方法
  • 修复out复用一直为null的bug
  • 删除@SpringBootApplication避免包名相同重复扫描注解

v0.2.1

  • 新增UrlConcat指定统一outUrl的拼接方式
  • 修复统一outUrl未拼接服务名的bug

v0.2.0

  • 支持注解统一配置所有feign的outUrlfeignOutfeignMethod
  • 复用相同url的feign
  • 如果url格式不标准则修改url,更方便复用

v0.1.0

  • 提供@EnableDynamicFeignClients支持@FeignClient
  • 默认注入服务间负载均衡的feign(inUrl)
  • 支持动态配置feign的额外url(outUrl)
  • 支持方法级别的配置,可通过(methodName,url)来指定每个feign对应方法调用的url

Versions

Version
0.4.0
0.3.1
0.3.0
0.2.1
0.2.0
0.1.0