Skip to content

Commit

Permalink
Fixup Split main startup logic
Browse files Browse the repository at this point in the history
Make sure that Quarkus orders booting our runtime before starting to
serve HTTP endpoints.
  • Loading branch information
ppalaga committed Jul 2, 2020
1 parent f30e2b6 commit 55f8520
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
Expand Up @@ -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;
Expand All @@ -45,11 +47,15 @@ void boot(
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"));
}
}
Expand Up @@ -19,11 +19,12 @@
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;
Expand Down Expand Up @@ -116,24 +117,24 @@ CamelContextBuildItem context(
* @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.
*/
@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,
CamelContextRecorder recorder,
CamelContextBuildItem context,
List<RuntimeCamelContextCustomizerBuildItem> customizers,
List<CamelRoutesBuilderClassBuildItem> routesBuilderClasses,
List<ServiceStartBuildItem> startList,
List<CamelRuntimeTaskBuildItem> runtimeTasks) {

for (CamelRoutesBuilderClassBuildItem item : routesBuilderClasses) {
Expand Down
Expand Up @@ -21,13 +21,14 @@

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;
Expand Down Expand Up @@ -145,21 +146,21 @@ CamelMainBuildItem main(
* @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
Expand Down

0 comments on commit 55f8520

Please sign in to comment.