Men*_*los 10 java spring-cloud netflix-feign spring-cloud-feign feign
我最近使用netflix假装和功能区非常有用.
一个例子是:
@FeignClient(name = "ldap-proxy")
public interface LdapProxyClient {
@RequestMapping(path = "/ldap-proxy/v1/users/{userNameOrEMail}", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET)
LdapUser search(@PathVariable("userNameOrEMail") String userNameOrEMail);
}
Run Code Online (Sandbox Code Playgroud)
但是,在某些时候,我认为不必手动编写所有这些定义(对于现有的Web服务),我应该看看是否存在工具.
我偶然发现了https://github.com/swagger-api/swagger-codegen一些客户端生成的例子,例如https://github.com/swagger-api/swagger-codegen/tree/master/samples/client/petstore/java/feign.
但是,一旦我仔细查看了进口,我注意到以下情况:
import feign.Feign;
另一方面,Netflix的开源解决方案有包名:
org.springframework.cloud.netflix.feign.
另外,我注意到两者都使用功能区(如果可用),但Netflix的表示法更加清晰,后台发生了很多事情.例如,@FeignClient注释类javadoc声明:
- 接口的注释声明应该*创建具有该接口的REST客户端(例如,用于自动装配到另一个组件中).如果功能区可用,它将*用于对后端请求进行负载平衡,并且可以使用
@RibbonClient与feign客户端具有相同名称(即值)的a来配置负载均衡器.
但是在Feign.feign文档中(https://github.com/OpenFeign/feign),我看到:
RibbonClient覆盖了Feign客户端的URL解析,添加了Ribbon提供的智能路由和弹性功能.
集成要求您将功能区客户端名称作为URL的主机部分传递,例如myAppProd.
> MyService api =
> Feign.builder().client(RibbonClient.create()).target(MyService.class,
> "https://myAppProd");
Run Code Online (Sandbox Code Playgroud)
它们是完全不同的项目,没有关系,或者netflix只是分叉/利用OpenFeign并将其修改为在其集成云解决方案中?从本质上讲,netflix是否只是从开源项目中获取并集成了Discovery,Ribbon和feign等不同技术?
Pau*_*son 14
"Netflix feign"是旧项目的名称.最后一个版本(以下依赖项)日期为2016年7月.
compile group: 'com.netflix.feign', name: 'feign-core', version:'8.18.0' // OLD
Run Code Online (Sandbox Code Playgroud)
"开放式假装"是新项目的名称.它是同一个项目,但被转移到另一个git repo并获得了一个新的group-id.它的版本从9.0.0开始.
compile group: 'io.github.openfeign', name: 'feign-core', version: '10.0.1' // NEW
Run Code Online (Sandbox Code Playgroud)
有关所发生情况的简要历史,请参阅此github问题.最值得注意的是,你会发现Feign不再在Netflix内部使用了.:^ o
Eie*_*ien 12
org.springframework.cloud.netflix.feign是Spring Cloud Netflix项目的一部分,该项目是Spring Cloud的一部分.
Spring Cloud使用OpenFeign.它扩展了它以支持Spring MVC注释,并通过自动配置为Spring Boot应用程序提供集成,使其成为Spring环境中的一流公民.
从文档:
Feign是一个声明性的Web服务客户端.Spring Cloud增加了对Spring MVC注释的支持,并使用了Spring Web中默认使用的相同HttpMessageConverters.Spring Cloud集成了Ribbon和Eureka,在使用Feign时提供负载均衡的http客户端.
请注意,在文档中有一个指向OpenFeign项目的链接.
因此,如果您使用Spring Boot,则使用Spring Cloud OpenFign集成会更好,更容易.
另请参阅源代码.
| 归档时间: |
|
| 查看次数: |
8758 次 |
| 最近记录: |