Hello everyone, In this post, you will learn Simple Hello World in Apache Camel. The example has been tested and shared in the post.
Maven Dependency
<dependency> <groupid>org.apache.camel</groupid> <artifactid>camel-core</artifactid> <version>${camel-version}</version> </dependency>
Camel Router
package com.dineshkrish.example1; import org.apache.camel.builder.RouteBuilder; /** * * @author Dinesh Krishnan * */ public class HelloWorldRouter extends RouteBuilder { @Override public void configure() throws Exception { // implementation goes here System.out.println("Hello World..."); } }
Final Program
package com.dineshkrish.example1; import org.apache.camel.CamelContext; import org.apache.camel.impl.DefaultCamelContext; /** * * @author Dinesh Krishnan * */ public class HelloWorldCamel { public static void main(String[] args) { // creating an instance for camel context CamelContext context = new DefaultCamelContext(); // creating an instance for router HelloWorldRouter router = new HelloWorldRouter(); try { // adding router to context context.addRoutes(router); // starting the camel context context.start(); // stopping the camel context context.stop(); } catch (Exception e) { e.printStackTrace(); } } }
Output
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". SLF4J: Defaulting to no-operation (NOP) logger implementation SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details. Hello World...
More from my site
Hello, folks, I am a founder of dineshkrish.com. I love Java and Open source technologies, If you find my tutorials are useful, please consider making donations to these charities.