连接到 HDInsight (Azure) 上安装的 Kafka

Dew*_*wfy 5 java azure apache-kafka azure-hdinsight

我需要从外部 java 应用程序连接到作为 Azure 上 HDinsight 的一部分启动的 Kafka 集群。我的集群包含 3 个代理实例、3 个 ZooKeeper 和 1 个 ZooKeeper 客户端。

现在我的问题:如何指定代理连接字符串。在管理面板上,我可以看到 3 个经纪人,例如:xxx-1.yyy.zzz.internal.cloudapp.net, xxx-2.yyy.zzz.internal.cloudapp.net- 但这些地址无法从外部获得。如果我尝试一下,我可以看到异常:

KafkaException:构建kafka消费者失败

...

ConfigException:bootstrap.servers 中的 URL 无效:xxx-1.yyy.zzz.internal.cloudapp.net

小智 -3

[root@domain bin]# ./kafka-console-producer.sh --broker-list host.domain.net:6667 --topic topic1 --security-protocol SASL_PLAINTEXT 
Test
[2017-04-11 09:07:43,821] WARN Error while fetching metadata with correlation id 0 : {topic1=UNKNOWN_TOPIC_OR_PARTITION} (org.apache.kafka.clients.NetworkClient)
[2017-04-11 09:07:44,022] WARN Error while fetching metadata with correlation id 1 : {topic1=UNKNOWN_TOPIC_OR_PARTITION} (org.apache.kafka.clients.NetworkClient)
[2017-04-11 09:07:44,122] WARN Error while fetching metadata with correlation id 2 : {topic1=UNKNOWN_TOPIC_OR_PARTITION} (org.apache.kafka.clients.NetworkClient)
[2017-04-11 09:07:44,223] WARN Error while fetching metadata with correlation id 3 : {topic1=UNKNOWN_TOPIC_OR_PARTITION} (org.apache.kafka.clients.NetworkClient)
[2017-04-11 09:07:44,323] WARN Error while fetching metadata with correlation id 4 : {topic1=UNKNOWN_TOPIC_OR_PARTITION} (org.apache.kafka.clients.NetworkClient)
[2017-04-11 09:07:44,423] WARN Error while fetching metadata with correlation id 5 : {topic1=UNKNOWN_TOPIC_OR_PARTITION} (org.apache.kafka.clients.NetworkClient)
[2017-04-11 09:07:44,523] WARN Error while fetching metadata with correlation id 6 : {topic1=UNKNOWN_TOPIC_OR_PARTITION} (org.apache.kafka.clients.NetworkClient)
[2017-04-11 09:07:44,624] WARN Error while fetching metadata with correlation id 7 : {topic1=UNKNOWN_TOPIC_OR_PARTITION} (org.apache.kafka.clients.NetworkClient)
[2017-04-11 09:07:43,821] WARN Error while fetching metadata with correlation id 0 : {topic1=UNKNOWN_TOPIC_OR_PARTITION} (org.apache.kafka.clients.NetworkClient)
[2017-04-11 09:07:44,022] WARN Error while fetching metadata with correlation id 1 : {topic1=UNKNOWN_TOPIC_OR_PARTITION} (org.apache.kafka.clients.NetworkClient)
[2017-04-11 09:07:44,122] WARN Error while fetching metadata with correlation id 2 : {topic1=UNKNOWN_TOPIC_OR_PARTI
Run Code Online (Sandbox Code Playgroud)

如果您有 3 个代理 kafka 集群,它会抛出此错误。因此,每当您运行 kafka 生产者和消费者时,请创建一个具有相同复制因子和代理数量的主题。

命令

bin/kafka-topics.sh --create --topic test --zookeeper node1:2181,node2:2181,node3:2181 --partitions 1 --replication-factor 3
Run Code Online (Sandbox Code Playgroud)

此命令适用于 3 个代理 hdinsigt 集群