Apache Camel

Revision as of 03:27, 21 September 2018 by Rasimsen (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

manuals : http://camel.apache.org/manual.html

5711687-camel4.png

Overview

Apache Camel is a versatile Java-based open source enterprise service bus and supports most of the Enterprise Integration Patterns (EIP). Camel is also known as a routing and mediation engine as it effectively routes data between endpoints, while taking heavy loads like transformation of data formats, endpoint connectivity, and much more. Apache Camel provides support for bean binding and seamless integration with popular frameworks such as CDI, Spring, Blueprint, and Guice. Camel empowers you to write rules and meditation in a variety of domain-specific languages (DSL) including Java-based Fluent API, Spring or Blueprint XML Configuration files, and a Scala DSL. Apache Camel uses URIs to work directly with any kind of Transport or messaging model such as HTTP, ActiveMQ, JMS, JBI, SCA, MINA, or CXF, as well as pluggable components and data format options.

Architecture

Camel Context provides the runtime system. Processors handles things in between endpoints like routing, transformation, validation, enrichment, etc. Endpoints connects several systems to be integrated and it acts as URI or URL in a web application or destination JMS queue. Apache Camel offers different DSLs to realize the integration problems.

Download and Extract Apache Camel

Download the Apache Camel (Camel 2.19.1) from this link

Unzip the apache-camel-x.xx.x and it will unzip all the jar files required for implementing integration solutions with Apache Camel.

Create Java Project and Add Camel Dependencies

  • Make sure you have Eclipse installed in your system for implementing Camel integrations.
  • Create a new Java project by selecting File < New < Java Project.
  • Now you need to add a jar dependency to build the path the application requires to implement Camel projects. Right click on "application" and select Build Path < Configure Build Path.
  • This will open a new dialog window. Now select Libraries < Add External Jars. You need to add camel-core-2.19.1.jar from the path \apache-camel-2.19.1\lib. Click OK.

Implementing Simple Apache Camel Integrations

Here we will implement a simple Apache Camel integration which transfers a file from one location to another.

  • Create Java class in your project and name it SimpleFileRouter.
  • Import the Apache Camel dependency into your Java class.
import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;


Camel Context

The CamelContext is the runtime system of Apache Camel and connects its different concepts, such as routes, components, or endpoints. Below is the Java code for initializing the Camel Context.

package com.file.demo;
import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
public class SimpleFileRouter {
public static void main(String [] args) throws Exception
{
CamelContext camelContext=new DefaultCamelContext();
camelContext.addRoutes(new RouteBuilder(){
});
camelContext.start();
Thread.sleep(5000);
camelContext.stop();
}
}

Domain Specific Language (DSLs)

Apache Camel offers various DSLs, such as Java-based Fluent API, Spring, or Blueprint XML Configuration files, and a Scala DSL. Spring XML DSL is based on the Spring framework and uses XML configuration. Java DSL has the best IDE support. Groovy and Scala DSLs are similar to the Java DSL; in addition, they offer the typical features of modern JVM languages, such as concise code or closures.

Routes

Routes are important when you're defining the Camel integration; it is defined as shown below.

package com.file.demo;
import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
public class SimpleFileRouter {
public static void main(String [] args) throws Exception
{
CamelContext camelContext=new DefaultCamelContext();
System.out.println("Apache Camel Context Intialize....");
try
{
camelContext.addRoutes(new RouteBuilder(){
@Override
public void configure() throws Exception
{
from("file:F:\\Apache_Camel_Test\\IN?noop=true")
.to("file:F:\\Apache_Camel_Test\\OUT");
}
});
System.out.println("File Moved To Output Directory....");
camelContext.start();
Thread.sleep(5000);
camelContext.stop();
}catch (Exception Ex) {
System.out.println(Ex.toString());
}
}
}

The DSLs are very easy to use. A file will be dropped to the input directory and it will be processed and sent to out directory. Routes have extends "RouteBuilder" and override "configure" method. The route itself begins with "from" endpoints and ends at one or more "to" endpoints.

Testing

For testing, drop the file to input directory, and run your application as a Java application. Once you run the application, the file will be moved to the output directory.

Conclusion

Apache Camel is a very powerful open source ESB and it supports most of Enterprise Integration Patterns. It is very easy to implement Camel integrations.

Now you know the basic components of Apache Camel and how to implement the integration application.



Microservices With Apache Camel

source : https://dzone.com/articles/microservices-with-apache-camel

The Apache Camel community introduced a new release a few months ago with a set of components for building microservices. Now, it has support for Hystrix Circuit Breaker and other solutions from Netflix OSS, like the Ribbon load balancer. There is also distributed message tracing with a Zipkin component, as well as service registration and discovery with Consul, etcd, Kubernetes, and Netflix Ribbon.

The new key component for microservices support is ServiceCall EIP, which allows calling a remote service in a distributed system where the service is looked up from a service registry on Kubernetes, Openshift, Cloud Foundry, Zuul, Consul, Zookeeper, etc. In addition, it is worth mentioning that now Apache Camel compiles against Java 8 and has improved support for Spring Boot. A full list of changes is available on Camel community site.

The main purpose of this article is to show how to create microservices with Apache Camel in the most common way using its new features available from release 2.18.