我在 JBoss Fuse 中运行了几条 Camel 路线(大约 100 条)。最近,我遇到了 OutOfMemoryError: Java heap space,因此我决定使用 Eclipse Memory Analyzer Tool 来查找泄漏。
报告显示了几个嫌疑点,但最大的一个是:
11.539 instances of "org.apache.http.impl.conn.PoolingHttpClientConnectionManager", loaded by "org.apache.felix.framework.BundleWiringImpl$BundleClassLoaderJava5 @ 0xd16558b8" occupy 443.624.920 (63,87%) bytes.
与其他泄漏问题不同,此案例的详细报告很小,只有 4 行:
class java.lang.Thread @ 0xd0a9c0c8
\class org.apache.camel.component.jms.DefaultJmsMessageListenerContainer @ 0xd367ee58 .\class org.apache.camel.component.jms.JmsQueueEndpoint @ 0xd36750d8
..\class org.apache.camel.blueprint.BlueprintCamelContext @ 0xd33bcd50
http 连接似乎有问题,但我真的不知道。
我在 pollEnrichers 中使用 http 组件,如下所示:
from(URI_COLA_ENTRADA_STEP)
.pollEnrich().simple("{{URL_CORRELATIVO}}?ruta=STEP", String.class).aggregationStrategy(new EstrategiaCorrelativo()).cacheSize(1).timeout(10000).aggregateOnException(true)
.to(URI_TOPIC_ARTICULOS);
或者在处理器内使用ProducerTemplate:
final String URL = exchange.getContext().resolvePropertyPlaceholders("{{URL_PAGO}}");
ProducerTemplate producer = exchange.getContext().createProducerTemplate();
String response = producer.requestBody(URL, "", String.class);
producer.stop();
因此,如您所见,我没有做任何太复杂的事情。
什么可能导致这个问题?
最佳答案
好的...我解决了问题。这是介于camel参数和http参数之间的东西。
首先:实际上,我是这样使用 http4 组件的:
String URL = exchange.getContext().resolvePropertyPlaceholders("{{URL_PAGO}}");
String PARAMS = "?param1=" + value1 + "¶m2=" + value2;
ProducerTemplate producer = exchange.getContext().createProducerTemplate();
String response = producer.requestBody(URL + PARAMS, "", String.class);
producer.stop();
我这样做是因为文档是这么说的:
The camel-http4 producer supports URI parameters to be sent to the HTTP server. The URI parameters can either be set directly on the endpoint URI or as a header with the key Exchange.HTTP_QUERY on the message:
但是...如果value1和/或value2发生变化,camel将使用URL + PARAMS创建一个新的端点。因此,如果我使用该代码一百万次,它将创建一百万个包含所有内容( header 、缓存等)的 http4 端点。
为避免我使用 Exchange.HTTP_QUERY header :
String URL = exchange.getContext().resolvePropertyPlaceholders("{{URL_PAGO}}");
String PARAMS = "param1=" + value1 + "¶m2=" + value2;
Map<String,Object> headers = new HashMap<String,Object>();
headers.put(Exchange.HTTP_QUERY, PARAMS);
ProducerTemplate producer = exchange.getContext().createProducerTemplate();
String response = producer.requestBody(URL, "",headers, String.class);
producer.stop();
使用此方法,camel 仅创建 1 个 http4 端点。
我认为文档应该更详细地说明这一点。
再见。
关于java - 如何解释 Eclipse Memory Analyzer( Camel route 的内存泄漏),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50158491/