Camel cxfrs RESTful 客户端/ProducerTemplate ConnectionTimeout [英] Camel cxfrs RESTful client / ProducerTemplate ConnectionTimeout

查看:21
本文介绍了Camel cxfrs RESTful 客户端/ProducerTemplate ConnectionTimeout的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to set the 'connectionTimeout' for a Camel CXF-RS component here which produces a RESTful requests on a 3rd party service. The default 30000 miliseconds is to long.

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 调试时看不到它修改默认值 类:

I have tried adding this to our application-context as many have suggested, but cannot see it modifying the default values when debugging through the HTTPConduit and HTTPClientPolicy classes:

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

我已经尝试附加

 "?httpClientAPI=true&connectionTimeout=5000" 

作为 url 字符串的选项.

as options to the url string.

任何帮助或指导将不胜感激.

Any help or guidance would be much appreciated.

推荐答案

像您一样在 application-context 中添加 http-conf:conduit 元素是去,应该工作.是什么让你说它没有?

Adding the http-conf:conduit element in application-context as you did is the way to go and should work. What makes you say it does not?

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

Quite often a backend server take too long to answer, after the connection is made; in this case setting ReceiveTimeout is as important as ConnectionTimeout.

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

This is a sample camel Route which consumes RS requests and calls a third-party RS server; the ReceiveTimeout and ConnectionTimeout parameters work as expected.

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

这篇关于Camel cxfrs RESTful 客户端/ProducerTemplate ConnectionTimeout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆