0

I got a problem to solve with Spring FeignClient.

I have two endpoints to send an SMS, both are the same behavior:

  • When I send a GET with all query parameters required, the service sends the SMS.
  • But I need to check if endpoint A is off – in which case I must send to endpoint B, both with the same request path and payload.

How can I solve this problem?

Today I have an interface with FeignClient annotation and just one URL.
I tried to make use a FeignBuilder to create the request in runtime and change the URL but without success.

How can I use Feign to control service fallback in client side, like:

@Value(${sms.urls})
List<String> endPoints;

for (endPoint : endPoints){
  if(endPoint.isUp())
  return makeRequest(endPoint).
}
vzsg
  • 2,831
  • 17
  • 20
Rodrigo Sene
  • 309
  • 1
  • 13

1 Answers1

1

With regards to using FeignBuilder, maybe you can find an answer to your problem here

If this doesn't work, I would suggest creating a wrapper class around the interface.
When I had to deal with such a problem in the past I simply created a class that uses the Feign client interface. Spring will handle the wiring for you based on the fact that you annotated your feign client with the @FeignClient annotation. This way you can modify the behavior from the wrapper class. You'd write your fallback logic in a method and call the feign client as needed.

Hope this helps

Joud C
  • 427
  • 3
  • 6
  • 1
    I found link that make easy to implement a fallback function: https://github.com/OpenFeign/feign/pull/308/files But now when i try to call Feign with builder: HystrixFeign.builder() .contract(new SpringMvcContract()) .target(AtlasFeignClient.class, this.url); Feign cannot parse the application.propertie value configured in spring config, they send a request for unparsed url like method: get url: /${some.propertie} – Rodrigo Sene Nov 14 '17 at 16:59
  • Thanks for the link! I wonder if you tried to use Spring (without Feign, using @Value("config_name")) to retrieve the config and then inject them in the Feign builder manually, maybe it could work? Just a suggestion. – Joud C Nov 15 '17 at 15:26