Search code examples
javaspringspring-cloudspring-cloud-feign

Migrating declarative REST client to Kuberentes config


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.


Solution

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