java - kafka AdminClient API Timed out waiting for node assignment
问题描述
I'm new to Kafka and am trying to use the AdminClient
API to manage the Kafka server running on my local machine. I have it setup exactly the same as in the quick start section of the Kafka documentation. The only difference being that I have not created any topics.
I have no issues running any of the shell scripts on this setup but when I try to run the following java code:
public class ProducerMain{
public static void main(String[] args) {
Properties props = new Properties();
props.setProperty(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG,
"localhost:9092");
try(final AdminClient adminClient =
KafkaAdminClient.create(props)){
try {
final NewTopic newTopic = new NewTopic("test", 1,
(short)1);
final CreateTopicsResult createTopicsResult =
adminClient.createTopics(
Collections.singleton(newTopic));
createTopicsResult.all().get();
}catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
}
}
}
Error: TimeoutException: Timed out waiting for a node assignment
Exception in thread "main" java.lang.RuntimeException: org.apache.kafka.common.errors.TimeoutException: Timed out waiting for a node assignment.
at ProducerMain.main(ProducerMain.java:41)
<br>Caused by: java.util.concurrent.ExecutionException: org.apache.kafka.common.errors.TimeoutException: Timed out waiting for a node assignment.
at org.apache.kafka.common.internals.KafkaFutureImpl.wrapAndThrow(KafkaFutureImpl.java:45)
at org.apache.kafka.common.internals.KafkaFutureImpl.access$000(KafkaFutureImpl.java:32)
at org.apache.kafka.common.internals.KafkaFutureImpl$SingleWaiter.await(KafkaFutureImpl.java:89)
at org.apache.kafka.common.internals.KafkaFutureImpl.get(KafkaFutureImpl.java:258)
at ProducerMain.main(ProducerMain.java:38)
<br>Caused by: org.apache.kafka.common.errors.TimeoutException: Timed out waiting for a node assignment.
I have searched online for an indication as to what the problem could be but have found nothing so far. Any suggestions are welcome as I am at the end of my rope.
解决方案
听起来你的经纪人不健康......
此代码工作正常
public class Main {
static final Logger logger = LoggerFactory.getLogger(Main.class);
public static void main(String[] args) {
Properties properties = new Properties();
properties.setProperty(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092");
properties.setProperty(AdminClientConfig.CLIENT_ID_CONFIG, "local-test");
properties.setProperty(AdminClientConfig.RETRIES_CONFIG, "3");
try (AdminClient client = AdminClient.create(properties)) {
final CreateTopicsResult res = client.createTopics(
Collections.singletonList(
new NewTopic("foo", 1, (short) 1)
)
);
res.all().get(5, TimeUnit.SECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
logger.error("unable to create topic", e);
}
}
}
我可以在代理日志中看到该主题已创建
推荐阅读
- excel - PrintPreview 不一致的行为
- wordpress - 向 Revolution Slider 添加 Webp 支持
- python - 无法使用 Python 3.8 将 BSTR 指针传递给 COM 对象
- android - 启动模拟器时找不到adb
- c# - 在 IIS 中托管的活动目录 c# 网站
- quartz.net - 使用 Quartz 为每两周在周四和周五运行的任务创建一个 cron express
- python - tensorflow 范围在 Jupyter 实验室中丢失
- spring-boot - 使用基本身份验证和无状态会话的无效会话
- android-studio - 无法安装英特尔 HAXM。尽我所能
- sql - 将列值向左切换