[
https://issues.apache.org/jira/browse/CAMEL-13761?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16888252#comment-16888252
]
Marquis Wang commented on CAMEL-13761:
--------------------------------------
Thanks, the updated comment is much clearer. However, I still think it is a bit
misleading.
{quote}This callback is invoked twice during starting the Camel routes, once
before the route consumers are started, and once again after the route consumer
has just been started.{quote}
Reading this, I would expect
{code}
context.addStartupListener((c, alreadyStarted) -> System.out.println("Calling
StartupListener"));
{code}
to be called twice on {{context.start()}}. Instead, it is only called once.
If I'm reading the code correctly, StartupListeners that are added before
{{context.start()}} is called will be invoked before the route consumers are
started. Route consumers may themselves implement StartupListener as well, in
which case they are then invoked after the route consumers are started. Is this
correct?
Also, it might be worth mentioning that this is also invoked whenever a route
is added after the service has already been started. I do realize that is in
the parameter javadoc for {{alreadyStarted}} but it's not super obvious.
> StartupListener runs before routes are started, contrary to Javadoc
> -------------------------------------------------------------------
>
> Key: CAMEL-13761
> URL: https://issues.apache.org/jira/browse/CAMEL-13761
> Project: Camel
> Issue Type: Improvement
> Components: came-core
> Affects Versions: 2.23.3
> Reporter: Marquis Wang
> Assignee: Claus Ibsen
> Priority: Trivial
> Fix For: 3.0.0, 3.0.0.M5
>
>
> 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):
> {quote}This can be used to perform any custom work when the entire
> [{{CamelContext}}|https://static.javadoc.io/org.apache.camel/camel-core/2.23.3/org/apache/camel/CamelContext.html]
> 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._
> {quote}
> However, routes are not started within the callback. The following code, for
> example,
> {code:java}
> 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();{code}
> fails with
> {code}
> 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
> {code}
> 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).
--
This message was sent by Atlassian JIRA
(v7.6.14#76016)