How to start Apache Camel: Message Router with Spring Boot

Apache Camel supports most of the Enterprise Integration Pattern, an engine for routing message. The tutorial will guide you how to start with Apache Camel by Spring Boot.

Related Articles:
How to start Spring Apache Kafka Application with SpringBoot
How to use Spring JMS with ActiveMQ – JMS Consumer and JMS Producer | Spring Boot

I. Technologies for Apache Camel tutorial

– Java 1.8
– Maven 3.3.9
– Spring Tool Suite – Version 3.8.1.RELEASE
– Spring Boot: 1.4.0.RELEASE
– ActiveMQ 5.8.0 Release

II. Overviews
1. Structure of project

apache camel message router - structure of project

2. Step to do

– Create Spring Boot project
– Add needed dependencies
– Configure main run controller for Camel
– Create ActiveMQ Connection bean
– Create Router class
– Run & check result

3. Demo video
III. Practices
1. Create Spring Boot project

Open Spring Tool Suite, on main menu choose File->New->Spring Starter Project, input project info as below:

spring apache router - create spring boot project

Press Next then Finish. Spring Boot project is created successfully.

2. Add needed dependencies

3. Configure main run controller for Camel

Config Run Controller for Camel, open application .properties , add configuration:

4. Create ActiveMQ Connection bean

Create ActiveMQComponent for connection factory

Import org.apache.activemq.camel.component.ActiveMQComponent in main class:

5. Create Router class

– Create Camel Router class, routing message from IN queue to “OUT” queue.
if: message in IN queue contains o1, message is routed to OUT_1 queue, else if message contains o2, it will be routed to OUT_2 queue. Otherwise, it will be routed to OUT_3.

6. Download & Run ActiveMQ

Download ActiveMQ from: activemq.apache.org

http://activemq.apache.org/activemq-580-release.html

Go to bin folder, run wrapper

activemq

CMD:

active mq start

7. Run & check result

Maven build:
clean install

Maven Run mode Spring Boot App

– Send a message to IN queue with content: Hello World

Send message spring apache camel router

Result:

Send message spring apache camel router

– Send a message to IN queue with content: o1: Welcome to Apache Router

Send message spring apache camel router - o1

Result:

Send message spring apache camel router - o1 - result

– Send a message to IN queue with content: o2: Have a nice day!

Send message spring apache camel router - o2

Result:

Send message spring apache camel router - o2 -result

IV. Source code

apache-router


Related Posts


Got Something To Say:

Your email address will not be published. Required fields are marked *

*