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 88942d066f6d19e49a464fa7c461daa42c16d5f8 Author: Claus Ibsen <[email protected]> AuthorDate: Thu Jun 13 11:04:29 2019 +0200 CAMEL-13636: camel3 - SPI for ReactiveHelper so we can plugin different reactive engines --- .../camel-headersmap/src/main/docs/headersmap.adoc | 4 +- core/camel-reactive-executor-vertx/pom.xml | 2 + .../src/main/docs/reactive-executor-vertx.adoc | 44 ++++++++++++++++++++++ .../reactive/vertx/VertXReactiveExecutor.java | 25 ++++++++++-- examples/README.adoc | 2 + examples/camel-example-main/pom.xml | 4 -- .../pom.xml | 13 ++----- .../readme.adoc | 15 ++++++++ .../org/apache/camel/example/MyApplication.java | 38 +++++++++++++++++++ .../org/apache/camel/example/MyRouteBuilder.java | 30 +++++++++++++++ .../src/main/resources/application.properties | 28 ++++++++++++++ .../src/main/resources/log4j2.properties | 23 +++++++++++ examples/pom.xml | 1 + 13 files changed, 209 insertions(+), 20 deletions(-) diff --git a/core/camel-headersmap/src/main/docs/headersmap.adoc b/core/camel-headersmap/src/main/docs/headersmap.adoc index 6947bc1..b7d8759 100644 --- a/core/camel-headersmap/src/main/docs/headersmap.adoc +++ b/core/camel-headersmap/src/main/docs/headersmap.adoc @@ -15,11 +15,9 @@ and Camel should auto-detect this on startup and log as follows: Detected and using custom HeadersMapFactory: org.apache.camel.component.headersmap.FastHeadersMapFactory@71e9ebae ---- -For spring-boot there is a `camel-headersmap-starter` dependency you should use. - === Manual enabling -If you use OSGi or the implementation is not added to the classpath, you need to enable this explict such: +If you use OSGi or the implementation is not added to the classpath, you need to enable this explicit such: [source,java] ---- diff --git a/core/camel-reactive-executor-vertx/pom.xml b/core/camel-reactive-executor-vertx/pom.xml index 0ae3475..d76289a 100644 --- a/core/camel-reactive-executor-vertx/pom.xml +++ b/core/camel-reactive-executor-vertx/pom.xml @@ -27,6 +27,8 @@ <version>3.0.0-SNAPSHOT</version> </parent> + <!-- TODO: move to components --> + <artifactId>camel-reactive-executor-vertx</artifactId> <packaging>jar</packaging> <name>Camel :: Reactive Executor :: Vert X</name> diff --git a/core/camel-reactive-executor-vertx/src/main/docs/reactive-executor-vertx.adoc b/core/camel-reactive-executor-vertx/src/main/docs/reactive-executor-vertx.adoc new file mode 100644 index 0000000..e541df4 --- /dev/null +++ b/core/camel-reactive-executor-vertx/src/main/docs/reactive-executor-vertx.adoc @@ -0,0 +1,44 @@ +== ReactiveExecutor VertX + +*Available as of Camel 3.0* + +The camel-reactive-executor-vertx is a VertX based implementation of the `ReactiveExecutor` SPI. + +By default Camel uses its own reactive engine for routing messages, but you can plugin +different engines via a SPI interface. This is a VertX based plugin that uses the VertX event loop +for processing message during routing. + +=== VertX instance + +This implementation will by default create a default `io.vertx.core.Vertx` instance to be used. +However you can configure an existing instance using the getter/setter on the `VertXReactiveExecutor` class. + +=== Auto detection from classpath + +To use this implementation all you need to do is to add the `camel-reactive-executor-vertx` dependency to the classpath, +and Camel should auto-detect this on startup and log as follows: + +[source,text] +---- +Using ReactiveExecutor: org.apache.camel.reactive.vertx.VertXReactiveExecutor@2a62b5bc +---- + +=== Manual enabling + +If you use OSGi or the implementation is not added to the classpath, you need to enable this explict such: + +[source,java] +---- +CamelContext camel = ... + +camel.setReactiveExecutor(new VertXReactiveExecutor()); +---- + +Or in XML DSL (spring or blueprint XML file) you can declare the factory as a `<bean>`: + +[source,xml] +---- +<bean id="vertxReactiveExecutor" class="org.apache.camel.reactive.vertx.VertXReactiveExecutor"/> +---- + +and then Camel should detect the bean and use the reactive executor. \ No newline at end of file diff --git a/core/camel-reactive-executor-vertx/src/main/java/org/apache/camel/reactive/vertx/VertXReactiveExecutor.java b/core/camel-reactive-executor-vertx/src/main/java/org/apache/camel/reactive/vertx/VertXReactiveExecutor.java index 922b4b5..38a4262 100644 --- a/core/camel-reactive-executor-vertx/src/main/java/org/apache/camel/reactive/vertx/VertXReactiveExecutor.java +++ b/core/camel-reactive-executor-vertx/src/main/java/org/apache/camel/reactive/vertx/VertXReactiveExecutor.java @@ -35,6 +35,18 @@ public class VertXReactiveExecutor extends ServiceSupport implements ReactiveExe private static final Logger LOG = LoggerFactory.getLogger(VertXReactiveExecutor.class); private Vertx vertx; + private boolean shouldClose; + + public Vertx getVertx() { + return vertx; + } + + /** + * To use an existing instance of {@link Vertx} instead of creating a default instance. + */ + public void setVertx(Vertx vertx) { + this.vertx = vertx; + } @Override public void schedule(Runnable runnable, String description) { @@ -88,13 +100,18 @@ public class VertXReactiveExecutor extends ServiceSupport implements ReactiveExe @Override protected void doStart() throws Exception { - LOG.debug("Starting VertX"); - vertx = Vertx.vertx(); + if (vertx == null) { + LOG.debug("Starting VertX"); + shouldClose = true; + vertx = Vertx.vertx(); + } } @Override protected void doStop() throws Exception { - LOG.debug("Stopping VertX"); - vertx.close(); + if (vertx != null && shouldClose) { + LOG.debug("Stopping VertX"); + vertx.close(); + } } } diff --git a/examples/README.adoc b/examples/README.adoc index fcb112d0..0edaf62 100644 --- a/examples/README.adoc +++ b/examples/README.adoc @@ -221,6 +221,8 @@ Number of Examples: 111 (0 deprecated) | link:camel-example-kotlin/ReadMe.md[Kotlin] (camel-example-kotlin) | Other Languages | A Camel route using Kotlin +| link:camel-example-reactive-executor-vertx/readme.adoc[Reactive Executor Vertx] (camel-example-reactive-executor-vertx) | Reactive | An example for showing using VertX as reactive executor with standalone Camel + | link:camel-example-reactive-streams/readme.adoc[Reactive Streams] (camel-example-reactive-streams) | Reactive | An example that shows how Camel can exchange data using reactive streams with Spring Boot reactor diff --git a/examples/camel-example-main/pom.xml b/examples/camel-example-main/pom.xml index d33e285..43d1ee8 100644 --- a/examples/camel-example-main/pom.xml +++ b/examples/camel-example-main/pom.xml @@ -51,10 +51,6 @@ <groupId>org.apache.camel</groupId> <artifactId>camel-quartz2</artifactId> </dependency> - <dependency> - <groupId>org.apache.camel</groupId> - <artifactId>camel-reactive-executor-vertx</artifactId> - </dependency> <!-- logging --> <dependency> diff --git a/examples/camel-example-main/pom.xml b/examples/camel-example-reactive-executor-vertx/pom.xml similarity index 89% copy from examples/camel-example-main/pom.xml copy to examples/camel-example-reactive-executor-vertx/pom.xml index d33e285..ce4ecf4 100644 --- a/examples/camel-example-main/pom.xml +++ b/examples/camel-example-reactive-executor-vertx/pom.xml @@ -28,13 +28,13 @@ <version>3.0.0-SNAPSHOT</version> </parent> - <artifactId>camel-example-main</artifactId> + <artifactId>camel-example-reactive-executor-vertx</artifactId> <packaging>jar</packaging> - <name>Camel :: Example :: Main</name> - <description>An example for showing standalone Camel</description> + <name>Camel :: Example :: Reactive Executor :: VertX</name> + <description>An example for showing using VertX as reactive executor with standalone Camel</description> <properties> - <category>Beginner</category> + <category>Reactive</category> </properties> <dependencies> @@ -49,10 +49,6 @@ </dependency> <dependency> <groupId>org.apache.camel</groupId> - <artifactId>camel-quartz2</artifactId> - </dependency> - <dependency> - <groupId>org.apache.camel</groupId> <artifactId>camel-reactive-executor-vertx</artifactId> </dependency> @@ -91,7 +87,6 @@ <mainClass>org.apache.camel.example.MyApplication</mainClass> </configuration> </plugin> - </plugins> </build> diff --git a/examples/camel-example-reactive-executor-vertx/readme.adoc b/examples/camel-example-reactive-executor-vertx/readme.adoc new file mode 100644 index 0000000..49af783 --- /dev/null +++ b/examples/camel-example-reactive-executor-vertx/readme.adoc @@ -0,0 +1,15 @@ +== Camel Example Reactive Executor VertX + +This example uses VertX as the reactive executor for routing messages with Camel. +By default Camel uses its own reactive engine for routing messages, but you can plugin +different engines via a SPI interface. This example uses VertX as the engine. + +=== How to run + +You can run this example using + + mvn camel:run + +=== More information + +You can find more information about Apache Camel at the website: http://camel.apache.org/ diff --git a/examples/camel-example-reactive-executor-vertx/src/main/java/org/apache/camel/example/MyApplication.java b/examples/camel-example-reactive-executor-vertx/src/main/java/org/apache/camel/example/MyApplication.java new file mode 100644 index 0000000..8c1cc6a --- /dev/null +++ b/examples/camel-example-reactive-executor-vertx/src/main/java/org/apache/camel/example/MyApplication.java @@ -0,0 +1,38 @@ +/* + * 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.example; + +import org.apache.camel.main.Main; + +/** + * Main class that boot the Camel application + */ +public final class MyApplication { + + private MyApplication() { + } + + public static void main(String[] args) throws Exception { + // use Camels Main class + Main main = new Main(); + // and add the routes (you can specify multiple classes) + main.addRouteBuilder(MyRouteBuilder.class); + // now keep the application running until the JVM is terminated (ctrl + c or sigterm) + main.run(args); + } + +} diff --git a/examples/camel-example-reactive-executor-vertx/src/main/java/org/apache/camel/example/MyRouteBuilder.java b/examples/camel-example-reactive-executor-vertx/src/main/java/org/apache/camel/example/MyRouteBuilder.java new file mode 100644 index 0000000..003edb5 --- /dev/null +++ b/examples/camel-example-reactive-executor-vertx/src/main/java/org/apache/camel/example/MyRouteBuilder.java @@ -0,0 +1,30 @@ +/* + * 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.example; + +import org.apache.camel.builder.RouteBuilder; + +public class MyRouteBuilder extends RouteBuilder { + + @Override + public void configure() throws Exception { + from("timer:foo?period=2s") + .setBody().constant("Hello World") + .delay(simple("${random(0,1000)}")) + .log("${body}"); + } +} diff --git a/examples/camel-example-reactive-executor-vertx/src/main/resources/application.properties b/examples/camel-example-reactive-executor-vertx/src/main/resources/application.properties new file mode 100644 index 0000000..0afb55c --- /dev/null +++ b/examples/camel-example-reactive-executor-vertx/src/main/resources/application.properties @@ -0,0 +1,28 @@ +## --------------------------------------------------------------------------- +## 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. +## --------------------------------------------------------------------------- + +# to configure camel main +# here you can configure options on camel main (see MainConfigurationProperties class) +camel.main.name = MyVertXCamel +camel.main.jmx-enabled = false + +# you can also configure camel context directly +# camel.context.shutdown-strategy.shutdown-now-on-timeout = false + +# application properties +hi = Hello + diff --git a/examples/camel-example-reactive-executor-vertx/src/main/resources/log4j2.properties b/examples/camel-example-reactive-executor-vertx/src/main/resources/log4j2.properties new file mode 100644 index 0000000..d406a9f --- /dev/null +++ b/examples/camel-example-reactive-executor-vertx/src/main/resources/log4j2.properties @@ -0,0 +1,23 @@ +## --------------------------------------------------------------------------- +## 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 = Console +appender.out.name = out +appender.out.layout.type = PatternLayout +appender.out.layout.pattern = %d [%-15.15t] %-5p %-30.30c{1} - %m%n +rootLogger.level = INFO +rootLogger.appenderRef.out.ref = out diff --git a/examples/pom.xml b/examples/pom.xml index 983a3d1..e81d72e 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -94,6 +94,7 @@ <module>camel-example-opentracing</module> <module>camel-example-pojo-messaging</module> <module>camel-example-rabbitmq</module> + <module>camel-example-reactive-executor-vertx</module> <module>camel-example-reactive-streams</module> <module>camel-example-rest-producer</module> <module>camel-example-rest-swagger</module>
