spring-cloud / spring-cloud/spring-cloud-openfeign
Support lb:// url in FeingClient annotation
@OlgaMaciaszek is already working on this.
Since Feb 25, 2021.
- Dominant language
- Java
- Stars
- 1.3k
- Forks
- 838
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 13
Description
Current behaviour
In a project where is used spring cloud gateway, feign client (with target put in configuration), we ended up having feign clients declared as follows
@FeignClient(name="${service.name:any-name}", url="${service.direct-url:}")
With configuration as follows
service:
name: service-id
# url: http://direct-url (only used when service discovery is not available)
This way we are able, by configuration, to either run in service discovery/load balancing mode and direct mode.
Proposal
I kind of like the way spring cloud gateway handle that by allowing lb:// protocol. Allowing this protocol in url attribute would allow the following implementation
@FeignClient(name="technical-name", url="${service.uri}")
with following configuration
service:
uri: "lb://service-id" # or "http//direct-url"
this way it will let common behaviour, allowing to have a common behaviour in url specification.
I spotted the code responsible for feign client building and think that it would be easily doable by
- only appending
http://ifurlattribute value does not match the[a-z]+://.*pattern - remove load balancing client if and only if
urlattribute does not starts withlb://
I am eager to implement it if you allow me to do so. I am also pleased to discuss about it and about any alternative I missed.
Thank you
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.