迁移声明式 REST 客户端至 Kubernetes 配置

huangapple go评论62阅读模式
英文:

Migrating declarative REST client to Kuberentes config

问题

我必须将一个 Spring Cloud 项目迁移到 Kubernetes 部署上。这意味着需要移除对网关、配置服务器、发现服务器等的依赖。然而,我想保留的部分是由 Spring Cloud OpenFeign 提供的声明式 REST 客户端,以避免为服务间通信编写客户端实现。

我想出的解决方案大致如下:

@FeignClient(name = "useless", url = "http://${product.service.url:localhost:3333}")
public interface ProductApiFeign extends ProductApi {}

其中 product.service.url 是 Kubernetes 服务的名称和端口,而 name 只是一个任意的字符串值,因为验证否则不会让我运行程序。ProductApi 是一个由 Swagger 生成的带有特定注解的接口。

我部署了这个解决方案,它按预期工作。

问题是:有没有更好的方法来实现基于注解接口的声明式 REST 客户端,而无需包含 Spring Cloud 依赖?我必须包含 name 值是否会对我产生任何负面影响?欢迎任何建议。

英文:

I have to migrate a spring-cloud project to a Kubernetes deployment. That would mean removing dependencies for gateway, config server, discovery server and so on. However, one part that I would like to keep is the declarative REST client provided by spring-cloud open feign so that I would avoid writing a client implementation for inter-service communication.

The solution that I came up with looks something like this:

@FeignClient(name = "useless", url = "http://${product.service.url:localhost:3333}")
public interface ProductApiFeign extends ProductApi {}

product.service.url is the Kubernetes Service name and port, whereas name is just an arbitrary string value because the validation wouldn't let me run the program otherwise. ProductApi is a Swagger generated interface with its specific annotations.

I deployed this and it works as expected.

The questions being: is there a better way to implement a declarative REST client based on an annotated interface, without having to include the spring-cloud dependency? Does the fact that I have to include the name value affect me in any negative way? Any suggestions would be welcome.

答案1

得分: 1

OpenFeign可以在没有Spring Cloud的情况下工作,但是@FeignClient以及对于Spring注解(@RequestMapping@GetMapping等)的支持仅由spring-cloud-openfeign提供。

英文:

OpenFeign works without spring cloud, but @FeignClient and support for Spring annotations (@RequestMapping, @GetMapping, etc...) are only provided by spring-cloud-openfeign.

huangapple
  • 本文由 发表于 2020年4月10日 18:37:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/61138508.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定