You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2019/12/07 21:47:24 UTC
[camel-quarkus] branch master updated: Add a workaround for Camel's
DI (see CAMEL-14271)
This is an automated email from the ASF dual-hosted git repository.
acosentino 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 bd646e7 Add a workaround for Camel's DI (see CAMEL-14271)
new fc08606 Merge pull request #525 from lburgazzoli/camel-di
bd646e7 is described below
commit bd646e7ccab47723ba8fcf0780b608402a4b74fe
Author: lburgazzoli <lb...@gmail.com>
AuthorDate: Sat Dec 7 19:37:04 2019 +0100
Add a workaround for Camel's DI (see CAMEL-14271)
---
.../quarkus/core/runtime/CamelRegistryTest.java | 25 +++++++++++++++++++++-
.../org/apache/camel/quarkus/core/CamelMain.java | 22 +++++++++++++++++++
2 files changed, 46 insertions(+), 1 deletion(-)
diff --git a/extensions/core/deployment/src/test/java/org/apache/camel/quarkus/core/runtime/CamelRegistryTest.java b/extensions/core/deployment/src/test/java/org/apache/camel/quarkus/core/runtime/CamelRegistryTest.java
index 4bb4ba5..eb99554 100644
--- a/extensions/core/deployment/src/test/java/org/apache/camel/quarkus/core/runtime/CamelRegistryTest.java
+++ b/extensions/core/deployment/src/test/java/org/apache/camel/quarkus/core/runtime/CamelRegistryTest.java
@@ -22,6 +22,10 @@ import javax.inject.Inject;
import javax.inject.Named;
import io.quarkus.test.QuarkusUnitTest;
+import org.apache.camel.BindToRegistry;
+import org.apache.camel.Processor;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.spi.Registry;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
@@ -34,17 +38,24 @@ public class CamelRegistryTest {
@RegisterExtension
static final QuarkusUnitTest CONFIG = new QuarkusUnitTest()
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)
- .addClasses(BeanProducer.class));
+ .addClasses(BeanProducer.class, MyRoute.class));
+
@Inject
Registry registry;
@Test
+ public void testLookupRoutes() {
+ assertThat(registry.findByType(RoutesBuilder.class)).isNotEmpty();
+ }
+
+ @Test
public void testLookupByName() {
assertThat(registry.lookupByName("bean-1")).isInstanceOfSatisfying(String.class, s -> assertThat(s).isEqualTo("a"));
assertThat(registry.lookupByName("bean-2")).isInstanceOfSatisfying(String.class, s -> assertThat(s).isEqualTo("b"));
assertThat(registry.lookupByNameAndType("bean-1", String.class)).isEqualTo("a");
assertThat(registry.lookupByNameAndType("bean-2", String.class)).isEqualTo("b");
+ assertThat(registry.lookupByName("myProcessor")).isInstanceOf(Processor.class);
}
@Test
@@ -69,4 +80,16 @@ public class CamelRegistryTest {
return "b";
}
}
+
+ public static class MyRoute extends RouteBuilder {
+ @Override
+ public void configure() throws Exception {
+ }
+
+ @BindToRegistry
+ public Processor myProcessor() {
+ return e -> {
+ };
+ }
+ }
}
diff --git a/extensions/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelMain.java b/extensions/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelMain.java
index 147dc6e..6a7a551 100644
--- a/extensions/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelMain.java
+++ b/extensions/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelMain.java
@@ -21,10 +21,13 @@ import java.util.Collections;
import org.apache.camel.CamelContext;
import org.apache.camel.CamelContextAware;
+import org.apache.camel.ExtendedCamelContext;
import org.apache.camel.ProducerTemplate;
+import org.apache.camel.RoutesBuilder;
import org.apache.camel.main.BaseMainSupport;
import org.apache.camel.main.MainConfigurationProperties;
import org.apache.camel.main.MainListener;
+import org.apache.camel.spi.CamelBeanPostProcessor;
import org.apache.camel.support.service.ServiceHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -44,6 +47,20 @@ public class CamelMain extends BaseMainSupport implements CamelContextAware {
}
postProcessCamelContext(getCamelContext());
+
+ //
+ // TODO: this is required as the bean post processor in camel main
+ // is not triggered after all the routes are collected so i.e.
+ // for those from the registry, Camel DI does not work.
+ // This hack should be removed after the issues is fixed in
+ // Camel, see https://issues.apache.org/jira/browse/CAMEL-14271
+ //
+ CamelBeanPostProcessor postProcessor = camelContext.adapt(ExtendedCamelContext.class).getBeanPostProcessor();
+ for (RoutesBuilder builder : getRoutesBuilders()) {
+ postProcessor.postProcessBeforeInitialization(builder, builder.getClass().getName());
+ postProcessor.postProcessAfterInitialization(builder, builder.getClass().getName());
+ }
+
getCamelContext().start();
for (MainListener listener : listeners) {
@@ -52,6 +69,11 @@ public class CamelMain extends BaseMainSupport implements CamelContextAware {
}
@Override
+ protected void loadRouteBuilders(CamelContext camelContext) throws Exception {
+ // classes are automatically discovered by build processors
+ }
+
+ @Override
protected void doStop() throws Exception {
try {
if (camelTemplate != null) {