Installation and use of kafka under Windows

1. Kafka installation

Official website installation address

Installation prerequisites, kafka installation and operation minimum support jdk7; the demo version of this article is based on jdk1.8;

Currently, Kafka has built-in zookeeper, no need to download zookeeper separately

After downloading for windows, you can unzip it

Two, start

1. Start zookeeper

bin\windows\zookeeper-server-start.bat config\zookeeper.properties 

A strange error will be reported here, the command line is too long, directly extract the compressed package to the root directory or desktop for operation

insert image description here

Minimize the length of folder names or do not nest too many layers of folders

Start successfully
insert image description here

2. Start kafka

Start the kafka server command

bin\windows\kafka-server-start.bat config\server.properties

Start successfully
insert image description here

Three, use

1. Create Topic

bin/windows/kafka-topics.bat --create --bootstrap-server localhost:9092 --topic test --partitions 1 --replication-factor 1

The above command creates the test topic

2. View Topic

bin/windows/kafka-topics.bat --list --bootstrap-server localhost:9092

3. Send a message

As explained in the previous introduction to Kafka terminology, in the process of using Kafka, the message producer first needs to send a message, and then the consumer can read the message.

Start a terminal A and execute the following command,

> bin/windows/kafka-console-producer.bat --broker-list localhost:9092 --topic test
> hello

When the producer script is executed, a message input prompt will appear, where we can enter a message (data), and then it will be sent to the corresponding server (Broker).

4. Receive messages

Now that there is data in the pipeline, I can use the consumer to read the data.

In addition, start a terminal B and execute the following command,

> ./bin/windows/kafka-console-consumer.bat --bootstrap-server localhost:9092 --topic test 
hello world

Guess you like

Origin blog.csdn.net/weixin_42838061/article/details/123953574