我有一个本地 Kafka 使用以下命令运行docker-compose.yml
file:
version: '2'
services:
zookeeper:
image: "confluentinc/cp-zookeeper:5.0.1"
environment:
ZOOKEEPER_CLIENT_PORT: 2181
ZOOKEEPER_TICK_TIME: 2000
kafka:
image: "confluentinc/cp-enterprise-kafka:5.0.1"
ports:
- '9092:9092'
depends_on:
- zookeeper
environment:
KAFKA_BROKER_ID: 1
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:29092,PLAINTEXT_HOST://localhost:9092
KAFKA_METRIC_REPORTERS: io.confluent.metrics.reporter.ConfluentMetricsReporter
KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: 100
尝试在 Scala 中使用 kafka-client 2.1.0 运行基本创建主题:
val props = new Properties()
props.setProperty(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092")
val adminClient: AdminClient = AdminClient.create(props)
val newTopic = new NewTopic("test", 1, 1.toShort)
val topicsF = adminClient.createTopics(List(newTopic).asJavaCollection)
val result = topicsF.all().get()
但一段时间后我得到:
org.apache.kafka.common.errors.TimeoutException: Timed out waiting for a node assignment.
我可以使用命令行创建一个主题:
kafka-topics --create \
--zookeeper localhost:2181 \
--replication-factor 1 \
--partitions 1 \
--topic test
Created topic "test".
kafka AdminClient API等待节点分配超时 https://stackoverflow.com/questions/51325076/kafka-adminclient-api-timed-out-waiting-for-node-assignment描述了使用 Java 的类似问题,但评论表明系统重新启动解决了该问题,但我这边的情况并非如此。