我已经使用组件camel-http4定义了带有路由的整个骆驼上下文。基本上,在上下文启动时,此路由每 5 分钟向外部服务器发出一个 http 请求。这非常完美。
在某些时候,我想重新启动骆驼上下文(使用 JMX),所以我只是这样做:
if (camelContext.getStatus().isStoppable()) {
camelContext.stop();
}
然后:
if (camelContext.getStatus().isStarttable()) {
camelContext.start();
}
两个操作似乎都成功,日志确认实际停止和启动。但是当发出第一个 http 请求时,我收到以下错误:
java.lang.IllegalStateException: Connection pool shut down
at org.apache.http.util.Asserts.check(Asserts.java:34)[org.apache.httpcomponents:httpcore-nio:4.4.4 org.apache.httpcomponents:httpcore-osgi:4.4.4 org.apache.httpcomponents:httpcore:4.4.4]
at org.apache.http.pool.AbstractConnPool.lease(AbstractConnPool.java:184)[org.apache.httpcomponents:httpcore-nio:4.4.4 org.apache.httpcomponents:httpcore-osgi:4.4.4 org.apache.httpcomponents:httpcore:4.4.4]
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.requestConnection(PoolingHttpClientConnectionManager.java:251)[commons-codec:commons-codec:1.9 org.apache.httpcomponents:fluent-hc:4.5.2 org.apache.httpcomponents:httpclient-cache:4.5.2 org.apache.httpcomponents:httpclient-osgi:4.5.2 org.apache.httpcomponents:httpclient:4.5.2 org.apache.httpcomponents:httpmime:4.5.2]
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:175)[commons-codec:commons-codec:1.9 org.apache.httpcomponents:fluent-hc:4.5.2 org.apache.httpcomponents:httpclient-cache:4.5.2 org.apache.httpcomponents:httpclient-osgi:4.5.2 org.apache.httpcomponents:httpclient:4.5.2 org.apache.httpcomponents:httpmime:4.5.2]
看起来连接池处于无效状态。启动上下文时如何强制重新创建池?有没有其他方法可以避免这个错误?
版本: camel-http4 2.17 apache httpclient 4.5.2
我已经看到一些帖子说连接管理器必须通过使用(它更像是一种解决方法)HttpClientConfigurer 来共享。我定义并注入了我自己的客户端配置器,它不起作用:
public class MyHttpClientConfigurer implements HttpClientConfigurer {
@Override
public void configureHttpClient(HttpClientBuilder httpClientBuilder) {
httpClientBuilder.setConnectionManagerShared(true);
}
}