返回到文章

采纳

编辑于

kafka 集群映射端口到外网,外网无法生产消息

kafka

有3台kafka
ip分别是内网ip

192.168.2.21   9092
192.168.2.22   9092
192.168.2.23   9092

另有一台同时接通了内网和互联网的机器(内网ip 192.168.2.13,外网ip 172.50.63.1),
现在用这台机器做了端口映射,用的rinetd

0.0.0.0  9092  192.168.2.21  9092
0.0.0.0  9093  192.168.2.22  9092
0.0.0.0  9094  192.168.2.23  9092

然后在自己开发电脑上用java代码生产消息 topic=ffff

props.put("bootstrap.servers", "172.50.63.1:9092");

会产生如下报错

java.util.concurrent.ExecutionException: org.apache.kafka.common.errors.TimeoutException: Batch containing 1 record(s) expired due to timeout while requesting metadata from brokers for ffff-0
    at org.apache.kafka.clients.producer.internals.FutureRecordMetadata.valueOrError(FutureRecordMetadata.java:65)
    at org.apache.kafka.clients.producer.internals.FutureRecordMetadata.get(FutureRecordMetadata.java:52)
    at org.apache.kafka.clients.producer.internals.FutureRecordMetadata.get(FutureRecordMetadata.java:25)
    at Producer.run(Producer.java:140)
Caused by: org.apache.kafka.common.errors.TimeoutException: Batch containing 1 record(s) expired due to timeout while requesting metadata from brokers for ffff-0

这是我的kafka配置

listeners=PLAINTEXT://0.0.0.0:9092
advertised.listeners=PLAINTEXT://192.168.2.13:9092

现在的疑问是:
这个配置应该写什么?才能让外网能够正常生产
advertised.listeners应该写互联网ip 172.50.63.1 还是做映射的那台内网ip 192.168.2.13