Kafka3.0.0 version - producer, consumer command line operation

1. Kafka cluster deployment

Two, three server information

  • three servers
    name of server server ip
    centos7 virtual machine 1 192.168.136.27
    centos7 virtual machine 2 192.168.136.28
    centos7 virtual machine 3 192.168.136.29

3. Producer command line operation

3.1. View the example of operating producer command parameters

  • View operation producer command parameters

    [root@localhost kafka-3.0.0]# bin/kafka-console-producer.sh
    

    insert image description here

3.2. View the detailed explanation of the command parameters of the operation producer

  • Detailed Explanation of Producer Command Parameters

    parameter describe
    –bootstrap-server <String: server toconnect to> The connected Kafka Broker host name and port number.
    –topic <String: topic> The topic name of the operation.

3.3. Example of producer sending message

  • Create a news topic

    [root@localhost kafka-3.0.0]# bin/kafka-topics.sh --bootstrap-server 192.168.136.28:9092 --create --partitions 1 --replication-factor 3 --topic news
    

    insert image description here

  • Producers send messages to the news topic

    [root@localhost kafka-3.0.0]# bin/kafka-console-producer.sh --bootstrap-server 192.168.136.28:9092 --topic news
    >hello world
    >this is a news topic
    

    insert image description here

4. Consumer command line operation

4.1. View an example of operating consumer command parameters

  • View operation consumer command parameters

    [root@localhost kafka-3.0.0]# bin/kafka-console-consumer.sh
    

    insert image description here

4.2. View the detailed explanation of the operation consumer command parameters

  • Detailed Explanation of Consumer Order Parameters

    parameter describe
    –bootstrap-server <String: server toconnect to> The connected Kafka Broker host name and port number.
    –topic <String: topic> The topic name of the operation.
    –from-beginning Consume from scratch.
    -group <String: consumer group id> Specify the consumer group name.

4.3. Example of data in consumer consumption news topic

  • Data in the Consumer News (news) topic

    [root@localhost kafka-3.0.0]# bin/kafka-console-consumer.sh --bootstrap-server 192.168.136.28:9092 --topic news
    
  • Producer sends abcdef message to news topic

    [root@localhost kafka-3.0.0]# bin/kafka-console-producer.sh --bootstrap-server 192.168.136.28:9092 --topic news
    >hello world
    >this is a news topic
    >abcdef
    >
    

    insert image description here

  • Consumers check the data in the news (news) topic, whether it can be received

    [root@localhost kafka-3.0.0]# bin/kafka-console-consumer.sh --bootstrap-server 192.168.136.28:9092 --topic news
    abcdef
    

    insert image description here

4.4. An example of consumer consumption of all data (including historical data) in the topic of news

  • Consumers consume all the data in the news topic (including historical data)

    [root@localhost kafka-3.0.0]# bin/kafka-console-consumer.sh --bootstrap-server 192.168.136.28:9092 --topic news --from-beginning
    

    insert image description here

Guess you like

Origin blog.csdn.net/li1325169021/article/details/129906962