For everyone — The universal adapter, but for data
When traveling, you always end up running into an outlet that looks like no other. Rather than adapting each device to each country, you slip a universal adapter into your suitcase: a small piece that knows how to talk to every outlet. Apache Camel plays that role in the software world: every system — database, messaging, web service, file, remote backup — has its own "outlet", and Camel provides hundreds of ready-made adapters, plus a simple language to define where the information flows, where it is transformed and where it arrives.
This routing problem is universal: every company, every administration, every website lives constantly with data that must move from one system to another, reliably and without human intervention. Such an automatic "telephone switchboard" saves hours of copy-pasting and plenty of mistakes.
For Yokul, it was a building block explored in the spirit of its method: reuse proven open source components and fit them together to move information between the parts of a simulation — event flows, environment states, results — without recoding every connection. The project has since preferred a different approach, carried by Apache Quarkus (see the note at the top of the article), but the original article remains a reference document on how to wire systems together.
The full text
Note written after the fact. Camel — like Google Guice (see Google Guice) — has since been dropped from the project, with the arrival of Apache Quarkus: the latter provides the whole set of elements that used to let Camel and Guice exist (dependency injection included, via CDI), with a more efficient implementation. The following article is kept as-is for historical reference.
What is Apache Camel?
Apache Camel is an open source integration framework that lets developers build integration solutions quickly and easily. It combines two complementary strengths:
- ready-made components, which provide connectivity with the most common systems, protocols and technologies;
- a declarative routing language (a DSL, Domain-Specific Language), which describes and orchestrates data flows between those systems.
Ready-made components
Apache Camel provides many connectivity components: databases, message queues, web services, messaging protocols, flat files, FTP, cloud services, and many others. Most build on popular third-party libraries and are maintained release after release to keep up with how those technologies evolve.
Each component handles a specific type of system: for example, camel-ftp transfers files over FTP, while camel-jms talks to JMS messaging systems. Each one is configured through its own properties, allowing fine-grained customization to fit the application's needs.
A declarative routing language
Camel's DSL lets you describe routes declaratively: you specify the data source, the transformation steps and the destination, and the library handles the delivery, the format conversions and the re-queuing when something goes wrong. Routes can be loaded dynamically from XML or configuration files, which makes them easier to manage.
These routes build on the integration patterns catalogued in the classic Enterprise Integration Patterns (Gregor Hohpe and Bobby Woolf, 2003) — adapter, messaging, aggregation, routing — which answer recurring problems: data transformation, synchronization, inter-system communication, message queuing.
A minimal example, in Java DSL: read readings from an FTP server, filter out abnormal values and send them to a JMS message queue:
from("ftp://capteurs@192.168.1.10/releves")
.unmarshal().csv()
.filter(simple("${body[2]} > 100"))
.transform(simple("Alerte : la sonde ${body[0]} a relevé ${body[2]} °C"))
.to("jms:queue:alertes");
A few Camel "bricks" are used here: FTP and JMS components at each end of the chain, CSV conversion, filtering and transformation in the middle. You could add other steps — logging, error recovery, a parallel route — without changing either the source or the destination.
Data transformations and enrichment
To convert data from one format to another, Camel ships transformers based on proven libraries such as XStream, JAXB or Jackson. Developers can also write their own transformers for specific formats; they are applied upstream or downstream of routes, as needed.
A flow can also be enriched with information from external sources: an HTTP, SOAP or REST call to a web service, for example, can top up the data in flight (fetching a customer's balance, the weather at a site, and so on).
Reliability and error handling
Camel provides error-handling mechanisms to guarantee the reliability and robustness of flows: logging and error notification, queuing of pending messages, and re-injection of failed messages into the flow. These mechanisms can be defined globally for the application, or case by case for each route.
Integration with the Spring ecosystem
Camel integrates naturally with the Spring ecosystem: the camel-spring module lets you define routes inside a Spring application context, and Camel ships a starter for Spring Boot that starts the Camel context and automatically loads the detected routes. The application then benefits from Spring's dependency injection mechanism, and Camel remains driven by the project's dependencies.
But nothing forces you to use Spring: Camel also runs in plain Java (as in the example above) or embedded in an application server.
Where Camel is used
- Integrating heterogeneous systems, leaning heavily on ready-made components and transformers;
- Communicating with cloud services (Amazon Web Services, Microsoft Azure, Google Cloud Platform);
- Centralized file management: transfer, transformation, aggregation as the application requires;
- Consuming and exposing web services (SOAP, REST), with enrichment from external sources;
- Enterprise application integration (ERP, CRM, databases).
Key takeaways
- Camel combines hundreds of connectivity components and a declarative routing language: two bricks that can stand on their own, but reinforce each other.
- Routes rely on proven integration patterns — no need to reinvent the wiring between systems.
- Error handling (queues, replay of failed messages) is built into the core of routes, not bolted on afterwards.
See also
- Google Guice
- Apache Quarkus
- Apache Maven
- Message queues — the queues these routes move data through