简体   繁体   English

没有docker-compose的Docker上的Kafka?

[英]Kafka On Docker without docker-compose?

I wanted to set up kafka single broker on my local machine(Windows 7) using Docker. 我想使用Docker在本地计算机(Windows 7)上设置kafka单一代理。 Essentially, I used the steps listed out on this link: 本质上,我使用了此链接中列出的步骤:

Apache Kafka on Docker Docker上的Apache Kafka

Then, I was able to create a topic by running the following command: 然后,我可以通过运行以下命令来创建主题:

kafka-topics.bat --create --zookeeper 192.168.59.103:32769 --replica 1 --partition 1 --topic test 

This created the topic alright as when I do list-topics, it displays correctly. 这样就创建了主题,就像我执行列表主题一样,它可以正确显示。

Next, I tried to publish a message using the kafka-console-producer.bat file and when I do that and hit enter after entering the message, I get the following exception: 接下来,我尝试使用kafka-console-producer.bat文件发布消息,当我这样做并在输入消息后按回车键时,出现以下异常:

[2015-08-02 13:48:46,075] WARN Error while fetching metadata [{TopicMetadata for
 topic test ->
No partition metadata for topic test due to kafka.common.LeaderNotAvailableExcep
tion}] for topic [test]: class kafka.common.LeaderNotAvailableException  (kafka.
producer.BrokerPartitionInfo)
[2015-08-02 13:48:46,084] WARN Error while fetching metadata [{TopicMetadata for
 topic test ->
No partition metadata for topic test due to kafka.common.LeaderNotAvailableExcep
tion}] for topic [test]: class kafka.common.LeaderNotAvailableException  (kafka.
producer.BrokerPartitionInfo)
[2015-08-02 13:48:46,085] ERROR Failed to collate messages by topic, partition d
ue to: Failed to fetch topic metadata for topic: test (kafka.producer.async.Defa
ultEventHandler)
[2015-08-02 13:48:46,195] WARN Error while fetching metadata [{TopicMetadata for
 topic test ->
No partition metadata for topic test due to kafka.common.LeaderNotAvailableExcep
tion}] for topic [test]: class kafka.common.LeaderNotAvailableException  (kafka.
producer.BrokerPartitionInfo)
[2015-08-02 13:48:46,205] WARN Error while fetching metadata [{TopicMetadata for
 topic test ->
No partition metadata for topic test due to kafka.common.LeaderNotAvailableExcep
tion}] for topic [test]: class kafka.common.LeaderNotAvailableException  (kafka.
producer.BrokerPartitionInfo)
[2015-08-02 13:48:46,206] ERROR Failed to collate messages by topic, partition d
ue to: Failed to fetch topic metadata for topic: test (kafka.producer.async.Defa
ultEventHandler)
[2015-08-02 13:48:46,315] WARN Error while fetching metadata [{TopicMetadata for
 topic test ->
No partition metadata for topic test due to kafka.common.LeaderNotAvailableExcep
tion}] for topic [test]: class kafka.common.LeaderNotAvailableException  (kafka.
producer.BrokerPartitionInfo)
[2015-08-02 13:48:46,325] WARN Error while fetching metadata [{TopicMetadata for
 topic test ->
No partition metadata for topic test due to kafka.common.LeaderNotAvailableExcep
tion}] for topic [test]: class kafka.common.LeaderNotAvailableException  (kafka.
producer.BrokerPartitionInfo)
[2015-08-02 13:48:46,325] ERROR Failed to collate messages by topic, partition d
ue to: Failed to fetch topic metadata for topic: test (kafka.producer.async.Defa
ultEventHandler)
[2015-08-02 13:48:46,434] WARN Error while fetching metadata [{TopicMetadata for
 topic test ->
No partition metadata for topic test due to kafka.common.LeaderNotAvailableExcep
tion}] for topic [test]: class kafka.common.LeaderNotAvailableException  (kafka.
producer.BrokerPartitionInfo)
[2015-08-02 13:48:46,442] WARN Error while fetching metadata [{TopicMetadata for
 topic test ->
No partition metadata for topic test due to kafka.common.LeaderNotAvailableExcep
tion}] for topic [test]: class kafka.common.LeaderNotAvailableException  (kafka.
producer.BrokerPartitionInfo)
[2015-08-02 13:48:46,443] ERROR Failed to collate messages by topic, partition d
ue to: Failed to fetch topic metadata for topic: test (kafka.producer.async.Defa
ultEventHandler)
[2015-08-02 13:48:46,548] WARN Error while fetching metadata [{TopicMetadata for
 topic test ->
No partition metadata for topic test due to kafka.common.LeaderNotAvailableExcep
tion}] for topic [test]: class kafka.common.LeaderNotAvailableException  (kafka.
producer.BrokerPartitionInfo)
[2015-08-02 13:48:46,549] ERROR Failed to send requests for topics test with cor
relation ids in [9,17] (kafka.producer.async.DefaultEventHandler)
[2015-08-02 13:48:46,549] ERROR Error in handling batch of 1 events (kafka.produ
cer.async.ProducerSendThread)
kafka.common.FailedToSendMessageException: Failed to send messages after 3 tries
.
        at kafka.producer.async.DefaultEventHandler.handle(DefaultEventHandler.s
cala:90)
        at kafka.producer.async.ProducerSendThread.tryToHandle(ProducerSendThrea
d.scala:105)
        at kafka.producer.async.ProducerSendThread$$anonfun$processEvents$3.appl
y(ProducerSendThread.scala:88)
        at kafka.producer.async.ProducerSendThread$$anonfun$processEvents$3.appl
y(ProducerSendThread.scala:68)
        at scala.collection.immutable.Stream.foreach(Stream.scala:547)
        at kafka.producer.async.ProducerSendThread.processEvents(ProducerSendThr
ead.scala:67)
        at kafka.producer.async.ProducerSendThread.run(ProducerSendThread.scala:
45)

The exception seems strange to me as when I started the kafka using 当我使用以下命令启动kafka时,异常对我来说似乎很奇怪

docker run --name kafka -e HOST_IP=localhost -e KAFKA_ADVERTISED_HOST_NAME=192.168.59.103 -e KAFKA_ADVERTISED_PORT=9092 -e KAFKA_BROKER_ID=1 -e ZK=zk -p 9092 --link zookeeper:zk -t wurstmeister/kafka

The last line that shows up in the terminal is : 终端中显示的最后一行是:

[2015-08-02 17:20:44,037] INFO Registered broker 1 at path /brokers/ids/1 with a
ddress 192.168.59.103:9092. (kafka.utils.ZkUtils$)
[2015-08-02 17:20:44,055] INFO [Kafka Server 1], started (kafka.server.KafkaServ
er)
[2015-08-02 17:20:44,108] INFO New leader is 1 (kafka.server.ZookeeperLeaderElec
tor$LeaderChangeListener)

So, I am guessing that the leader has already been assigned. 所以,我想领导者已经被任命。 And lastly, from the Consumer side, when I run the bat file, the following is thrown: 最后,从消费者方面,当我运行bat文件时,将引发以下情况:

[2015-08-02 13:41:47,005] WARN Fetching topic metadata with correlation id 0 for
 topics [Set(test)] from broker [id:1,host:192.168.59.103,port:9092] failed (kaf
ka.client.ClientUtils$)
java.nio.channels.ClosedChannelException
        at kafka.network.BlockingChannel.send(BlockingChannel.scala:100)
        at kafka.producer.SyncProducer.liftedTree1$1(SyncProducer.scala:73)
        at kafka.producer.SyncProducer.kafka$producer$SyncProducer$$doSend(SyncP
roducer.scala:72)
        at kafka.producer.SyncProducer.send(SyncProducer.scala:113)
        at kafka.client.ClientUtils$.fetchTopicMetadata(ClientUtils.scala:58)
        at kafka.client.ClientUtils$.fetchTopicMetadata(ClientUtils.scala:93)
        at kafka.consumer.ConsumerFetcherManager$LeaderFinderThread.doWork(Consu
merFetcherManager.scala:66)
        at kafka.utils.ShutdownableThread.run(ShutdownableThread.scala:60)

So, what is it that I am doing wrongly over here? 那么,我在这里做错了什么? Do I always need compose for running kafka? 我是否总是需要撰写代码才能运行kafka? My understanding is that compose is needed if I want to run multiple brokers which isn't what I am doing anyways. 我的理解是,如果我想运行多个经纪人,那么无论如何我都不会这样做。 Wouldn't linking the 2 containers suffice in my case? 在我的情况下,将两个容器链接起来就足够了吗?

I noticed that the ZooKeeper host & port that you passed to kafka-topcs.bat is not the default one. 我注意到您传递给kafka-topcs.bat的ZooKeeper主机和端口不是默认端口。 Perhaps that is the source of the problem. 也许这就是问题的根源。 Did you start a separate Docker container for Zookeeper? 您是否为Zookeeper启动了单独的Docker容器?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM