简体   繁体   English

如何在 Feign 客户端中为 API 设置单独的不同读取超时?

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

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?我在我的 spring 引导应用程序中使用假装客户端,我想为不同的调用配置单独的超时,例如,如果我有更新和创建调用,我想为更新 = 3000 和创建 =12000 设置读取超时,我怎么能去做?

@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:我的服务 class 是:


    public class  MyService {
    .
    .
    productCreationResponse = productClient.productCreationExternalRequest(productCreationRequest);
    ..
    productupdateResponse = productClient.productUpdateExternalRequest(productCreationRequest);
    
    }

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM