You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ja...@apache.org on 2022/06/08 10:45:55 UTC
[camel-quarkus] branch main updated: Auto discover routes created as LambdaEndpointRouteBuilder
This is an automated email from the ASF dual-hosted git repository.
jamesnetherton pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
The following commit(s) were added to refs/heads/main by this push:
new 242a068a5b Auto discover routes created as LambdaEndpointRouteBuilder
242a068a5b is described below
commit 242a068a5b6aed7a83fe565c337674db5c647398
Author: James Netherton <ja...@gmail.com>
AuthorDate: Wed Jun 8 07:59:09 2022 +0100
Auto discover routes created as LambdaEndpointRouteBuilder
Fixes #3837
---
.../quarkus/core/deployment/CamelProcessor.java | 3 +
...ainLambdaEndpointRouteBuilderDiscoveryTest.java | 72 ++++++++++++++++++++++
.../camel/quarkus/core/CamelContextRecorder.java | 12 ++++
.../camel/quarkus/core/RegistryRoutesLoaders.java | 13 ++++
.../CamelRouteWithLambdaEndpointRouteBuilder.java | 32 ++++++++++
.../apache/camel/quarkus/main/CoreMainTest.java | 2 +-
6 files changed, 133 insertions(+), 1 deletion(-)
diff --git a/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelProcessor.java b/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelProcessor.java
index 8c32cef1c1..f6b94366b0 100644
--- a/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelProcessor.java
+++ b/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelProcessor.java
@@ -93,6 +93,8 @@ class CamelProcessor {
"org.apache.camel.builder.RouteBuilder");
private static final DotName LAMBDA_ROUTE_BUILDER_TYPE = DotName.createSimple(
"org.apache.camel.builder.LambdaRouteBuilder");
+ private static final DotName LAMBDA_ENDPOINT_ROUTE_BUILDER_TYPE = DotName.createSimple(
+ "org.apache.camel.builder.endpoint.LambdaEndpointRouteBuilder");
private static final DotName ADVICE_WITH_ROUTE_BUILDER_TYPE = DotName.createSimple(
"org.apache.camel.builder.AdviceWithRouteBuilder");
private static final DotName DATA_FORMAT_TYPE = DotName.createSimple(
@@ -109,6 +111,7 @@ class CamelProcessor {
private static final Set<DotName> UNREMOVABLE_BEANS_TYPES = CamelSupport.setOf(
ROUTES_BUILDER_TYPE,
LAMBDA_ROUTE_BUILDER_TYPE,
+ LAMBDA_ENDPOINT_ROUTE_BUILDER_TYPE,
DATA_FORMAT_TYPE,
LANGUAGE_TYPE,
COMPONENT_TYPE,
diff --git a/extensions-core/core/deployment/src/test/java/org/apache/camel/quarkus/core/deployment/main/CamelMainLambdaEndpointRouteBuilderDiscoveryTest.java b/extensions-core/core/deployment/src/test/java/org/apache/camel/quarkus/core/deployment/main/CamelMainLambdaEndpointRouteBuilderDiscoveryTest.java
new file mode 100644
index 0000000000..13c91d5d99
--- /dev/null
+++ b/extensions-core/core/deployment/src/test/java/org/apache/camel/quarkus/core/deployment/main/CamelMainLambdaEndpointRouteBuilderDiscoveryTest.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.quarkus.core.deployment.main;
+
+import java.io.IOException;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.util.Properties;
+
+import javax.enterprise.inject.Produces;
+import javax.inject.Inject;
+
+import io.quarkus.test.QuarkusUnitTest;
+import org.apache.camel.builder.endpoint.LambdaEndpointRouteBuilder;
+import org.apache.camel.quarkus.main.CamelMain;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.Asset;
+import org.jboss.shrinkwrap.api.asset.StringAsset;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class CamelMainLambdaEndpointRouteBuilderDiscoveryTest {
+ @RegisterExtension
+ static final QuarkusUnitTest CONFIG = new QuarkusUnitTest()
+ .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)
+ .addAsResource(applicationProperties(), "application.properties"));
+
+ @Inject
+ CamelMain main;
+
+ public static Asset applicationProperties() {
+ Writer writer = new StringWriter();
+
+ Properties props = new Properties();
+ props.setProperty("quarkus.banner.enabled", "false");
+
+ try {
+ props.store(writer, "");
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+
+ return new StringAsset(writer.toString());
+ }
+
+ @Test
+ public void testRoutesDiscovery() {
+ assertThat(main.getCamelContext().getRoutes()).isNotEmpty();
+ }
+
+ @Produces
+ public LambdaEndpointRouteBuilder myRoute() {
+ return rb -> rb.from(rb.direct("in")).to(rb.log("out"));
+ }
+}
diff --git a/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelContextRecorder.java b/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelContextRecorder.java
index 9f99f1c59c..989596519d 100644
--- a/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelContextRecorder.java
+++ b/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelContextRecorder.java
@@ -28,6 +28,8 @@ import org.apache.camel.RouteConfigurationsBuilder;
import org.apache.camel.RoutesBuilder;
import org.apache.camel.builder.LambdaRouteBuilder;
import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.builder.endpoint.EndpointRouteBuilder;
+import org.apache.camel.builder.endpoint.LambdaEndpointRouteBuilder;
import org.apache.camel.catalog.RuntimeCamelCatalog;
import org.apache.camel.spi.CamelContextCustomizer;
import org.apache.camel.spi.ComponentNameResolver;
@@ -112,6 +114,16 @@ public class CamelContextRecorder {
});
}
+ for (LambdaEndpointRouteBuilder builder : context.getValue().getRegistry()
+ .findByType(LambdaEndpointRouteBuilder.class)) {
+ allRoutesBuilders.add(new EndpointRouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ builder.accept(this);
+ }
+ });
+ }
+
for (RoutesBuilder cdiRoutesBuilder : context.getValue().getRegistry().findByType(RoutesBuilder.class)) {
allRoutesBuilders.add(cdiRoutesBuilder);
}
diff --git a/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/RegistryRoutesLoaders.java b/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/RegistryRoutesLoaders.java
index be76546b61..b70c73d5e1 100644
--- a/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/RegistryRoutesLoaders.java
+++ b/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/RegistryRoutesLoaders.java
@@ -26,6 +26,8 @@ import org.apache.camel.CamelContext;
import org.apache.camel.RoutesBuilder;
import org.apache.camel.builder.LambdaRouteBuilder;
import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.builder.endpoint.EndpointRouteBuilder;
+import org.apache.camel.builder.endpoint.LambdaEndpointRouteBuilder;
import org.apache.camel.util.AntPathMatcher;
import org.apache.camel.util.ObjectHelper;
import org.slf4j.Logger;
@@ -69,6 +71,17 @@ public final class RegistryRoutesLoaders {
routes.add(rb);
}
+ Set<LambdaEndpointRouteBuilder> lerbs = camelContext.getRegistry().findByType(LambdaEndpointRouteBuilder.class);
+ for (LambdaEndpointRouteBuilder lerb : lerbs) {
+ EndpointRouteBuilder rb = new EndpointRouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ lerb.accept(this);
+ }
+ };
+ routes.add(rb);
+ }
+
Set<RoutesBuilder> builders = camelContext.getRegistry().findByType(RoutesBuilder.class);
for (RoutesBuilder routesBuilder : builders) {
// filter out abstract classes
diff --git a/integration-tests/main/src/main/java/org/apache/camel/quarkus/main/CamelRouteWithLambdaEndpointRouteBuilder.java b/integration-tests/main/src/main/java/org/apache/camel/quarkus/main/CamelRouteWithLambdaEndpointRouteBuilder.java
new file mode 100644
index 0000000000..ba34d81c4c
--- /dev/null
+++ b/integration-tests/main/src/main/java/org/apache/camel/quarkus/main/CamelRouteWithLambdaEndpointRouteBuilder.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.quarkus.main;
+
+import javax.enterprise.inject.Produces;
+
+import org.apache.camel.builder.endpoint.LambdaEndpointRouteBuilder;
+
+public class CamelRouteWithLambdaEndpointRouteBuilder {
+
+ @Produces
+ public LambdaEndpointRouteBuilder lambdaEndpointRouteBuilder() {
+ return rb -> rb
+ .from(rb.direct("greet")).routeId("lambdaEndpointRoute")
+ .setBody().constant("Hello World!")
+ .to(rb.log("end"));
+ }
+}
diff --git a/integration-tests/main/src/test/java/org/apache/camel/quarkus/main/CoreMainTest.java b/integration-tests/main/src/test/java/org/apache/camel/quarkus/main/CoreMainTest.java
index 7482a93bb2..c27441a553 100644
--- a/integration-tests/main/src/test/java/org/apache/camel/quarkus/main/CoreMainTest.java
+++ b/integration-tests/main/src/test/java/org/apache/camel/quarkus/main/CoreMainTest.java
@@ -91,7 +91,7 @@ public class CoreMainTest {
.contains(CamelRoute.class.getName())
.doesNotContain(CamelRouteFiltered.class.getName());
assertThat(p.getList("routes", String.class))
- .contains("keep-alive", "configure", "beforeStart", "produced", "endpointdsl")
+ .contains("keep-alive", "configure", "beforeStart", "produced", "endpointdsl", "lambdaEndpointRoute")
.doesNotContain("filtered");
assertThat(p.getString("lru-cache-factory")).isEqualTo(DefaultLRUCacheFactory.class.getName());