Apache Camel Complete Reference Guide

What is Apache Camel?

Apache Camel is an open-source integration framework that implements Enterprise Integration Patterns (EIPs). It enables communication between applications, APIs, databases, messaging systems, cloud services, and files using a simple routing engine.

Apache Camel = Routing + Transformation + Integration Framework

Core Concepts

Concept Description
CamelContext Runtime container that manages routes and components.
Route Flow of messages from source to destination.
Processor Custom business logic executed inside routes.
Exchange Message container carrying body, headers, and properties.
Message Actual payload being processed.

Domain Specific Languages (DSLs)

DSL Description
Java DSL Programmatic route configuration.
Spring XML DSL XML-based route definitions.
YAML DSL Declarative route configuration.
Groovy / Kotlin Alternative DSLs.

Enterprise Integration Patterns (EIPs)

Pattern Usage
Content-Based Router Route based on message content.
Splitter Break one message into many.
Aggregator Combine multiple messages.
Recipient List Dynamic routing to multiple endpoints.
Wire Tap Copy message to another route.
Dead Letter Channel Handles failed messages.
Retry / Redelivery Retry failed processing.
Idempotent Consumer Avoid duplicate processing.

Camel Components

Category Components
File file, ftp, sftp
Messaging jms, kafka, rabbitmq, activemq
HTTP http, rest, servlet, netty-http
Database jdbc, sql, jpa, mybatis
Cloud aws-sqs, azure-storage-queue, gcp-pubsub
Scheduling timer, quartz

Error Handling

Feature Description
DefaultErrorHandler Retries with backoff policy.
DeadLetterChannel Moves failed messages to DLQ.
OnException Handle specific exceptions.
Try-Catch-Finally Structured exception handling.

Apache Camel with Spring Boot

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

Camel routes are automatically discovered and loaded by Spring Boot.

Apache Camel with RabbitMQ

Dependencies

<dependency>
    <groupId>org.apache.camel.springboot</groupId>
    <artifactId>camel-rabbitmq-starter</artifactId>
</dependency>

Producer Route

<route id="direct-to-rabbitmq">
    <from uri="direct:sendToRabbit"/>
    <to uri=
"rabbitmq:exchange1?routingKey=mykey&queue=myqueue"/>
</route>

Consumer Route

<route id="rabbitmq-to-logger">
    <from uri=
"rabbitmq:exchange1?routingKey=mykey&queue=myqueue"/>

    <log message=
"Received from RabbitMQ: ${body}"/>
</route>

Real-Time EIP Examples

Aggregator Pattern - Order Processing

Combines billing, inventory, and shipping messages into a complete order.

Content-Based Router - Banking Fraud Detection

from("direct:transactions")
    .choice()
        .when(simple("${body.amount} > 500000"))
            .to("direct:manualReview")
        .otherwise()
            .to("direct:autoProcess");

Splitter Pattern - Invoice Processing

from("direct:bulkInvoice")
    .split()
    .jsonpath("$.items")
    .to("direct:processLineItem");

Recipient List Pattern

from("direct:orderShipped")
    .recipientList(header("emailRecipients"));

Wire Tap Pattern

from("direct:paymentProcessed")
    .wireTap("direct:auditService")
    .to("direct:continueProcessing");

Routing Slip Pattern

from("direct:startApproval")
    .routingSlip(header("approvalSteps"));

Dead Letter Channel Example

errorHandler(
 deadLetterChannel("jms:deadLetterQueue")
    .maximumRedeliveries(3)
    .redeliveryDelay(2000)
);

from("direct:paymentRequest")
    .to("bean:paymentService");

Testing & Monitoring

Tool Purpose
CamelTestSupport Unit testing Camel routes.
AdviceWith Modify routes during testing.
JMX Monitor routes and metrics.
Hawt.io Web UI for route monitoring.
Jolokia JMX over HTTP.

Advanced Features

Common Camel Abbreviations

Abbreviation Meaning
EIP Enterprise Integration Pattern
DSL Domain Specific Language
JMS Java Message Service
DLQ Dead Letter Queue
SEDA Staged Event Driven Architecture
JMX Java Management Extensions
KEDA Kubernetes Event Driven Autoscaling
OAS OpenAPI Specification

Camel Architecture Flow

Source Endpoint
      |
      v
    Route
      |
      v
 Processor
      |
      v
Transformation
      |
      v
 Destination Endpoint

Interview Questions

  1. What is Apache Camel?
  2. What is CamelContext?
  3. What is an Exchange?
  4. Difference between Processor and Route?
  5. What are EIPs?
  6. Explain Splitter and Aggregator.
  7. What is Dead Letter Channel?
  8. How does Content-Based Router work?
  9. What is SEDA in Camel?
  10. Difference between Camel K and Camel Spring Boot?
  11. How do you integrate Camel with RabbitMQ?
  12. How do you monitor Camel routes?

Apache Camel Interview Quick Reference

1. What is Apache Camel?

Apache Camel is an integration framework that implements Enterprise Integration Patterns (EIPs) to connect different systems.

from("file:input")
.to("jms:queue:orders");
    

2. What is CamelContext?

CamelContext is the runtime container that manages routes, components, endpoints, and services.

CamelContext context = new DefaultCamelContext();
context.start();
    

3. What is an Exchange?

Exchange is the message container that carries data between endpoints.

exchange.getIn().getBody(String.class);
    

4. Difference Between Processor and Route?

Processor: Contains business logic.

Route: Defines message flow.

from("direct:start")
.process(new MyProcessor())
.to("log:output");
    

5. What are EIPs?

Enterprise Integration Patterns are reusable solutions for integration problems.

Examples: Splitter, Aggregator, Router, Filter, Dead Letter Channel.

6. Explain Splitter and Aggregator

Splitter: Splits one message into multiple messages.

Aggregator: Combines multiple messages into one.

from("direct:start")
.split(body())
.to("log:item");
    

7. What is Dead Letter Channel?

Handles failed messages and redirects them to an error queue.

errorHandler(
 deadLetterChannel("jms:queue:error")
);
    

8. How Does Content-Based Router Work?

Routes messages based on content or conditions.

from("direct:start")
.choice()
.when(header("type").isEqualTo("A"))
.to("direct:A")
.otherwise()
.to("direct:B");
    

9. What is SEDA in Camel?

SEDA (Staged Event-Driven Architecture) enables asynchronous processing using an in-memory queue.

from("seda:orders")
.to("bean:orderService");
    

10. Difference Between Camel K and Camel Spring Boot?

Camel K Camel Spring Boot
Runs natively on Kubernetes/OpenShift Runs as Spring Boot application
Serverless Integration Microservice Integration
Lightweight Full Spring Ecosystem

11. How Do You Integrate Camel with RabbitMQ?

Use RabbitMQ component to publish and consume messages.

from("rabbitmq:orders")
.to("bean:orderProcessor");
    

12. How Do You Monitor Camel Routes?

management.endpoints.web.exposure.include=*