Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-13504

Strange behaviour of SimpleLRUCache with ProducerTemplate

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 3.0.0
    • 3.0.0.RC2
    • came-core
    • None
    • Unknown

    Description

      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:

      mvn clean test -Dtest=ElasticsearchIndexTest#testIndex
      

      In the console output you'll see something like the following. Note the multiple connect / disconnect from ElasticsearchProducer:

      [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
      

      When the test case comes to send a message via ProducerTemplate, it fails because there is no active connection to the test ElasticSearch cluster.

      java.lang.IllegalStateException: Request cannot be executed; I/O reactor status: STOPPED
      

      Attachments

        Activity

          People

            gnodet Guillaume Nodet
            jamesnetherton James Netherton
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: