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

StartupListener runs before routes are started, contrary to Javadoc

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Trivial
    • Resolution: Fixed
    • Affects Version/s: 2.23.3
    • Fix Version/s: 3.0.0.RC1, 3.0.0
    • Component/s: came-core
    • Labels:
      None
    • Estimated Complexity:
      Unknown

      Description

      The Javadoc (https://static.javadoc.io/org.apache.camel/camel-core/2.23.3/org/apache/camel/StartupListener.html) for StartupListener is misleading (italics for emphasis):

      This can be used to perform any custom work when the entire CamelContext has been initialized and almost started. For example this ensures that all Camel routes have been started and are up and running, before this callback is invoked.

      However, routes are not started within the callback. The following code, for example, 

      DefaultCamelContext context = new DefaultCamelContext();
      
      context.addStartupListener((c, alreadyStarted) -> {
          c.createProducerTemplate().sendBody("direct:doesNotExistYet", new Object());
      });
      
      context.addRoutes(new RouteBuilder() {
          @Override
          public void configure() {
              from("direct:doesNotExistYet").bean((Consumer<Object>) System.out::println);
          }
      });
      context.start();

      fails with

      Caused by: org.apache.camel.component.direct.DirectConsumerNotAvailableException: No consumers available on endpoint: direct://doesNotExistYet. Exchange[ID-x-1563396556957-0-1]
      	at org.apache.camel.component.direct.DirectProducer.process(DirectProducer.java:69)
      	at org.apache.camel.processor.SharedCamelInternalProcessor.process(SharedCamelInternalProcessor.java:186)
      	at org.apache.camel.processor.SharedCamelInternalProcessor.process(SharedCamelInternalProcessor.java:86)
      	at org.apache.camel.impl.ProducerCache$1.doInProducer(ProducerCache.java:541)
      	at org.apache.camel.impl.ProducerCache$1.doInProducer(ProducerCache.java:506)
      	at org.apache.camel.impl.ProducerCache.doInProducer(ProducerCache.java:369)
      	at org.apache.camel.impl.ProducerCache.sendExchange(ProducerCache.java:506)
      	at org.apache.camel.impl.ProducerCache.send(ProducerCache.java:229)
      	at org.apache.camel.impl.DefaultProducerTemplate.send(DefaultProducerTemplate.java:144)
      	at org.apache.camel.impl.DefaultProducerTemplate.sendBody(DefaultProducerTemplate.java:161)
      	... 12 more
      

      I am aware that using ExtendedStartupListener or an EventNotifier makes this work, but it would be great if the Javadoc was updated (assuming this is intended behavior, I am not sure).

        Attachments

          Activity

            People

            • Assignee:
              davsclaus Claus Ibsen
              Reporter:
              mwang5 Marquis Wang
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: