1

I am using feign client in my spring boot application and I want to configure separate timeouts for different calls for example if I have update and create calls and I want to set read time out for update = 3000 and for create =12000, how can I do that?

@FeignClient(name = "product-service")
public interface ProductClient {

    @PostMapping(value = "/product/create")
    public ProductCreation productCreationExternalRequest(@RequestBody ProductCreationRequest productCreationRequest);
    
    @PostMapping(value = "/product/update")
    public ProductCreation productUpdateExternalRequest(@RequestBody ProductCreationRequest productCreationRequest );
    
}

My service class is :


    public class  MyService {
    .
    .
    productCreationResponse = productClient.productCreationExternalRequest(productCreationRequest);
    ..
    productupdateResponse = productClient.productUpdateExternalRequest(productCreationRequest);
    
    }
Mr.Fix
  • 35
  • 1
  • 8
  • 1
    Does this answer your question? [How to solve Timeout FeignClient](https://stackoverflow.com/questions/38080283/how-to-solve-timeout-feignclient) – Andrei Kovrov Oct 12 '20 at 23:06
  • Add a configuration class definning two beans of '@Bean public Request.Options options() { return new Request.Options(connectTimeOutMillis, readTimeOutMillis); }' – Hilmi Reda Oct 13 '20 at 07:42
  • @hilmi can you explain ,it,,,means how i can i bring it in my case – Mr.Fix Oct 13 '20 at 09:58
  • There is on way : 1- separate productCreationExternalRequest & productUpdateExternalRequest in separated two feign clients(each feign client use its own configuration '@FeignClient(value = "product-service", configuration = UpdateFeignConfig.class, fallbackFactory = UpdatetFallbackFactory.class, url = "")'class that define the read time out ) that reference two services that its not the standard so i think that your need is not applicable for this purpose .. – Hilmi Reda Oct 13 '20 at 10:55

1 Answers1

0

You can do it by sending options parameter as argument of you feign methods:

@FeignClient(name = "product-service")
public interface ProductClient {
    @PostMapping(value = "/product/create")
    ProductCreation productCreationExternalRequest(ProductCreationRequest productCreationRequest, Request.Options options);

    @PostMapping(value = "/product/update")
    ProductCreation productUpdateExternalRequest(ProductCreationRequest productCreationRequest, Request.Options options);
}

And then use your methods like next:

productClient.productCreationExternalRequest(new ProductCreationRequest(), new Request.Options(300, TimeUnit.MILLISECONDS,
           1000, TimeUnit.MILLISECONDS, true));
productClient.productUpdateExternalRequest(new ProductCreationRequest(), new Request.Options(100, TimeUnit.MILLISECONDS,
           100, TimeUnit.MILLISECONDS, true));
E.H.
  • 326
  • 1
  • 7