我对Kafka来说是全新的,我很难做到正确。
我有" wurstmeister / kafka-docker"对于使用docker-compose的docker:
zookeeper:
image: wurstmeister/zookeeper
ports:
- "2181:2181"
kafka:
image: wurstmeister/kafka
ports:
- "9092:9092"
links:
- zookeeper:zk
environment:
KAFKA_ADVERTISED_HOST_NAME: 192.168.59.103
# KAFKA_AUTO_CREATE_TOPCIS_ENABLE: 'true'
KAFKA_CREATE_TOPICS: "events:1:1"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
对于生产者和消费者,我使用ruby gem" kafka-rb"。
制片:
require 'kafka'
producer = Kafka::Producer.new({
host: "192.168.59.103",
port: 9092,
topic: "events"
})
1000000.times do |i|
message = Kafka::Message.new("Message #{i}")
producer.push(message)
end
消费者:
要求' kafka'
consumer = Kafka::Consumer.new({
host: "192.168.59.103",
port: 9092,
topic: "events"
})
consumer.loop do |messages|
puts "Received"
puts messages
end
但我仍然被拒绝连接或错误:
[2015-07-15 09:50:49,769] ERROR Closing socket for /192.168.59.3 because of error (kafka.network.Processor)
kafka_1 | java.nio.BufferUnderflowException
kafka_1 | at java.nio.HeapByteBuffer.get(HeapByteBuffer.java:145)
kafka_1 | at java.nio.ByteBuffer.get(ByteBuffer.java:692)
kafka_1 | at kafka.api.ApiUtils$.readShortString(ApiUtils.scala:38)
kafka_1 | at kafka.api.LeaderAndIsrRequest$.readFrom(LeaderAndIsrRequest.scala:108)
kafka_1 | at kafka.api.RequestKeys$$anonfun$5.apply(RequestKeys.scala:43)
kafka_1 | at kafka.api.RequestKeys$$anonfun$5.apply(RequestKeys.scala:43)
kafka_1 | at kafka.network.RequestChannel$Request.<init>(RequestChannel.scala:50)
kafka_1 | at kafka.network.Processor.read(SocketServer.scala:450)
kafka_1 | at kafka.network.Processor.run(SocketServer.scala:340)
kafka_1 | at java.lang.Thread.run(Thread.java:701)
设置是否存在根本性问题?谢谢
答案 0 :(得分:0)
何时发生此错误,运行wurstmeister/zookeeper
图像或尝试生成或使用消息时。
为什么报告Closing socket for /192.168.59.3
,如果它是192.168.59.103
,你可以尝试在你运行生产者和消费者的地方ping或telnet kafka服务器,看看你是否可以连接它或者不