You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by lb...@apache.org on 2019/09/09 18:05:08 UTC

[camel-quarkus] branch master updated: don't start camel context before the container is fully started

This is an automated email from the ASF dual-hosted git repository.

lburgazzoli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git


The following commit(s) were added to refs/heads/master by this push:
     new 7c5955b  don't start camel context before the container is fully started
7c5955b is described below

commit 7c5955b70e986de5c58a563a24a028798297a3f0
Author: lburgazzoli <lb...@gmail.com>
AuthorDate: Mon Sep 9 14:41:14 2019 +0200

    don't start camel context before the container is fully started
---
 .../org/apache/camel/quarkus/core/deployment/BuildProcessor.java | 4 ++++
 integration-tests/core-cdi/pom.xml                               | 4 ++++
 .../camel/quarkus/component/core/cdi/CamelApplication.java       | 9 +++++++++
 .../apache/camel/quarkus/component/core/cdi/CamelServlet.java    | 8 ++++++++
 .../org/apache/camel/quarkus/component/core/cdi/CamelTest.java   | 6 ++++++
 5 files changed, 31 insertions(+)

diff --git a/extensions/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/BuildProcessor.java b/extensions/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/BuildProcessor.java
index b0c3bed..028ac26 100644
--- a/extensions/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/BuildProcessor.java
+++ b/extensions/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/BuildProcessor.java
@@ -40,6 +40,7 @@ import io.quarkus.deployment.annotations.ExecutionTime;
 import io.quarkus.deployment.annotations.Record;
 import io.quarkus.deployment.builditem.ApplicationArchivesBuildItem;
 import io.quarkus.deployment.builditem.CombinedIndexBuildItem;
+import io.quarkus.deployment.builditem.ServiceStartBuildItem;
 import io.quarkus.deployment.builditem.ShutdownContextBuildItem;
 import io.quarkus.runtime.RuntimeValue;
 import org.apache.camel.RoutesBuilder;
@@ -142,6 +143,9 @@ class BuildProcessor {
             CamelRecorder recorder,
             CamelRuntimeBuildItem runtime,
             ShutdownContextBuildItem shutdown,
+            // TODO: keep this list as placeholder to ensure the ArC container is fully
+            //       started before starting the runtime
+            List<ServiceStartBuildItem> startList,
             CamelConfig.Runtime runtimeConfig)
             throws Exception {
 
diff --git a/integration-tests/core-cdi/pom.xml b/integration-tests/core-cdi/pom.xml
index 9649b88..4c030f3 100644
--- a/integration-tests/core-cdi/pom.xml
+++ b/integration-tests/core-cdi/pom.xml
@@ -46,6 +46,10 @@
             <groupId>io.quarkus</groupId>
             <artifactId>quarkus-resteasy</artifactId>
         </dependency>
+        <dependency>
+            <groupId>io.quarkus</groupId>
+            <artifactId>quarkus-vertx</artifactId>
+        </dependency>
 
         <!-- test dependencies -->
         <dependency>
diff --git a/integration-tests/core-cdi/src/main/java/org/apache/camel/quarkus/component/core/cdi/CamelApplication.java b/integration-tests/core-cdi/src/main/java/org/apache/camel/quarkus/component/core/cdi/CamelApplication.java
index 4e3303b..b7cd0ea 100644
--- a/integration-tests/core-cdi/src/main/java/org/apache/camel/quarkus/component/core/cdi/CamelApplication.java
+++ b/integration-tests/core-cdi/src/main/java/org/apache/camel/quarkus/component/core/cdi/CamelApplication.java
@@ -23,6 +23,8 @@ import javax.enterprise.context.ApplicationScoped;
 import javax.enterprise.event.Observes;
 import javax.inject.Inject;
 
+import io.quarkus.arc.Arc;
+import io.vertx.core.Vertx;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.model.ModelHelper;
 import org.apache.camel.model.RoutesDefinition;
@@ -40,6 +42,13 @@ public class CamelApplication {
     public void starting(@Observes StartingEvent event) {
         runtime.addProperty("starting", "true");
 
+        // invoking Arc.::instance(...) before the container is fully
+        // started may result in a null reference being returned
+        Vertx instance = Arc.container().instance(Vertx.class).get();
+        if (instance != null) {
+            runtime.getRegistry().bind("my-vertx", Arc.container().instance(Vertx.class).get());
+        }
+
         addRoute("src/main/resources/hello.xml");
     }
 
diff --git a/integration-tests/core-cdi/src/main/java/org/apache/camel/quarkus/component/core/cdi/CamelServlet.java b/integration-tests/core-cdi/src/main/java/org/apache/camel/quarkus/component/core/cdi/CamelServlet.java
index 0dda99e..c67f476 100644
--- a/integration-tests/core-cdi/src/main/java/org/apache/camel/quarkus/component/core/cdi/CamelServlet.java
+++ b/integration-tests/core-cdi/src/main/java/org/apache/camel/quarkus/component/core/cdi/CamelServlet.java
@@ -55,4 +55,12 @@ public class CamelServlet {
     public String sayHello(@PathParam("name") String name) {
         return runtime.getContext().createProducerTemplate().requestBody("direct:hello", name, String.class);
     }
+
+    @Path("/registry/{name}")
+    @GET
+    @Produces(MediaType.TEXT_PLAIN)
+    public String lookupByName(@PathParam("name") String name) {
+        Object answer = runtime.getContext().getRegistry().lookupByName(name);
+        return answer != null ? answer.getClass().getName() : "";
+    }
 }
diff --git a/integration-tests/core-cdi/src/test/java/org/apache/camel/quarkus/component/core/cdi/CamelTest.java b/integration-tests/core-cdi/src/test/java/org/apache/camel/quarkus/component/core/cdi/CamelTest.java
index f9832ec..1942e79 100644
--- a/integration-tests/core-cdi/src/test/java/org/apache/camel/quarkus/component/core/cdi/CamelTest.java
+++ b/integration-tests/core-cdi/src/test/java/org/apache/camel/quarkus/component/core/cdi/CamelTest.java
@@ -18,6 +18,7 @@ package org.apache.camel.quarkus.component.core.cdi;
 
 import io.quarkus.test.junit.QuarkusTest;
 import io.restassured.RestAssured;
+import io.vertx.core.impl.VertxImpl;
 import org.junit.jupiter.api.Test;
 
 import static org.hamcrest.Matchers.containsString;
@@ -40,4 +41,9 @@ public class CamelTest {
     public void testHello() {
         RestAssured.when().get("/test/hello/quarkus").then().body(is("hello quarkus"));
     }
+
+    @Test
+    public void restLookupBeanByName() {
+        RestAssured.when().get("/test/registry/my-vertx").then().body(is(VertxImpl.class.getName()));
+    }
 }