2016-03-21 82 views
3

我想設置一個駱駝CXF-RS組件here的'connectionTimeout',它在第三方服務上產生一個RESTful請求。默認的30000毫秒是很長的。駱駝cxfrs RESTful客戶端/ ProducerTemplate ConnectionTimeout

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字符串的選項。

任何幫助或指導將不勝感激。

回答

1

http-conf:conduit元素添加到application-context中,就像您所做的那樣是要走的路,並且應該有效。是什麼讓你說它不是?

很多時候後端服務器花費很長時間回答,之後進行連接;在這種情況下,設置ReceiveTimeoutConnectionTimeout一樣重要。

這是一個駱駝路由示例,它消耗RS請求並調用第三方RS服務器; 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>