gpt4 book ai didi

docker - KafkaException : No key found on line 1 at kafka. 工具.ConsoleProducer$LineMessageReader.readMessage

转载 作者:行者123 更新时间:2023-12-04 08:35:45 32 4
gpt4 key购买 nike

简而言之,我启动了 Kafka,成功创建了一个主题,启动了一个启用了 key 的生产者。到目前为止,一切都很好。我发送了一条简单的消息,我得到了

root@kafka:/# kafka-console-producer --broker-list localhost:9092 --topic testkey --property "parse.key=true" propert
y "key.separator=:"
>1:fisrtmessage
org.apache.kafka.common.KafkaException: No key found on line 1: 1:fisrtmessage
at kafka.tools.ConsoleProducer$LineMessageReader.readMessage(ConsoleProducer.scala:275)
at kafka.tools.ConsoleProducer$.main(ConsoleProducer.scala:55)
at kafka.tools.ConsoleProducer.main(ConsoleProducer.scala)
root@kafka:/#

这里既有生产者也有消费者。如您所见,消费者没有收到消息,生产者崩溃了。

cmd screens

docker-compose.yml

version: '3'

services:
zookeeper:
image: confluentinc/cp-zookeeper:5.4.0
hostname: zookeeper
container_name: zookeeper
ports:
- "2181:2181"
environment:
ZOOKEEPER_CLIENT_PORT: 2181
ZOOKEEPER_TICK_TIME: 2000

broker:
image: confluentinc/cp-server:5.4.0
hostname: broker
container_name: broker
depends_on:
- zookeeper
ports:
- "9092:9092"
environment:
KAFKA_BROKER_ID: 1
KAFKA_ZOOKEEPER_CONNECT: 'zookeeper:2181'
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://broker:29092,PLAINTEXT_HOST://localhost:9092
KAFKA_METRIC_REPORTERS: io.confluent.metrics.reporter.ConfluentMetricsReporter
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: 0
KAFKA_CONFLUENT_LICENSE_TOPIC_REPLICATION_FACTOR: 1
CONFLUENT_METRICS_REPORTER_BOOTSTRAP_SERVERS: broker:29092
CONFLUENT_METRICS_REPORTER_ZOOKEEPER_CONNECT: zookeeper:2181
CONFLUENT_METRICS_REPORTER_TOPIC_REPLICAS: 1
CONFLUENT_METRICS_ENABLE: 'true'
CONFLUENT_SUPPORT_CUSTOMER_ID: 'anonymous'

kafka-tools:
image: confluentinc/cp-kafka:5.4.0
hostname: kafka
container_name: kafka
command: ["tail", "-f", "/dev/null"]
network_mode: "host"

最佳答案

您对 kafka-console-producer 的调用在 property 的第二次调用中缺少 --

这意味着 keySeparator 不是您提供的那个 (:),而是退回到默认值。根据code ConsoleProducer 的默认值是:

var keySeparator = "\t"

由于您提供的字符串不包含任何制表符,它将抛出异常“No key found on line ...”,这是在 line 处完成的。的代码。

关于docker - KafkaException : No key found on line 1 at kafka. 工具.ConsoleProducer$LineMessageReader.readMessage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64811444/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com