Apache camel即使在配置组件选项

时间:2016-01-29 08:56:55

标签: java apache-camel restlet

我有一个调用restlet端点的camel Java DSL路由。当我手动敲击时,路线没有任何问题。但是,当我尝试通过代码抽取大量请求时,我得到“超时等待来自池的连接

以下是相同的堆叠种族:

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个请求然后我开始收到错误。从配置中我可以看到默认的maxThreads是10.这意味着我通过Bean做的事情没有正常。

3 个答案:

答案 0 :(得分:2)

实际上在我的代码中我已经在路由配置后定义了restlet bean,如下所示

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)

检查以下内容:

  1. 确保您已在Spring App Context XML文件中启用<context:annotation-config/>
  2. 在Spring XML中使用<context:component-scan base-package="<your package>" />
  3. 请确保您已注明包含@Bean @Configuration
  4. 的内容
  5. name属性添加到@Bean@Bean(name={"restlet"})
  6. 希望有所帮助。

答案 2 :(得分:0)

看看这个例子。它的Spring-boot APP。我创建了一个单独的配置类并使用了spring-boot配置注释,因此在启动时spring-boot会执行所有需要的配置

这是一个有效的解决方案 https://github.com/RakeshBhat/rb-springbootcamelrestlet