How to make seperate different read timeout for APIs in feign client?

1.1k views Asked by At

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);
    
    }
1

There are 1 answers

0
E.H. On

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));