Kafka Introduction Series—2. Topic creation and storage

1. First start zookeeper and kafka

  • Start zookeeper in the foreground

    bin/zkServer.sh start-foreground
    
  • Start kafka

     bin/kafka-server-start.sh config/server.properties
    

2. Topic command line tool

You must specify topic when sending messages to or receiving messages from Kafka .

The following command can view the existing topics in Kafka:

 

bin/kafka-topics.sh --zookeeper localhost:2181 --list

The --zookeeper localhost:2181parameters are required.

  • Create a topic( --create)

     bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic testtopic
    

You can view after creating testtopic

  • View topic information ( --describe)

     bin/kafka-topics.sh --describe --topic testtopic --zookeeper localhost:2181
    

Testtopic information: 1 partition, 1 copy

You can see that the number of partitions is 1, and the replicationfactor is 1, because the parameters specified when creating testtopic are as follows:

 

--replication-factor 1 --partitions 1 

3. Data stored in zookeeper

Kafka topic information is stored in zookeeper.

  • Use the zkCli.shcommand line tool to connect to the zookeeper server.

    bin/zkCli.sh -server localhost:2181
    
  • Zookeeper is a tree structure with a root node /. The following command can view all the child nodes under the root node.

Child nodes under the zookeeper root node

  • The topic information is stored in the /config/topicspath, and you can see the testtopic just created.

    ls /config/topics
    

Topics stored in zookeeper

 

Guess you like

Origin blog.csdn.net/mrlin6688/article/details/106882773