May 22, 2017

Consuming files from folders with Apache Camel

Apache Camel is a an open-source integration framework written in Java that helps the user implement many of the design patterns defined in the book Enterprise Integration Patterns by Gregor Hohpe and Bobby Woolf. The book discusses 65 design patterns for asynchronous messaging systems and Camel implements many of the design patterns in the EIP book.
Aim of Camel is to make easier the integration of different applications which use several protocols and technologies.
In this article I make use of some fundamental Camel objects like Route Builder, Processor and File Component to poll a given directory and consume from a file endpoint. You can find further details here:

camel-polling-directory-01

Stack

Apache Camel 2.17.3
JDK 1.8
Maven 3.2

Source

SUBVERSION
svn co https://github.com/giuseppeurso-eu/activemq/trunk activemq-samples
GIT
git clone https://github.com/giuseppeurso-eu/activemq

The source code covered in this post is located under the subfolder camel-polling-directory.

ConsumerRouteBuilder.java

The endpoint URI builder. The File component provides access to file systems, allowing files to be processed by a Consumer.

CamelExecutor.java

The CamelContext initializer. This class make use of Thread.sleep to simulate a runtime system of 30 seconds. During the poll operation, the ConsumerRouteBuilder is used to monitor the state of the source directory and then start message exchanges.

ConsumerProcessor.java

The processor of files from the source directory.

 

Related posts

Leave a Reply

Your email address will not be published.