Spring-cloud-netflix: Is it possible to set a timeout policy per Feign client method?

Created on 15 Sep 2017  路  14Comments  路  Source: spring-cloud/spring-cloud-netflix

Hi,

I would like to ask if it's possible to set different timeout policies for different methods in the same feign client. Example:

public class MyClient {

@RequestLine("GET /a") // This would have the configuration set in a config file
String getA(@Param("id") String id);

@RequestLine("GET /b")
@HttpConfiguration(readTimeout=100, connectTimeout=50) // This would override the configuration set
String getB(@Param("id") String id);
}

The @HttpConfiguration is just something that I came up with, it does not exist. Does anyone know if this is possible?

question

Most helpful comment

Thanks, @spencergibb! Would a contribution be appreciated in order to support it? If yes, I can create a new issue and we can debate there how it should be implemented.

All 14 comments

Are you using Ribbon as well?

Hi @ryanjbaxter,

I'm not using Ribbon. We could not set HTTP read and connection timeouts properly. The only option we saw was to use the Options class because internally we saw that Feign was ignoring vipAddress + ".ribbon." + Keys.ConnectTimeout and vipAddress + ".ribbon." + Keys.ReadTimeout properties. Then I thought that maybe we could override this Options object somehow but it seems it's not possible.

@joaoqalves Yes, you can set different timeouts for different methods of a Feign client if Hystrix is enabled. Can you please post your feign client?

Hi @indrabasak,

I have the following client:

HystrixFeign.builder()
        .options(getOptions())
        .retryer(getRetryer())
        .target(ApiClientClass.class, clientConfig.getUrl());

Before we had this:

HystrixFeign.builder()
        .client(RibbonClient.create());
        .target(ApiClientClass.class, clientConfig.getUrl());

But somehow using this and the usual properties wasn't working because Feign was overriding the defaults for retrying and using Options to set both connect and read HTTP timeouts. That's why I changed to that approach instead.

So you have what you need now?

@ryanjbaxter

No, I don't. I can set different HTTP timeouts per client but not per method. What I don't understand is [not sure if this is the right place to ask these]:

  1. Why do Feign and Ribbon overlap when the latter is _injected_ in the former?
  2. Even if I could make it work using Ribbon, it's not clear for me how could I use different HTTP timeouts for different methods.

I don't think it's possible to set them per method.

Thanks, @spencergibb! Would a contribution be appreciated in order to support it? If yes, I can create a new issue and we can debate there how it should be implemented.

I'm not sure if it would happen here or at OpenFeign since it might be a lower level enhancement.

any further update on same ?

If there was there would have been an update here

I think it's a useful feature to support different timeout per method, our team also need this feature recently.
I think Request.Options should not only be a property of feign client, but also be a part of MethodMetadata, and a Contract implemention can resolve the Options per method.
feign.Client should use Method Options first, if method options is not provided, then the client will use class level options.

We really need it as well.

This is a limitation of feign. It uses one http client per interface. Please open an issue here https://github.com/openfeign/feign

Was this page helpful?
0 / 5 - 0 ratings