Saturday 25 June 2016

Getting Started with Apache Camel using Spring Boot

Well, I am not going to write post to introduce Apache Camel and EIP concepts. Rather I'll just provide quick highlights of the Spring Boot based project skeleton, which I implemented to integrate hawtio and try it with Apache Camel @ https://github.com/tirthalpatel/Learning-Camel/tree/master/gs-camel-spring-boot-helloworld. For promptly getting started with it, you should obviously know Maven, Java and Spring (not necessarily Spring Boot).

First Things First - Understanding Fundamentals


  • Apache Camel is an open-source, lightweight, integration library that allows your applications to accomplish intelligent routing, message transformation, and protocol mediation using the established Enterprise Integration Patterns and out-of-the-box components with a highly expressive Domain Specific Language (Java, XML, or Scala). With Camel you can implement integration solutions as part of an overarching ESB solution, or as individual routes deployed to any container such as Apache Tomcat, Apache ServiceMix, JBoss AS, or even a stand-alone java process. Read more @ DZone Refcard - Essential Camel Components.
  • Enterprise Integration Patterns (EIP): Integration is a hard problem. To help deal with the complexity of integration problems the Enterprise Integration Patterns (EIP) have become the standard way to describe, document and implement complex integration problems. Apache Camel is an open source project for implementing the EIP easily in a few lines of Java code or Spring XML configuration. Read more @ DZone Refcard - The Top Twelve Integration Patterns for Apache Camel.
  • Integration Framework vs. ESB vs. Integration Suite: See remarkable presentation by Kai Wähner @ Spoilt for Choice: How to Choose the Right Enterprise Service Bus (ESB)?

Get Started with Apache Camel Practically

If you don't  know, what is Spring Boot, then immediately read about it. Believe me, it has already become super popular in Java world. Spring Boot nicely gels with Apache Camel too. Anyway you may get started with Apache Camel by following below steps, even if you don't know Spring Boot.

  1. Download or Clone "gs-camel-spring-boot-helloworld" project from Github.
  2. Prerequisites:
    • Java 1.8+
    • Maven (If maven is not installed on your machine, then just use maven wrapper "mvnw", which is already in project. Be aware that you may need to configure proxy settings, if you are in restricted corporate network.)
    • Spring STS or alternate IDE (Optional, but recommended)
  3. Run maven command at project's root to run project: gs-camel-spring-boot-helloworld > mvn spring-boot:run
  4. This would start Spring Boot's embedded server on default 8080 port. In case you need to change it to different port, then you can configure in "application.properties" file at "gs-camel-spring-boot-helloworld\src\main\resources".
  5. Refer README file to import project in IDE or maven's alternative option to run it.
  6. Once you successfully run it, you should see following logs without errors. Well, App.java does all magic to provide Camel Context with help of Spring Boot. (Alternatively, we may write code for creating Camel Context without using Spring.)
  1. Next, you can see logs for executed example code of router configurations, which is using Camel Java DSL.
  1. Then, open hawtio web console in browser @ http://localhost:8080/hawtio/index.html, which I have already integrated in the project. You can see "HelloWorldRouterFirst.java" has timer component, which triggers events and sends to "direct:helloWorldChannel" end-point. In "HelloWorldRouterSecond.java", it route message from "direct:helloWorldChannel" end-point to further. You can see, "HelloWorldRouterFirst.java" has implemented "Deal Letter Channel EIP". To try it practically, just pause or stop "hw-ex1-second-router-direct-process-log" route and see how it reacts. When "hw-ex1-second-router-direct-process-log" is running, it does its job as per configuration in "HelloWorldRouterSecond.java". When "hw-ex1-second-router-direct-process-log" is unavailable (paused or stopped), all events triggered by "hw-ex1-first-router-timer-bean-direct" route would go to "DeadHelloWorldQueue" queue automatically as per configured Camel provided "Deal Letter Channel EIP".
  1. Likewise, following snapshot speaks about another "HelloWorldJmsRouter.java" example router.
  1. Finally, you can implement few examples in similar way using any Camel supported DSL and Components as per your interest. Just ensure to annotate router component with @Component annotation, implement camel's RouteBuilder and add necessary dependencies in Maven's pom.xml. (Read Apache Camel with Spring Boot post to understand how we get Camel context magically.)

Also Refer

No comments:

Post a Comment