Quarkus and Apache Camel

Writing a Java integration service with just 2 files, it is possible!

One of the biggest arguments against Java that is always coming up in discussions is the fact that it is bloated. In comparison to some other (newer) languages I always had to agree. However lately a lot of new cool frameworks / features have been released or are set to released in the coming period. One of those frameworks is Quarkus, and the guys behind Camel have jumped on that bandwagon (both are backed by Red Hat). This has resulted in Camel being able to run on Quarkus with minimal effort from our (the developers) side. Just 2 files and you have a route up and running (you can even create a native image!)

First of all, we need a pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
   <parent>
    <groupId>org.apache.camel.quarkus</groupId>
       <artifactId>camel-quarkus-bom</artifactId>
       <version>1.0.0-CR2</version>
   </parent>

   <modelVersion>4.0.0</modelVersion>

   <artifactId>quarkus-file</artifactId>
   <name>Camel Quarkus :: Rubix ::  RTest</name>

   <properties>
       <mvnd.builder.rule>camel-quarkus-jackson-deployment,camel-quarkus-platform-http-deployment,camel-quarkus-support-policy-deployment</mvnd.builder.rule>
   </properties>

   <dependencies>
       <dependency>
           <groupId>org.apache.camel.quarkus</groupId>
           <artifactId>camel-quarkus-platform-http</artifactId>
       </dependency>
       <dependency>
           <groupId>org.apache.camel.quarkus</groupId>
           <artifactId>camel-quarkus-jackson</artifactId>
       </dependency>
       <dependency>
           <groupId>org.apache.camel</groupId>
           <artifactId>camel-timer</artifactId>
       </dependency>
       <dependency>
           <groupId>org.apache.camel</groupId>
           <artifactId>camel-log</artifactId>
       </dependency>


       <!-- test dependencies -->
       <dependency>
           <groupId>io.quarkus</groupId>
           <artifactId>quarkus-junit5</artifactId>
           <scope>test</scope>
       </dependency>
       <dependency>
           <groupId>io.rest-assured</groupId>
           <artifactId>rest-assured</artifactId>
           <scope>test</scope>
       </dependency>
   </dependencies>

   <build>
       <plugins>
           <plugin>
               <groupId>io.quarkus</groupId>
               <artifactId>quarkus-maven-plugin</artifactId>
               <executions>
                   <execution>
                       <id>build</id>
                       <goals>
                           <goal>build</goal>
                       </goals>
                   </execution>
               </executions>
           </plugin>
       </plugins>
   </build>

   <profiles>
       <profile>
           <id>native</id>
           <activation>
               <property>
                   <name>native</name>
               </property>
           </activation>
           <properties>
               <quarkus.package.type>native</quarkus.package.type>
           </properties>
           <build>
               <plugins>
                   <plugin>
                       <groupId>org.apache.maven.plugins</groupId>
                       <artifactId>maven-failsafe-plugin</artifactId>
                       <executions>
                           <execution>
                               <goals>
                                   <goal>integration-test</goal>
                                   <goal>verify</goal>
                               </goals>
                           </execution>
                       </executions>
                   </plugin>
               </plugins>
           </build>
       </profile>
   </profiles>

</project>

Next we need a java class that holds the camel route:

In my case src/main/java/nl/rubix/file.java

package nl.rubix;

import org.apache.camel.builder.RouteBuilder;

public class file extends RouteBuilder {

   private final String period = "10000";

   @Override
   public void configure() throws Exception {
       fromF("timer:foo?period=%s", period)
               .setBody(constant("Banana"))
               .to("log:example?showExchangePattern=false&showBodyType=false");
   }
}


Now, simply run: mvn quarkus:dev and sit back and relax. When all is good and well you should see something like:

2020-06-08 17:09:54,679 INFO  [org.apa.cam.imp.eng.AbstractCamelContext] (Quarkus Main Thread) StreamCaching is not in use. If using streams then its recommended to enable stream caching. See more details at http://camel.apache.org/stream-caching.html
2020-06-08 17:09:54,679 INFO  [org.apa.cam.imp.eng.AbstractCamelContext] (Quarkus Main Thread) Route: route3 started and consuming from: timer://foo
2020-06-08 17:09:54,680 INFO  [org.apa.cam.imp.eng.AbstractCamelContext] (Quarkus Main Thread) Total 1 routes, of which 1 are started
2020-06-08 17:09:54,680 INFO  [org.apa.cam.imp.eng.AbstractCamelContext] (Quarkus Main Thread) Apache Camel 3.3.0 (CamelContext: camel-3) started in 0.001 seconds
2020-06-08 17:09:54,680 INFO  [io.quarkus] (Quarkus Main Thread) camel-quarkus-examples-rest-json 1.0.0-CR2 on JVM (powered by Quarkus 1.5.0.Final) started in 0.305s. Listening on: http://0.0.0.0:8080
2020-06-08 17:09:54,680 INFO  [io.quarkus] (Quarkus Main Thread) Profile dev activated. Live Coding activated.
2020-06-08 17:09:54,681 INFO  [io.quarkus] (Quarkus Main Thread) Installed features: [camel-core, camel-jackson, camel-platform-http, camel-support-common, camel-support-xml, cdi, mutiny, vertx, vertx-web]
2020-06-08 17:09:55,680 INFO  [example] (Camel (camel-3) thread #2 - timer://foo) Exchange[Body: Banana]

That is it!