This is an automated email from the ASF dual-hosted git repository. ppalaga pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
commit dd638115523e83a5a0cae8faa39b3eadd8d2c325 Author: Peter Palaga <[email protected]> AuthorDate: Thu Jul 2 13:50:48 2020 +0200 Fixup Split main startup logic Make sure that Quarkus orders booting our runtime before starting to serve HTTP endpoints. --- .../quarkus/core/deployment/CamelBootstrapProcessor.java | 8 +++++++- .../camel/quarkus/core/deployment/CamelContextProcessor.java | 11 ++++++----- .../camel/quarkus/main/deployment/CamelMainProcessor.java | 11 ++++++----- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelBootstrapProcessor.java b/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelBootstrapProcessor.java index ae03d6c..6f6cc47 100644 --- a/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelBootstrapProcessor.java +++ b/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelBootstrapProcessor.java @@ -16,11 +16,13 @@ */ package org.apache.camel.quarkus.core.deployment; +import io.quarkus.deployment.annotations.BuildProducer; import io.quarkus.deployment.annotations.BuildStep; import io.quarkus.deployment.annotations.ExecutionTime; import io.quarkus.deployment.annotations.Produce; import io.quarkus.deployment.annotations.Record; import io.quarkus.deployment.builditem.RawCommandLineArgumentsBuildItem; +import io.quarkus.deployment.builditem.ServiceStartBuildItem; import io.quarkus.deployment.builditem.ShutdownContextBuildItem; import io.quarkus.runtime.ShutdownContext; import org.apache.camel.quarkus.core.CamelBootstrapRecorder; @@ -45,11 +47,15 @@ class CamelBootstrapProcessor { CamelBootstrapRecorder recorder, CamelRuntimeBuildItem runtime, RawCommandLineArgumentsBuildItem commandLineArguments, - ShutdownContextBuildItem shutdown) { + ShutdownContextBuildItem shutdown, + BuildProducer<ServiceStartBuildItem> serviceStartBuildItems) { recorder.addShutdownTask(shutdown, runtime.runtime()); if (runtime.isAutoStartup()) { recorder.start(runtime.runtime(), commandLineArguments); } + /* Make sure that Quarkus orders this method before starting to serve HTTP endpoints. + * Otherwise first requests might reach Camel context in a non-yet-started state. */ + serviceStartBuildItems.produce(new ServiceStartBuildItem("camel-runtime")); } } diff --git a/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelContextProcessor.java b/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelContextProcessor.java index 6dcb10b..a488baa 100644 --- a/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelContextProcessor.java +++ b/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelContextProcessor.java @@ -19,11 +19,12 @@ package org.apache.camel.quarkus.core.deployment; import java.util.List; import io.quarkus.arc.deployment.BeanContainerBuildItem; +import io.quarkus.arc.deployment.SyntheticBeansRuntimeInitBuildItem; import io.quarkus.deployment.annotations.BuildStep; +import io.quarkus.deployment.annotations.Consume; import io.quarkus.deployment.annotations.ExecutionTime; import io.quarkus.deployment.annotations.Overridable; import io.quarkus.deployment.annotations.Record; -import io.quarkus.deployment.builditem.ServiceStartBuildItem; import io.quarkus.runtime.RuntimeValue; import org.apache.camel.CamelContext; import org.apache.camel.quarkus.core.CamelConfig; @@ -116,9 +117,6 @@ public class CamelContextProcessor { * @param customizers a list of {@link org.apache.camel.quarkus.core.CamelContextCustomizer} used to customize * the {@link CamelContext} at {@link ExecutionTime#RUNTIME_INIT}. * @param routesBuilderClasses a list of known {@link org.apache.camel.RoutesBuilder} classes. - * @param startList a placeholder to ensure camel-main start after the ArC container is fully initialized. - * This is required as under the hoods the camel registry may look-up beans form the - * container thus we need it to be fully initialized to avoid unexpected behaviors. * @param runtimeTasks a placeholder to ensure all the runtime task are properly are done. * to the registry. * @return a build item holding a {@link CamelRuntime} instance. @@ -126,6 +124,10 @@ public class CamelContextProcessor { @Overridable @BuildStep @Record(value = ExecutionTime.RUNTIME_INIT, optional = true) + /* @Consume(SyntheticBeansRuntimeInitBuildItem.class) makes sure that camel-main starts after the ArC container is + * fully initialized. This is required as under the hoods the camel registry may look-up beans form the + * container thus we need it to be fully initialized to avoid unexpected behaviors. */ + @Consume(SyntheticBeansRuntimeInitBuildItem.class) public CamelRuntimeBuildItem runtime( BeanContainerBuildItem beanContainer, ContainerBeansBuildItem containerBeans, @@ -133,7 +135,6 @@ public class CamelContextProcessor { CamelContextBuildItem context, List<RuntimeCamelContextCustomizerBuildItem> customizers, List<CamelRoutesBuilderClassBuildItem> routesBuilderClasses, - List<ServiceStartBuildItem> startList, List<CamelRuntimeTaskBuildItem> runtimeTasks) { for (CamelRoutesBuilderClassBuildItem item : routesBuilderClasses) { diff --git a/extensions-core/main/deployment/src/main/java/org/apache/camel/quarkus/main/deployment/CamelMainProcessor.java b/extensions-core/main/deployment/src/main/java/org/apache/camel/quarkus/main/deployment/CamelMainProcessor.java index d98124b..4f76da4 100644 --- a/extensions-core/main/deployment/src/main/java/org/apache/camel/quarkus/main/deployment/CamelMainProcessor.java +++ b/extensions-core/main/deployment/src/main/java/org/apache/camel/quarkus/main/deployment/CamelMainProcessor.java @@ -21,13 +21,14 @@ import java.util.stream.Collectors; import io.quarkus.arc.deployment.AdditionalBeanBuildItem; import io.quarkus.arc.deployment.BeanContainerBuildItem; +import io.quarkus.arc.deployment.SyntheticBeansRuntimeInitBuildItem; import io.quarkus.deployment.annotations.BuildProducer; import io.quarkus.deployment.annotations.BuildStep; +import io.quarkus.deployment.annotations.Consume; import io.quarkus.deployment.annotations.ExecutionTime; import io.quarkus.deployment.annotations.Overridable; import io.quarkus.deployment.annotations.Record; import io.quarkus.deployment.builditem.CombinedIndexBuildItem; -import io.quarkus.deployment.builditem.ServiceStartBuildItem; import io.quarkus.runtime.RuntimeValue; import io.quarkus.runtime.annotations.QuarkusMain; import org.apache.camel.CamelContext; @@ -145,21 +146,21 @@ public class CamelMainProcessor { * @param main a reference to a {@link CamelMain}. * @param customizers a list of {@link org.apache.camel.quarkus.core.CamelContextCustomizer} that will be * executed before starting the {@link CamelContext} at {@link ExecutionTime#RUNTIME_INIT}. - * @param startList a placeholder to ensure camel-main start after the ArC container is fully initialized. - * This is required as under the hoods the camel registry may look-up beans form the - * container thus we need it to be fully initialized to avoid unexpected behaviors. * @param runtimeTasks a placeholder to ensure all the runtime task are properly are done. * @return a build item holding a {@link CamelRuntime} instance. */ @BuildStep @Record(value = ExecutionTime.RUNTIME_INIT, optional = true) + /* @Consume(SyntheticBeansRuntimeInitBuildItem.class) makes sure that camel-main starts after the ArC container is + * fully initialized. This is required as under the hoods the camel registry may look-up beans form the + * container thus we need it to be fully initialized to avoid unexpected behaviors. */ + @Consume(SyntheticBeansRuntimeInitBuildItem.class) CamelRuntimeBuildItem runtime( CombinedIndexBuildItem index, BeanContainerBuildItem beanContainer, CamelMainRecorder recorder, CamelMainBuildItem main, List<RuntimeCamelContextCustomizerBuildItem> customizers, - List<ServiceStartBuildItem> startList, List<CamelRuntimeTaskBuildItem> runtimeTasks) { // Run the customizer before starting the context to give a last chance
