An example which shows how to integrate Camel with Kafka.
This project consists of the following examples:
-
Send messages continuously by typing on the command line.
-
Example of partitioner for a given producer.
-
Topic is sent in the header as well as in the URL.
This example requires that Kafka Server is up and running. For this, assuming that environment variable KAFKA has been
set to the home directory of the Kafka distribution, you will need to start ZooKeeper and a Kafka Broker thanks to
the next commands:
On Windows run
$ %KAFKA%\bin\windows\zookeeper-server-start.bat ${KAFKA}/config/zookeeper.properties
$ %KAFKA%\bin\windows\kafka-server-start.bat ${KAFKA}/config/server.propertiesOn linux run
$ ${KAFKA}/bin/zookeeper-server-start.sh ${KAFKA}/config/zookeeper.properties
$ ${KAFKA}/bin/kafka-server-start.sh ${KAFKA}/config/server.propertiesYou will need to create following topics before you run the examples.
On Windows run
$ %KAFKA%\bin\windows\kafka-topics.bat --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 2 --topic TestLog
$ %KAFKA%\bin\windows\kafka-topics.bat --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic AccessLogOn linux run
$ ${KAFKA}/bin/kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 2 --topic TestLog
$ ${KAFKA}/bin/kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic AccessLogRun the consumer first in a shell
$ mvn exec:java -Pkafka-consumerRun the message producer in a separate shell
$ mvn exec:java -Pkafka-producerInitially, some messages are sent programmatically.
On the command prompt, type the messages. Each line is sent as one message to kafka
Press Ctrl+C to exit.
You can configure the details in the file:
src/main/resources/application.properties
You can enable verbose logging by adjusting the src/main/resources/log4j2.properties
file as documented in the file.
If you hit any problem using Camel or have some feedback, then please let us know.
We also love contributors, so get involved :-)
The Camel riders!