kafka安装程序,docker为客户端使用kafka rb

ajsxfq5m  于 2021-06-08  发布在  Kafka
关注(0)|答案(1)|浏览(357)

我对Kafka完全陌生,我很难把它弄对。
我使用docker compose为docker设置了以下“wurstmeister/kafka 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)

设置有什么根本性的问题吗?谢谢您

rbl8hiat

rbl8hiat1#

这个错误是什么时候发生的 wurstmeister/zookeeper 当你试图产生或消费信息时。
为什么要报道 Closing socket for /192.168.59.3 ,应该是吗 192.168.59.103 ,您是否可以尝试ping或telnet kafka服务器在您运行生产者和消费者的地方,看看您是否可以连接到它。

相关问题