骆驼cxfrs RESTful客户端/ProducerTemplate ConnectionTimeout [英] Camel cxfrs RESTful client / ProducerTemplate ConnectionTimeout
问题描述
我正在尝试为Camel CXF-RS组件设置'connectionTimeout'此处在第三方服务上产生一个RESTful请求.默认的30000
毫秒为long.
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
中,但是在通过HTTPConduit
和HTTPClientPolicy
类进行调试时看不到它修改了默认值:
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"
作为网址字符串的选项.
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?
通常,后端服务器在建立连接后 花费的时间太长.在这种情况下,设置ReceiveTimeout
与ConnectionTimeout
同样重要.
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服务器. 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>
这篇关于骆驼cxfrs RESTful客户端/ProducerTemplate ConnectionTimeout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!