This project demonstrates Apache Camel integration with Kafka using a simple producer-consumer setup in a Spring Boot application. It helps understand how to work with Kafka topics, producers, consumers, and how Camel simplifies the message routing.
- Java 17+
- Spring Boot
- Apache Camel
- Kafka (via Docker)
- Docker Compose
- What is Kafka?
- Topics, Brokers, Producers, Consumers
- Apache Camel Kafka Integration
- Difference between Spring Kafka & Apache Camel Kafka
- Creating Camel Routes for sending and receiving messages
- Configuring Docker Compose for Zookeeper and Kafka
| Term | Description |
|---|---|
| Broker | A Kafka server that stores data and serves clients. |
| Topic | A named stream of records (e.g., topicNameOne). |
| Producer | Sends messages to a Kafka topic. |
| Consumer | Reads messages from a Kafka topic. |
| Zookeeper | Manages Kafka cluster metadata and leader election (required by Kafka). |
| Feature | Spring Kafka | Apache Camel Kafka |
|---|---|---|
| Abstraction Level | Low-level (you manage producer/consumer logic) | High-level (declarative routing with DSL) |
| Configuration | Manual with properties and annotations | Routes are configured using Camel DSL |
| Flexibility | Offers more fine-grained control | Offers faster development with reusable route definitions |
| Integration Capability | Kafka-specific | Supports multiple systems (Kafka, JMS, File, REST, etc.) |
| Learning Curve | Moderate to High | Easier for routing but needs learning Camel terminology |
git clone https://github.com/Sakshi0704/Apache_Camel_V1.git
cd Apache_Camel_V1docker-compose up -dThis will start:
- Zookeeper on
localhost:2181 - Kafka on
localhost:9092
./mvnw spring-boot:runOr run it from your IDE.
- KafkaSenderRoute will send a message every second to
topicNameOne. - KafkaReceiverRoute will consume the message and log it to the console.
Example Output:
INFO route1 : Send the message to consumer
INFO route2 : Send the message to consumer
You can verify Kafka is working by:
docker exec -it kafka /bin/bash
kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic topicNameOne --from-beginningApacheCamelWithKafka/
│
├── docker-compose.yml # Kafka & Zookeeper setup
├── pom.xml # Maven dependencies
├── src/
│ └── main/java/
│ └── com/apachecamel/routes/
│ ├── KafkaSenderRoute.java
│ └── KafkaReceiverRoute.java
└── README.md # Project documentation