java - 重新启动骆驼上下文时,Http连接池关闭
问题描述
我已经使用组件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);
}
}
解决方案
阅读 CamelContext 上这些方法的 javadoc 以获取详细信息。
而不是停止骆驼上下文,您应该使用暂停和恢复它。
推荐阅读
- excel - VBA:列中的不同值及其关联的不同值
- arrays - 快速将二维数组分成2个不同的数组
- .net - 错误“rzc 生成退出,代码为 -1073741819。”
- .net - 在 .NET MVC 5 中使用严格的 CSP 网格视图集成
- python - Discord py - 如果在新创建的频道中有表情符号 - 删除频道
- mysql - Shell脚本从外部文件执行mysql过程,带有命令行参数
- python - 打包 python 应用程序,包括配置文件
- angular - 如何完成获取请求然后继续执行
- python - 如何将字典的值更改为键
- python - Python 中给定 TimeZone 的标准 UTC 偏移量(无 DST)