rest - Camel cxfrs RESTful 客户端/ProducerTemplate ConnectionTimeout

标签 rest apache-camel cxf cxfrs

我正在尝试为 Camel CXF-RS 组件设置“connectionTimeout”here 它在 3rd 方服务上产生 RESTful 请求。默认的 30000 毫秒太长了。

Exchange exchange = template.send("cxfrs://" + url, new Processor() {
 public void process(Exchange exchange) throws Exception {
  exchange.setPattern(ExchangePattern.InOut);
  Message inMessage = exchange.getIn();
  setupDestinationURL(inMessage);
  // using the http central client API
  inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_USING_HTTP_API, Boolean.TRUE);
  // set the Http method
  inMessage.setHeader(Exchange.HTTP_METHOD, "PUT");
  // set the relative path
  inMessage.setHeader(Exchange.HTTP_PATH, url);                
  // Specify the response class , cxfrs will use InputStream as the response                 object type 
  inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_RESPONSE_CLASS, Customer.class);
  // set a customer header
  inMessage.setHeader("key", "value");
  // since we use the Get method, so we don't need to set the message body
  inMessage.setBody(null);                
 }
});

我已经尝试按照许多人的建议将它添加到我们的 application-context 中,但是在通过 HTTPConduitHTTPClientPolicy 调试时看不到它修改默认值 类:

<http-conf:conduit name="*.http-conduit">
  <http-conf:client ConnectionTimeout="5000"/>
</http-conf:conduit>

我试过追加

 "?httpClientAPI=true&connectionTimeout=5000" 

作为 url 字符串的选项。

如有任何帮助或指导,我们将不胜感激。

最佳答案

像您所做的那样在 application-context 中添加 http-conf:conduit 元素是可行的方法。是什么让你说它没有?

建立连接后,后端服务器通常需要很长时间才能响应;在这种情况下,设置 ReceiveTimeoutConnectionTimeout 一样重要。

这是一个消费 RS 请求并调用第三方 RS 服务器的示例 camel Route; ReceiveTimeout 和 ConnectionTimeout 参数按预期工作。

<cxf:rsServer id="rsFrontServer" address="..." serviceClass="..."/>

<cxf:rsClient id="rsBackendClient" address=".../" serviceClass="..."/>

<http-conf:conduit name="*.http-conduit">
    <http-conf:client ReceiveTimeout="5000" ConnectionTimeout="5000"/>
</http-conf:conduit>

<camelContext xmlns="http://camel.apache.org/schema/spring">
    <route id="front">
        <from uri="cxfrs:bean:rsFrontServer"/>
        <!-- do stuff -->
        <to uri="cxfrs:bean:rsBackendClient"/>
    </route>
</camelContext>

关于rest - Camel cxfrs RESTful 客户端/ProducerTemplate ConnectionTimeout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36133777/

相关文章:

java - 无法删除 Camel Quartz 路线

java - 无法使用camel SQL组件连接到mariaDB

java - 在 Apache Camel 中对 null body 的这种处理可以更优雅吗?

java - Json 映射异常无法从 START_ARRAY token 中反序列化实例

java - 使用所需网络适配器的 Web 服务调用

python - Flask-RESTful 如何添加资源并向其传递非全局数据

spring - 如何将 Spring REST 中的图像返回到浏览器

java - 使用 Apache CXF 在 SOAP POST 请求中出错,但 curl 有效

c# - RestSharp 响应返回空

javascript - 浏览器是否支持带有多部分/表单数据的 PUT 请求