2016-01-29 34 views
5

我有一個駝峯Java DSL路由調用restlet端點。當我手動點擊時,路線沒有任何問題。但是,當我嘗試通過泵代碼我得到「超時等待池連接」Apache camel即使在配置組件選項後,連接池超時與restlet

而下面的請求較大數量是相同的stackt種族:

2016-01-29 14:09:38.650 WARN 20256 --- [pool-3-thread-2] org.restlet        : An error occurred during the communication with the remote HTTP server.org.apache.http.conn.ConnectionPoolTimeoutException: Timeout waiting for connection from pool 
at org.apache.http.impl.conn.tsccm.ConnPoolByRoute.getEntryBlocking(ConnPoolByRoute.java:412) 
at org.apache.http.impl.conn.tsccm.ConnPoolByRoute$1.getPoolEntry(ConnPoolByRoute.java:298) 
at org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager$1.getConnection(ThreadSafeClientConnManager.java:238) 
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:423) 
at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:863) 
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82) 
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:106) 
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:57) 
at org.restlet.ext.httpclient.internal.HttpMethodCall.sendRequest(HttpMethodCall.java:339) 
at org.restlet.engine.adapter.ClientAdapter.commit(ClientAdapter.java:105) 
at org.restlet.engine.adapter.HttpClientHelper.handle(HttpClientHelper.java:119) 
at org.restlet.Client.handle(Client.java:153) 
at org.restlet.Restlet.handle(Restlet.java:275) 
at org.apache.camel.component.restlet.RestletProducer.process(RestletProducer.java:79) 
at org.apache.camel.component.restlet.RestletProducer.process(RestletProducer.java:98) 
at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:141) 
at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77) 
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:460) 
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:190) 
at org.apache.camel.processor.Pipeline.process(Pipeline.java:121) 
at org.apache.camel.processor.Pipeline.process(Pipeline.java:83) 
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:460) 
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:190) 
at org.apache.camel.processor.MulticastProcessor.doProcessSequential(MulticastProcessor.java:668) 
at org.apache.camel.processor.MulticastProcessor.doProcessSequential(MulticastProcessor.java:596) 
at org.apache.camel.processor.MulticastProcessor.process(MulticastProcessor.java:237) 
at org.apache.camel.processor.Splitter.process(Splitter.java:104) 
at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77) 
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:460) 
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:190) 
at org.apache.camel.processor.Pipeline.process(Pipeline.java:121) 
at org.apache.camel.processor.Pipeline.process(Pipeline.java:83) 
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:190) 
at org.apache.camel.component.direct.DirectProducer.process(DirectProducer.java:62) 
at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:141) 
at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77) 
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:190) 
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:460) 
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:190) 
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:109) 
at org.apache.camel.processor.MulticastProcessor.doProcessParallel(MulticastProcessor.java:814) 
at org.apache.camel.processor.MulticastProcessor.access$200(MulticastProcessor.java:84) 
at org.apache.camel.processor.MulticastProcessor$1.call(MulticastProcessor.java:314) 
at org.apache.camel.processor.MulticastProcessor$1.call(MulticastProcessor.java:299) 
at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) 
at java.lang.Thread.run(Thread.java:745) 

而按照該文檔我沒有配置與下面的代碼的Restlet組件,但我仍然看到了同樣的問題:

@Bean 
public RestletComponent restlet() 
{ 
    RestletComponent restlet = new RestletComponent(); 
    restlet.setMaxThreads(100); 
    restlet.setThreadMaxIdleTimeMs(10000); 
    restlet.setMaxQueued(20); 
    return restlet; 
} 

注:這條路線也接受了一次10個請求,然後我就開始剛開g錯誤。從配置中我可以看到默認情況下maxThreads是10.這意味着我通過Bean做的不正確。

+0

我做了一個小變化的代碼,定義的Restlet配置之前的Bean,然後一切順利。 –

+0

用您的解決方案寫一個答案,以便其他人可以受益。 –

回答

2

路由配置成功後,其實在我的代碼我已經定義的Restlet豆即如下

public class RoutesBuilder extends FatJarRouter { 

.... 

@Override 
    public void configure() throws JAXBException { 
    ...... 
} 

@Bean(name={"restlet"}) 
    public RestletComponent restlet() 
    { 
     ....... 
    } 
} 

現在我已經改變了定義代碼,即首先我定義的Restlet,如下列路線配置的順序。有了這個,我看到restlet的配置已經被選中,我再也看不到連接池的問題了。

public class RoutesBuilder extends FatJarRouter { 

.... 

@Bean(name={"restlet"}) 
    public RestletComponent restlet() 
    { 
     ....... 
    } 

@Override 
    public void configure() throws JAXBException { 
    ...... 
} 


} 
1

檢查這些東西:

  1. 確保您在春應用程序上下文XML文件中啓用<context:annotation-config/>
  2. 在Spring XML中使用<context:component-scan base-package="<your package>" />
  3. 請確保您已註釋包含@Bean@Configuration
  4. name屬性添加到@Bean@Bean(name={"restlet"})

希望有所幫助。

+0

我的應用程序是駱駝春季啓動應用程序,所以你提到的前三件事情都照顧。我已經將bean命名爲4,但我仍然看到這個問題。我routesbuilder類的樣子如下: [在] SpringBootApplication 公共類RoutesBuilder擴展FatJarRouter { ..... [在]覆蓋 公共無效配置()拋出JAXBException { ..... }} –