kafka create topic, production and consumption of specified topic message

After starting the zookeeper and Kafka, enter kafka directory (install / boot kafka refer to the previous chapter: https://www.cnblogs.com/cici20166/p/9425613.html )

1. Create Topic

  1) Run command: ./bin/kafka-topics.sh --create --zookeeper zk1: 2181 --replication-factor 2 --partitions 3 --topic hello

    replication-factor:副本数,包含主节点,不能大于机器数
    partitions:分区数,可以大于机器数
    同一台机器不能包含两个相同的partition:hello-1/hello-1
    但是可以有两个不同的分区:hello-2/hello-3

  To create a successful illustration:

  

2. View Topic

  1) Run command to view all of topic: ./bin/kafka-topics.sh --list --zookeeper zk1: 2181

  The results as shown below, and represents a total test test1 two topic:

  

3. Kafka's console-producer in the production topic hello message

  New terminal window to kafka directory, run the command: ./ bin / kafka-console-producer.sh --broker-list zk1: 9092 --topic hello

  Then enter the message content to be produced (e.g., hello world), Enter:

4. console-consumer consumption of message topic hello Kafka

  New terminal window to kafka directory,

  Run the command: ./ bin / kafka-console-consumer.sh --bootstrap-server zk1: 9092 --topic hello --from-beginning

  (9092 is the start of kafka single port; - bootstrap-server kafka old and the new version is not the same, this is a new version of the command)

  

  ps. 1) If the producer and consumer opens two windows simultaneously, the input information producer, consumer information and consumer immediately print terminal
{{-Image Uploading-892112.png (Uploading ...)}}
{{-Image Uploading -443812.png (uploading ...)}}

    2) open a new terminal, to spend the same topic, the news had just been consumed by the new terminal will continue to spend. In other words, the message is not deleted immediately after consumption. (Groupid different consumer recalculated offset)          

5.kafka-Manager can see the effect produced by the above-described recording operation

adds a topic

Three kafka-broker

Details specific topic




Guess you like

Origin www.cnblogs.com/xiaohan970121/p/12361049.html