为什么我的kafka在一个分区中有消息?

Dea*_*hen 6 apache-kafka

我有两个kafka代理在本地机器上有两个分区,并使用以下工具将一个本地文件写入kafka test2主题.

# create topic
  ./kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 2 --partitions 2 --topic test2
  Created topic "test2".
  # write 15MB file to kafka, very fast!!
  kafka-console-producer.sh --broker-list localhost:9093,localhost:9094 --topic test2 < data.txt
  # read data from kafka
  ./kafka-console-consumer.sh --zookeeper localhost:2181 --topic test2 --from-beginning
Run Code Online (Sandbox Code Playgroud)

然后我发现所有消息都在一个分区中,如何调试呢?

$ kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list localhost:9093,localhost:9094 --topic test2 --time -1
    SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
    SLF4J: Defaulting to no-operation (NOP) logger implementation
    SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
    test2:0:68263
    test2:1:0
Run Code Online (Sandbox Code Playgroud)

分区的状态是:

$ kafka-topics.sh --describe --zookeeper localhost:2181 --topic test2
Topic:test2 PartitionCount:2    ReplicationFactor:2 Configs:
    Topic: test2    Partition: 0    Leader: 1   Replicas: 1,2   Isr: 1,2
    Topic: test2    Partition: 1    Leader: 2   Replicas: 2,1   Isr: 2,1
Run Code Online (Sandbox Code Playgroud)

小智 0

我将尝试以下操作:

  1. 使用kcat(以前的kafkacat工具,使生产/消费者变得更加容易)
  2. 尝试发布 10 条消息
  3. 尝试使用密钥发布消息,观察到带有 null 的密钥被发布到单个分区