Java KAFKA:60000 毫秒后无法更新元数据
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/52798479/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
KAFKA: Failed to update metadata after 60000 ms
提问by Fawad Shah
I am new to KAFKA and I know that this question has been asked multiple times on stack overflow but none of the solutions worked for me so here I am trying my luck with asking the same question again. I have downloaded and installed KFKA on Centos7 VM. The VM is on my laptop. When I run the KAFKA producer and consumer from the command line, it works fine. Next step, I wanted to create a Java Producer but it always timeout with the following exception.
我是 KAFKA 的新手,我知道这个问题在堆栈溢出时被问过多次,但没有一个解决方案对我有用,所以在这里我再次问同样的问题来试试运气。我已经在 Centos7 VM 上下载并安装了 KFKA。VM 在我的笔记本电脑上。当我从命令行运行 KAFKA 生产者和消费者时,它工作正常。下一步,我想创建一个 Java Producer,但它总是超时并出现以下异常。
Exception in thread "main" java.util.concurrent.ExecutionException: org.apache.kafka.common.errors.TimeoutException: Failed to update metadata after 60000 ms.
at org.apache.kafka.clients.producer.KafkaProducer$FutureFailure.<init>(KafkaProducer.java:1186)
at org.apache.kafka.clients.producer.KafkaProducer.doSend(KafkaProducer.java:880)
at org.apache.kafka.clients.producer.KafkaProducer.send(KafkaProducer.java:803)
at org.apache.kafka.clients.producer.KafkaProducer.send(KafkaProducer.java:690)
at com.soft.teradata.KafkaProducerExample.runProducer(KafkaProducerExample.java:40)
at com.soft.teradata.KafkaProducerExample.main(KafkaProducerExample.java:55)
Caused by: org.apache.kafka.common.errors.TimeoutException: Failed to update metadata after 60000 ms.
The Java code for the producer is:
生产者的Java代码是:
package com.soft;
import java.util.Properties;
import java.util.concurrent.Future;
import org.apache.kafka.clients.producer.Producer;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.clients.producer.RecordMetadata;
public class SimpleProducer {
public static void main(String[] args) throws Exception {
try {
String topicName = "Hello-Kafka";
Properties props = new Properties();
props.put("bootstrap.servers", "192.168.xxx.xxx:9092");
props.put("acks", "all");
props.put("retries", 1);
props.put("batch.size", 16384);
props.put("linger.ms", 1);
props.put("buffer.memory", 33554432);
props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
Producer<String, String> producer = new KafkaProducer<String, String>(props);
Future<RecordMetadata> f=producer.send(new ProducerRecord<String, String>(topicName, "Eclipse"));
System.out.println("Message sent successfully");
producer.close();
} catch (Exception e) {
System.out.println(e.getMessage());
}
System.out.println("Successful");
}
}
For bootstrap.server, i have even tried the following:
对于 bootstrap.server,我什至尝试过以下操作:
props.put("bootstrap.servers", "PLAINTEXT://192.168.xxx.xxx:9092");
props.put("bootstrap.servers", "PLAINTEXT://192.168.xxx.xxx:9092");
Please note that I am executing the java code from Eclipse on my laptop and KAFKA is installed on a CENTOS7 VM on my laptop. 192.168.xxx.xxx is the IP address of the CENTOS7 VM. I have noticed that 192.168.xxx.xxx:9092 (telnet 192.168.xxx.xxx 9092) is inaccessible from my laptop. I added the port to firewall but still no success.
请注意,我正在笔记本电脑上从 Eclipse 执行 java 代码,而 KAFKA 安装在笔记本电脑上的 CENTOS7 VM 上。192.168.xxx.xxx 是 CENTOS7 虚拟机的 IP 地址。我注意到我的笔记本电脑无法访问 192.168.xxx.xxx:9092 (telnet 192.168.xxx.xxx 9092)。我将端口添加到防火墙,但仍然没有成功。
firewall-cmd --zone=public --add-port=9092/tcp --permanent
firewall-cmd --reload
firewall-cmd --list-ports
The version of KAFKA is 2.12-2.0.0 and I have added the following jars to my Eclipse Classpath:
KAFKA 的版本是 2.12-2.0.0,我已经将以下 jars 添加到我的 Eclipse Classpath 中:
- kafka-clients-2.0.0.jar
- lz4-java-1.4.1.jar
- slf4j-api-1.7.25.jar
- snappy-java-1.1.7.1.jar
- kafka-clients-2.0.0.jar
- lz4-java-1.4.1.jar
- slf4j-api-1.7.25.jar
- snappy-java-1.1.7.1.jar
Thanks a lot for the help in advance :)
非常感谢您提前提供帮助:)
Regadrs, DIRSHAH.
Regadrs,DIRSHAH。
回答by user1811060
Same issue, you will find some port can work, some not.
同样的问题,你会发现有些端口可以工作,有些则不行。
Just change it to 19092 will works, coz rabbitMQ using 15672 works well, i guess the reason was some port taken by OSX
只需将其更改为 19092 即可,因为使用 15672 的 rabbitMQ 效果很好,我想原因是 OSX 占用了一些端口
回答by ynux
This error can indicate that the topic doesn't exist, so you may want to double check your topicName = "Hello-Kafka".
此错误可能表明该主题不存在,因此您可能需要仔细检查您的 topicName = "Hello-Kafka"。
Though this isn't exactly a deep answer, it seems to be a common problem, see also https://github.com/dpkp/kafka-python/issues/607
虽然这不是一个深刻的答案,但它似乎是一个常见问题,另见https://github.com/dpkp/kafka-python/issues/607
回答by Ahmad
I faced the same issue. You need to advertise the hostname/ip of Kafka broker to be reachable from Kafka Producer pc.
我遇到了同样的问题。您需要宣传 Kafka 代理的主机名/IP 以便可以从 Kafka Producer pc 访问。
kafka-server-start.sh config/server.properties --override advertised.listeners=PLAINTEXT://<accessible-hostname>:9092