Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change the feign URL during the runtime?

@FeignClient(name = "test", url="http://xxxx")

How can I change the feign URL (url="http://xxxx") during the runtime? because the URL can only be determined at run time.

like image 428
liucyu Avatar asked May 02 '17 08:05

liucyu


People also ask

How do you use dynamic URL in feign client?

Feign has a way to provide the dynamic URLs and endpoints at runtime. The following steps have to be followed: In the FeignClient interface we have to remove the URL parameter. We have to use @RequestLine annotation to mention the REST method (GET, PUT, POST, etc.):

Is feign client synchronous or asynchronous?

Synchronous and Asynchronous API callsThe API that we defined via Feign is synchronous — meaning that it makes blocking calls to the server. Feign allows us to easily define async APIs as well — utilizing CompletableFutures under the hood.

Which is better feign or RestTemplate?

One of the advantages of using Feign over RestTemplate is that, we do not need to write any implementation to call the other services. So there is no need to write any unit test as there is no code to test in the first place.


1 Answers

You can add an unannotated URI parameter (that can potentially be determined at runtime) and that will be the base path that will be used for the request. E.g.:

    @FeignClient(name = "dummy-name", url = "https://this-is-a-placeholder.com")     public interface MyClient {         @PostMapping(path = "/create")         UserDto createUser(URI baseUrl, @RequestBody UserDto userDto);     } 

And then the usage will be:

    @Autowired      private MyClient myClient;     ...     URI determinedBasePathUri = URI.create("https://my-determined-host.com");     myClient.createUser(determinedBasePathUri, userDto); 

This will send a POST request to https://my-determined-host.com/create (source).

like image 138
asherbret Avatar answered Sep 25 '22 06:09

asherbret