Apache Camel overview and Integration Apache Camel with Spring Boot

Reading Time: 3 minutes

Introduction

Camel is an open-source integration framework designed to make integrating systems simple and easy.

It uses URIs to enable easier integration with all types of transport or messaging model including HTTP, ActiveMQ, JMS, JBI, SCA, MINA, or CXF together with working with plug-gable Data Format options.

Camel is a undersized library that has minimal dependencies for painless embedding in any Java application. Apache Camel lets you operate with the same API regardless of the transport type, making it possible to interact with all the components supplied out-of-the-box, with a good understanding of the API.

It has robust Bean Binding and is integrated seamlessly with popular frameworks such as Spring, Quarkus, and CDI.

Apache Camel Features

1.Easy Configuration – Camel uses an easy and intuitive URI configuration.

2. Automatic type converter – Camel has a built-in type-converter mechanism that ships with more than 150 converters.

3.Modular and plug-gable architechture – Camel has a modular architecture, which allows any component to be loaded into Camel, regardless of whether the component ships with Camel, is from a third party, or is your own custom creation.

4.Domain specific language – Camel is unique because it offers multiple DSLs in regular programming languages such as Java, Scala, Groovy, and it also allows routing rules to be specified in XML.

The purpose of the DSL is to allow the developer to focus on the integration problem rather than on the tool

5.Routing and mediation engine – The core feature of Camel is its routing and mediation engine. A routing engine will selectively move a message around, based on the route’s configuration.

Camel Architecture and its Concepts

Apache Camel Architecture consists of a Camel Context that includes a group of Component instances. A Component is a manufacture of Endpoint instances, we can explicitly configure Component instances in Java

An Endpoint is either a URI or URL in a web application or a Destination in a JMS system. We can transmit with an endpoint either by sending messages to it or consuming messages from it.
We can then create a Producer or Consumer on an Endpoint to trade messages with it

The architecture of Camel is simple. Camel illustrates the Camel runtime system, and it wires additional concepts such as routes, components, or endpoints. Additionally, the processors handle routing and transformations between parameters, while endpoints integrate disparate systems.

EndPoints

Below are the use of consumer endpoint and producer endpoint, by there URIs.

from("file:messages/test")
    .to("jms:queue:test")

<route>
    <from uri="file:messages/test"/>
    <to uri="jms:queue:test"/>
</route>

Endpoints API

Camel support the message endpoint pattern using endpoint interface.
1. createProducer() will create a Producer for sending message exchanges to the endpoint.


2.createConsumer() implements the Event Driven Consumer pattern for consuming message exchanges from the endpoint via a Processor when creating a Consumer.


3.createPollingConsumer() implements the Polling Consumer pattern for consuming message exchanges from the endpoint via a Polling-consumer.

Implementation

In the Maven we need the camel dependency in pom.xml.Maven will be as follows-

<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">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.javainuse</groupId>
  <artifactId>springboot-camel</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  
 <dependencies>

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-spring-boot-starter</artifactId>
    <version>2.17.0</version>
</dependency>

</dependencies>
</project>

Create the SpringBootHelloApplication.java as below-

package com.test.apachecamel;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class SpringBootHelloApplication {

	public static void main(String[] args) {
		SpringApplication.run(SpringBootHelloApplication.class, args);
	}
}


Next we add class with the Camel routes.This routes will be started automatically.

package com.test.apachecamel;

import org.apache.camel.builder.RouteBuilder;
import org.springframework.stereotype.Component;

@Component
public class Route extends RouteBuilder {

	@Override
	public void configure() throws Exception {
		from("file:C://inputFolder?noop=true").to("file:C://outputFolder");
	}
}

Add camel.springboot.main-run-controller=true to the application.properties to keep thread blocked.

camel.springboot.main-run-controller=true

This code is only needed to get started. Compile and run the SpringBootHelloApplication.java as a Java application.

Conclusion

Apache Camel is a majestic framework for integrating applications with different technologies and protocols. The best part except for exceptional support for various technologies is that we can always use identical concepts.

As the number of applications and technologies additions, Apache Camel is a suitable option for integrating them.

Discover more from Knoldus Blogs

Subscribe now to keep reading and get access to the full archive.

Continue reading