【问题标题】:Apache Kafka : Producer -Consume API not running on GCPApache Kafka:Producer -Consume API 未在 GCP 上运行
【发布时间】:2017-12-04 02:25:07
【问题描述】:

我一直在尝试在 Kafka 集群上运行我的生产者和消费者 API,但它不起作用。

1) Zookeeper 在一个 GCP 虚拟机实例上运行

2) Kafka 正在另一个 GCP 虚拟机实例上运行

遵循的步骤:

步骤 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 虚拟机实例上运行 Kafka:

bin/kafka-console-producer.sh --broker-li de-kafka-1:9092 --topic test 

server.properties:

 ############################# 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 实例上运行生产者 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. 

第 4 步:

在 Kafka 实例上运行 Consumer API(使用第三个 SSH 隧道):

bin/kafka-console-consumer.sh --bootstrap-server de-kafka-1:2181 --topic test --from-beginning 

如果有人能提供帮助,我们将不胜感激。谢谢

【问题讨论】:

  • 尝试从kafka vm运行telnet zook-1 2181,如果成功,输入stats并回车。这将检查您的 kafka-zookepper 连接和 zookeeper 的状态。
  • @Gal 感谢您的回复,这是我得到的:------------ 'Zookeeper 版本: 3.4.9-1757313,建于 08/23/2016 06:50 GMT 客户端:/xx.xxx.x.xx:45284[1](queued=0,recved=275,sent=277) /xx.xxx。 x.xx:45384[0](queued=0,recved=1,sent=0) 延迟最小/平均/最大:0/0/6 接收:276 发送:277 连接:2 未完成:0 Zxid:0x113 模式:独立节点数:36 连接被外部主机关闭。'
  • @Gal 知道这意味着什么
  • 看起来不错,Mode: standalone 表示您正在运行 zk 独立模式。尝试在kafka vm上运行netstat -nlp | grep 9092并发布输出..
  • @Gal tcp6 0 0 xx.xxx.x.xx:9092 :::* LISTEN 890/java 。这是运行 netstat -nlp | 后的输出grep 9092

标签: apache-kafka apache-zookeeper kafka-producer-api gcp


【解决方案1】:

在产生bin/kafka-topics.sh --create --zookeeper zook-1:2181 --replication-factor 1 --partitions 1 --topic test之前尝试创建主题。

如果它不起作用,请阅读 zkCli.sh 脚本 here - 使用此脚本,您可以检查代理是否已在 zookeeper 中注册。

如果您仍然有问题,并且您尝试从 kafka 集群外部进行生产,请尝试阅读有关 advertised.listeners 属性 here 的信息。

【讨论】:

  • 感谢您的建议。但是已经创建了主题测试。此外,经纪人在 Zookeeper [root@de-kafka-1 bin]# ./zookeeper-shell.sh zook-1:2181 <<< "ls /brokers/ids" Connecting to zook-1:2181 Welcome to ZooKeeper! JLine support is disabled WATCHER:: WatchedEvent state:SyncConnected type:None path:null [10] 上注册。此外,我在同一个 kafka 集群中生产它。
猜你喜欢
  • 2018-11-19
  • 1970-01-01
  • 1970-01-01
  • 2018-09-25
  • 2016-02-23
  • 2018-08-13
  • 2020-06-21
  • 2022-08-16
  • 2017-10-04
相关资源
最近更新 更多