Request to expose the Targeter interface in feign client
I have a requirement where i have to wire in a custom targeted. Exposing this interface would be great
Can you tell me why you think you need a custom Targeter?
I have a requirement where in we have to resolve the url based of a String passed in the interface method. Feign only allows URI as the parameter. So I wrote a custom target to do so. By using spring cloud i have to implement the targeted to wire in my custom target. I can provide an example if you like
Examples always help.
This is the use case:
We are generating feign client using swagger code gen to communicate with a thrid party apis.
We want to to use spring-cloud to register these as bean with spring . At this point we are not using hystrix nor ribbon, so i have excluded those dependencies for the autoconfiguration to not kick in.
But we need dynamic resolution of the url based on the product we passed to the interface methods.
For each product we have map to different baseurl likewise
foo -> http://foo.com bar -> https://bar.com
Ex:
@FeignClient("foo")
public interface FooApi {
@RequestLine("POST /foo/dosomething")
@Headers({"Content-type: application/json", "Accept: application/json"})
Foo doSomething(@Product product ,Bar var1);
}
For this i have created a contract which takes the product string and treats it like a url and appends it to the request.
I also created a custom Target, which see the product and consults a map to replace it with the acutal URL in the apply method.
At this point , i would copy the encoder , decoder, feign registar code to my codespace and implement this logic.
But i want to leverage the work done in spring-cloud but i need to wire in this custom Target via the targeter interface
The way to use feign without ribbon or eureka is as follows:
@FeignClient(name="foo", url="${foo.url}")
public interface FooApi {
//...
}
You can set foo.url at runtime with normal boot properties.