Skip to content

Sakshi0704/Apache_Camel_V2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 

Repository files navigation

Apache Camel V2 - Kafka and Apache Camel Integration in Spring Boot with Docker Compose

This project demonstrates a seamless integration between Apache Camel, Kafka, and Spring Boot, allowing message routing and transformation between REST APIs and Kafka topics. The application is built to showcase how you can produce and consume messages using Apache Camel routes and processors.

🚀 Features

  • REST API to send messages directly to Kafka
  • Camel-based routing for Kafka consumer
  • Kafka topic configured via application.properties
  • Custom message processing using a Camel Processor

🛠️ Technologies Used

  • Java 11+
  • Spring Boot
  • Apache Camel
  • Apache Kafka
  • Maven

📁 Project Structure

apachecamel/
├── controller/
│   └── MessageProducerController.java
├── processor/
│   └── MetadataProcessor.java
├── routers/
│   └── KafkaConsumerRoute.java
└── ApachecamelApplication.java

📦 Dependencies

Declared in pom.xml, including:

  • spring-boot-starter
  • camel-spring-boot-starter
  • camel-kafka
  • spring-boot-configuration-processor

📡 API Endpoints

POST /api/send-direct

Description: Sends a message directly to the configured Kafka topic.

Request Parameters:

  • message (String): The message content to send.

Example:

POST http://localhost:8080/api/send-direct?message=HelloKafka

Response:

"Message sent directly to Kafka topic: <your-topic-name>"

POST /api/send-with-route

POST /api/send-with-metadata

Note: Including "fail" you will find the consume retry process

🔄 Camel Route

Kafka Consumer Route

Defined in KafkaConsumerRoute.java:

  • Listens to messages from the Kafka topic (configured via application.properties)
  • Passes the incoming message to MetadataProcessor.java for transformation or logging
  • Logs final message to the console or another configured endpoint

🧠 Processor

MetadataProcessor.java

This Camel processor handles the incoming Kafka message:

  • Logs metadata
  • Optionally enriches or modifies the message
  • Can be extended for further business logic

⚙️ Configuration

All necessary configurations should be placed in application.properties.

Example:

server.port=8080

# Kafka Configuration
kafka.topic.name=demo-topic
kafka.bootstrap.servers=localhost:9092

🚀 How to Run the Project

1. Clone the Repository

git clone https://github.com/Sakshi0704/Apache_Camel_V2.git
cd Apache_Camel_V2

2. Start Kafka and Zookeeper via Docker Compose

docker-compose up -d

This will start:

  • Zookeeper on localhost:2181
  • Kafka on localhost:9092

3. Run the Spring Boot Application

./mvnw spring-boot:run

Or run it from your IDE.


About

Kafka and Apache Camel Integration in Spring Boot with Docker Compose

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages