Apache Camel Integration with Kafka
This article covers the integration of Apache Camel with Kafka, from setup to testing, with code blocks and plenty of pictures!
Join the DZone community and get the full member experience.Join For Free
This article covers Apache Camel Integration with Kafka.
We will launch Kafka as a docker container.
From the path of the docker-compose.yml file run the below command and observe that the Kafka cluster is successfully started.
Open Kafka Console at http://localhost:3030
A screen like the below opens:
Let us create 2 Springboot camel microservices,
camel-demo-a will publish the data to Kafka topic which will be consumed by
pom.xml of both the microservices, add the below dependency.
Configure the Kafka broker URL in the
Configuring the KafkaSenderRoute in
The route is configured to read from the file and publish to Kafka topic:
Configuring the KafkaReceiverRoute in
Let us assume that the sender route is publishing a JSON message, which we will unmarshal and do some processing.
camel-demo-b application, add below dependency:
Creating the Model class:
The route is configured to consume the message from the Kafka topic, unmarshal using the Jackson JSON library and do some processing.
camel-demo-a application and place the json file in the input folder:
The file will be read and the message will be published on the Kafka topic.
camel-demo-b application. Observe that the route consumes the message from the Kafka topic, performs json unmarshalling, and further processing.
Opinions expressed by DZone contributors are their own.