spring-cloud-netflix icon indicating copy to clipboard operation
spring-cloud-netflix copied to clipboard

Request to expose the Targeter interface in feign client

Open nani3105 opened this issue 10 years ago • 5 comments

I have a requirement where i have to wire in a custom targeted. Exposing this interface would be great

nani3105 avatar Oct 14 '16 23:10 nani3105

Can you tell me why you think you need a custom Targeter?

spencergibb avatar Oct 15 '16 04:10 spencergibb

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

nani3105 avatar Oct 17 '16 04:10 nani3105

Examples always help.

ryanjbaxter avatar Oct 17 '16 10:10 ryanjbaxter

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

nani3105 avatar Oct 18 '16 15:10 nani3105

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.

spencergibb avatar Oct 18 '16 21:10 spencergibb