Quick Kafka Setup & Usage Guide
To quickly set up and start using Kafka, you can follow these steps:
- To download Kafka, first, you need to download the latest version from the official website (https://kafka.apache.org/downloads). Choose the version that is compatible with your operating system.
- Decompress Kafka: Once the download is complete, unzip the Kafka compressed file into the directory of your choice.
- Start Zookeeper: Kafka relies on Zookeeper to manage the cluster’s state. Navigate to the bin folder in the Kafka directory and run the following command to start Zookeeper:
./zookeeper-server-start.sh ../config/zookeeper.properties
- Start Kafka: In the same bin directory, run the following command to start the Kafka server:
./kafka-server-start.sh ../config/server.properties
- Create a Topic: Use the command below to create a topic named “test”.
./kafka-topics.sh --create --topic test --bootstrap-server localhost:9092 --partitions 1 --replication-factor 1
- Publishing and consuming messages: Use the following command to publish a message to the newly created topic:
./kafka-console-producer.sh --topic test --bootstrap-server localhost:9092
Use the following command to consume messages:
./kafka-console-consumer.sh --topic test --bootstrap-server localhost:9092 --from-beginning
By following the above steps, you can quickly install and use Kafka, and start publishing and consuming messages. Hope it helps!