首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >cxfrs client / ProducerTemplate ConnectionTimeout

cxfrs client / ProducerTemplate ConnectionTimeout
EN

Stack Overflow用户
提问于 2016-03-21 14:30:42
回答 1查看 1.6K关注 0票数 3

我试图为Camel CXF组件这里设置“RESTful”,它在第三方服务上生成RESTful请求。默认的30000毫秒是长的。

代码语言:javascript
复制
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类进行调试时看不到它修改默认值:

代码语言:javascript
复制
<http-conf:conduit name="*.http-conduit">
  <http-conf:client ConnectionTimeout="5000"/>
</http-conf:conduit>

我已经试过了

代码语言:javascript
复制
 "?httpClientAPI=true&connectionTimeout=5000" 

作为url字符串的选项。

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

EN

回答 1

Stack Overflow用户

发布于 2016-03-21 21:54:17

像您所做的那样,在http-conf:conduit中添加application-context元素是可行的,并且应该能够工作。你凭什么说它没有?

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

这是一个示例camel路由,它使用RS请求并调用第三方RS服务器;ReceiveTimeout和ConnectionTimeout参数按预期工作。

代码语言:javascript
复制
<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>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36133777

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档