James Netherton created CAMEL-13504:
---------------------------------------
Summary: Strange behaviour of SimpleLRUCache with ProducerTemplate
Key: CAMEL-13504
URL: https://issues.apache.org/jira/browse/CAMEL-13504
Project: Camel
Issue Type: Bug
Components: came-core
Affects Versions: 3.0.0
Reporter: James Netherton
Fix For: 3.0.0
If no cache factory implementation can be found on the classpath then CamelĀ
falls back on {{SimpleLRUCache}}.
This has some strange effects when using {{ProducerTemplate.send()}} (or
{{.request()}}). I didn't dig too much into the problem, but it's something to
do with what happens when a producer is evicted from the producer cache. It
causes the producer {{doStop()}} method to be called. So if an endpoint is
trying to connect to some external resource, it ends up closing that connection
prior to any message being sent.
To see this, add a dependency exclusion for {{camel-caffeine-lrucache}} in the
{{camel-elasticsearch-rest}} {{pom.xml}}, then run a test:
{code:java}
mvn clean test -Dtest=ElasticsearchIndexTest#testIndex
{code}
In the console output you'll see something like the following. Note the
multiple connect / disconnect from {{ElasticsearchProducer}}:
{code:java}
[2019-05-13T08:03:30,574][INFO ][o.a.c.c.e.ElasticsearchProducer] [unknown]
Connecting to the ElasticSearch cluster: elasticsearch
[2019-05-13T08:03:30,575][INFO ][o.a.c.c.e.ElasticsearchProducer] [unknown]
Disconnecting from ElasticSearch cluster: elasticsearch
[2019-05-13T08:03:30,578][INFO ][o.a.c.c.e.ElasticsearchProducer] [unknown]
Connecting to the ElasticSearch cluster: elasticsearch
[2019-05-13T08:03:30,579][INFO ][o.a.c.c.e.ElasticsearchProducer] [unknown]
Disconnecting from ElasticSearch cluster: elasticsearch
[2019-05-13T08:03:30,582][INFO ][o.a.c.c.e.ElasticsearchProducer] [unknown]
Connecting to the ElasticSearch cluster: elasticsearch
[2019-05-13T08:03:30,582][INFO ][o.a.c.c.e.ElasticsearchProducer] [unknown]
Disconnecting from ElasticSearch cluster: elasticsearch
[2019-05-13T08:03:30,586][INFO ][o.a.c.c.e.ElasticsearchProducer] [unknown]
Connecting to the ElasticSearch cluster: elasticsearch
[2019-05-13T08:03:30,587][INFO ][o.a.c.c.e.ElasticsearchProducer] [unknown]
Disconnecting from ElasticSearch cluster: elasticsearch
[2019-05-13T08:03:30,590][INFO ][o.a.c.i.DefaultCamelContext] [unknown] Route:
route9 started and consuming from: direct://start
[2019-05-13T08:03:30,591][INFO ][o.a.c.i.DefaultCamelContext] [unknown] Route:
route10 started and consuming from: direct://index
[2019-05-13T08:03:30,591][INFO ][o.a.c.i.DefaultCamelContext] [unknown] Route:
route11 started and consuming from: direct://deleteIndex
[2019-05-13T08:03:30,592][INFO ][o.a.c.i.DefaultCamelContext] [unknown] Route:
route12 started and consuming from: direct://indexWithReplication
[2019-05-13T08:03:30,592][INFO ][o.a.c.i.DefaultCamelContext] [unknown] Total 4
routes, of which 4 are started
[2019-05-13T08:03:30,592][INFO ][o.a.c.i.DefaultCamelContext] [unknown] Apache
Camel 3.0.0-SNAPSHOT (CamelContext: camel-3) started in 0.040 seconds
{code}
When the test case comes to send a message via {{ProducerTemplate}}, it fails
because there is no active connection to the test ElasticSearch cluster.
{code:java}
java.lang.IllegalStateException: Request cannot be executed; I/O reactor
status: STOPPED
{code}
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)