You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2019/06/20 06:14:40 UTC
[camel] 10/18: CAMEL-13636: camel3 - SPI for ReactiveHelper so we
can plugin different reactive engines
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 344d5487ce06398e09f9529439a65ad6ed04c3e6
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Jun 13 09:59:42 2019 +0200
CAMEL-13636: camel3 - SPI for ReactiveHelper so we can plugin different reactive engines
---
.../camel/impl/engine/AbstractCamelContext.java | 4 +-
core/camel-caffeine-lrucache/pom.xml | 2 +-
core/camel-headersmap/pom.xml | 2 +-
core/camel-jaxp/pom.xml | 6 +-
.../pom.xml | 22 +++----
.../camel/reacitve/VertXReactiveExecutor.java | 74 ++++++++++++++++++++++
.../services/org/apache/camel/reactive-executor | 18 ++++++
.../org/apache/camel/reactive/SimpleMockTest.java | 66 +++++++++++++++++++
.../src/test/resources/log4j2.properties | 31 +++++++++
core/pom.xml | 1 +
10 files changed, 208 insertions(+), 18 deletions(-)
diff --git a/core/camel-base/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java b/core/camel-base/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
index 46217c2..d52a395 100644
--- a/core/camel-base/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
+++ b/core/camel-base/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
@@ -2503,7 +2503,7 @@ public abstract class AbstractCamelContext extends ServiceSupport implements Ext
forceLazyInitialization();
- // if camel-bean is on classpath then we can load its bean proxy facory
+ // if camel-bean is on classpath then we can load its bean proxy factory
BeanProxyFactory beanProxyFactory = new BeanProxyFactoryResolver().resolve(this);
if (beanProxyFactory != null) {
addService(beanProxyFactory);
@@ -2581,6 +2581,8 @@ public abstract class AbstractCamelContext extends ServiceSupport implements Ext
getHeadersMapFactory());
}
+ log.info("Using ReactiveExecutor: {}", getReactiveExecutor());
+
// start routes
if (doNotStartRoutesOnFirstStart) {
log.debug("Skip starting routes as CamelContext has been configured with autoStartup=false");
diff --git a/core/camel-caffeine-lrucache/pom.xml b/core/camel-caffeine-lrucache/pom.xml
index 1d2beff..cbc0b9c 100644
--- a/core/camel-caffeine-lrucache/pom.xml
+++ b/core/camel-caffeine-lrucache/pom.xml
@@ -35,7 +35,7 @@
<properties>
<firstVersion>3.0</firstVersion>
- <label>tooling</label>
+ <label>core</label>
</properties>
<dependencies>
diff --git a/core/camel-headersmap/pom.xml b/core/camel-headersmap/pom.xml
index 33b6181..3852bbd 100644
--- a/core/camel-headersmap/pom.xml
+++ b/core/camel-headersmap/pom.xml
@@ -34,7 +34,7 @@
<properties>
<firstVersion>2.20.0</firstVersion>
- <label>tooling</label>
+ <label>core</label>
</properties>
<dependencies>
diff --git a/core/camel-jaxp/pom.xml b/core/camel-jaxp/pom.xml
index 6d8e8db..48eb4d8 100644
--- a/core/camel-jaxp/pom.xml
+++ b/core/camel-jaxp/pom.xml
@@ -30,10 +30,14 @@
<artifactId>camel-jaxp</artifactId>
<packaging>jar</packaging>
-
<name>Camel :: JAXP</name>
<description>Camel JAXP Support</description>
+ <properties>
+ <firstVersion>3.0.0</firstVersion>
+ <label>core</label>
+ </properties>
+
<dependencies>
<!-- camel annotations -->
diff --git a/core/camel-headersmap/pom.xml b/core/camel-reactive-executor-vertx/pom.xml
similarity index 81%
copy from core/camel-headersmap/pom.xml
copy to core/camel-reactive-executor-vertx/pom.xml
index 33b6181..bfa6ccd 100644
--- a/core/camel-headersmap/pom.xml
+++ b/core/camel-reactive-executor-vertx/pom.xml
@@ -27,14 +27,14 @@
<version>3.0.0-SNAPSHOT</version>
</parent>
- <artifactId>camel-headersmap</artifactId>
+ <artifactId>camel-reactive-executor-vertx</artifactId>
<packaging>jar</packaging>
- <name>Camel :: Headers Map</name>
- <description>Fast case-insensitive headers map implementation</description>
+ <name>Camel :: Reactive Executor :: Vert X</name>
+ <description>Reactive Executor for camel-core using Vert X</description>
<properties>
- <firstVersion>2.20.0</firstVersion>
- <label>tooling</label>
+ <firstVersion>3.0.0</firstVersion>
+ <label>core</label>
</properties>
<dependencies>
@@ -45,15 +45,9 @@
</dependency>
<dependency>
- <groupId>com.cedarsoftware</groupId>
- <artifactId>java-util</artifactId>
- <version>${java-util-version}</version>
- <exclusions>
- <exclusion>
- <groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-core</artifactId>
- </exclusion>
- </exclusions>
+ <groupId>io.vertx</groupId>
+ <artifactId>vertx-core</artifactId>
+ <version>${vertx-version}</version>
</dependency>
<!-- testing -->
diff --git a/core/camel-reactive-executor-vertx/src/main/java/org/apache/camel/reacitve/VertXReactiveExecutor.java b/core/camel-reactive-executor-vertx/src/main/java/org/apache/camel/reacitve/VertXReactiveExecutor.java
new file mode 100644
index 0000000..5e2f507
--- /dev/null
+++ b/core/camel-reactive-executor-vertx/src/main/java/org/apache/camel/reacitve/VertXReactiveExecutor.java
@@ -0,0 +1,74 @@
+/*
+ * 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.reacitve;
+
+import io.vertx.core.Vertx;
+import org.apache.camel.StaticService;
+import org.apache.camel.spi.ReactiveExecutor;
+import org.apache.camel.support.service.ServiceSupport;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A VertX based {@link ReactiveExecutor} that uses Vert X event loop.
+ */
+public class VertXReactiveExecutor extends ServiceSupport implements ReactiveExecutor, StaticService {
+
+ private static final Logger LOG = LoggerFactory.getLogger(VertXReactiveExecutor.class);
+
+ private Vertx vertx;
+
+ @Override
+ public void schedule(Runnable runnable, String description) {
+ LOG.trace("schedule: {}", runnable);
+ vertx.nettyEventLoopGroup().execute(runnable);
+ }
+
+ @Override
+ public void scheduleMain(Runnable runnable, String description) {
+ LOG.trace("scheduleMain: {}", runnable);
+ vertx.nettyEventLoopGroup().execute(runnable);
+ }
+
+ @Override
+ public void scheduleSync(Runnable runnable, String description) {
+ LOG.trace("scheduleSync: {}", runnable);
+ vertx.executeBlocking(future -> {
+ runnable.run();
+ future.complete();
+ }, res -> {});
+ }
+
+ @Override
+ public boolean executeFromQueue() {
+ LOG.trace("executeFromQueue");
+ // TODO: not implemented
+ return false;
+ }
+
+ @Override
+ protected void doStart() throws Exception {
+ LOG.debug("Starting VertX");
+ vertx = Vertx.vertx();
+ }
+
+ @Override
+ protected void doStop() throws Exception {
+ LOG.debug("Stopping VertX");
+ vertx.close();
+ }
+}
diff --git a/core/camel-reactive-executor-vertx/src/main/resources/META-INF/services/org/apache/camel/reactive-executor b/core/camel-reactive-executor-vertx/src/main/resources/META-INF/services/org/apache/camel/reactive-executor
new file mode 100644
index 0000000..68975fc
--- /dev/null
+++ b/core/camel-reactive-executor-vertx/src/main/resources/META-INF/services/org/apache/camel/reactive-executor
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+class=org.apache.camel.reactive.VertXReactiveExecutor
diff --git a/core/camel-reactive-executor-vertx/src/test/java/org/apache/camel/reactive/SimpleMockTest.java b/core/camel-reactive-executor-vertx/src/test/java/org/apache/camel/reactive/SimpleMockTest.java
new file mode 100644
index 0000000..924952f
--- /dev/null
+++ b/core/camel-reactive-executor-vertx/src/test/java/org/apache/camel/reactive/SimpleMockTest.java
@@ -0,0 +1,66 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.reactive;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.reacitve.VertXReactiveExecutor;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class SimpleMockTest extends CamelTestSupport {
+
+ @Override
+ protected CamelContext createCamelContext() throws Exception {
+ // TODO: should detect from classpath
+ CamelContext context = super.createCamelContext();
+ context.setReactiveExecutor(new VertXReactiveExecutor());
+ return context;
+ }
+
+ @Test
+ public void testSimple() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedBodiesReceived("Hello World");
+
+ template.sendBody("direct:start", "Hello World");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Test
+ public void testSimpleTwoMessages() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedBodiesReceived("Hello World", "Bye World");
+
+ template.sendBody("direct:start", "Hello World");
+ template.sendBody("direct:start", "Bye World");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start").to("log:foo").to("log:bar").to("mock:result");
+ }
+ };
+ }
+}
diff --git a/core/camel-reactive-executor-vertx/src/test/resources/log4j2.properties b/core/camel-reactive-executor-vertx/src/test/resources/log4j2.properties
new file mode 100644
index 0000000..2cebd6a
--- /dev/null
+++ b/core/camel-reactive-executor-vertx/src/test/resources/log4j2.properties
@@ -0,0 +1,31 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+
+appender.out.type = File
+appender.out.name = out
+appender.out.fileName = target/camel-reactive-executor-vertx.log
+appender.out.layout.type = PatternLayout
+appender.out.layout.pattern = %d [%-15.15t] %-5p %-30.30c{1} - %m%n
+appender.stdout.type = Console
+appender.stdout.name = stdout
+appender.stdout.layout.type = PatternLayout
+appender.stdout.layout.pattern = %d [%-15.15t] %-5p %-30.30c{1} - %m%n
+
+rootLogger.level = INFO
+
+rootLogger.appenderRef.out.ref = out
+#rootLogger.appenderRef.out.ref = stdout
diff --git a/core/pom.xml b/core/pom.xml
index 0792804..5da53d0 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -40,6 +40,7 @@
<module>camel-support</module>
<module>camel-caffeine-lrucache</module>
<module>camel-headersmap</module>
+ <module>camel-reactive-executor-vertx</module>
<module>camel-management-api</module>
<module>camel-management-impl</module>
<module>camel-base</module>