我一直在尝试在kafka集群上运行producer和consumer api,但它不起作用。
1) zookeeper正在一个gcp vm示例上运行
2) kafka正在另一个gcp vm示例上运行
接下来的步骤:
步骤1)使用以下命令运行zookeeper:
bin/zookeeper-server-start.sh config/zookeeper.properties
zookeeper.properties属性:
# the directory where the snapshot is stored.
dataDir=/tmp/zookeeper
# the port at which the clients will connect
clientPort=2181
# disable the per-ip limit on the number of connections since this is a non-production config
maxClientCnxns=0
# In milliseconds
tickTime=2000
# In ticks
initLimit=10
syncLimit=5
maxClientCnxns=30
# All Zookeeper servers need to be aware of other Zookeepers part of the cluster
server.1=zook-1:2888:3888
注意:zook-1是zookeeper示例的名称
步骤2)
在另一个gcp vm示例上运行kafka作为:
bin/kafka-console-producer.sh --broker-li de-kafka-1:9092 --topic test
服务器属性:
############################# Server Basics ############################# # The id of the broker. This must be set to a unique integer for each broker.
broker.id=0
############################ Zookeeper ############################# #
# root directory for all kafka znodes.
zookeeper.connect=zook-1:2181
# Timeout in ms for connecting to zookeeper
zookeeper.connection.timeout.ms=6000
host.name=de-kafka-1
步骤3)
在步骤2中的kafka示例上运行producer api(使用另一个ssh隧道),如下所示:
bin/kafka-console-producer.sh --broker-list de-kafka-1:9 092 --topic test
注意:这里de-kafka-1是我尝试过的gcp kafka vm示例的名称,并将de-kafka-1替换为de-kafka-1示例的外部ip、localhost、zook-1(zookeeper vm示例的名称)、zook-1 vm示例的外部ip
Error: OpenJDK 64-Bit Server VM warning: If the number of processors is expected to increase from one, then you should configure the number of parallel GC threads appropriately using -XX:ParallelGCThreads=N Sending msg1 sending msg2
Error: error when sending message to topic test single node with key: null, value: 5 bytes with error (org.apache.kafka.clients.producer.internals.errorloggingcallback)org.apache.kafka.common.errors.timeoutexception: failed to update metadata after 60000 ms.
第四步:
在kafka示例上运行使用者api(使用第三个ssh隧道):
bin/kafka-console-consumer.sh --bootstrap-server de-kafka-1:2181 --topic test --from-beginning
如果有人能帮上忙,我将不胜感激。谢谢
1条答案
按热度按时间6pp0gazn1#
在制作之前尝试创建主题
bin/kafka-topics.sh --create --zookeeper zook-1:2181 --replication-factor 1 --partitions 1 --topic test
.如果不起作用,请阅读
zkCli.sh
脚本在这里-通过这个脚本,您可以检查代理是否在zookeeper中注册。如果你仍然有一个问题,你试图从Kafka以外的集群生产,尝试阅读有关
advertised.listeners
这里的财产。