我需要从包含6个分区的主题中使用一些kafka消息。我想用线程做这样的事情:
require 'poseidon'
require 'msgpack'
theads = [];
6.times do |partition|
theads << Thread.new {
puts "start thread #{partition}\n"
consumer = Poseidon::PartitionConsumer.new("my_test_consumer", "localhost", 9093,
"transactions", partition, :latest_offset)
loop do
messages = consumer.fetch
messages.each do |m|
puts "partition #{partition}:\n " + MessagePack.unpack(m.value)
end
end
}
end
theads.each { |thread| thread.join }
但是当我运行它并且kafka主题中有消息时(我用其他类似于问题的脚本检查它们,但没有线程),它们不会在控制台中打印出来。
答案 0 :(得分:0)
puts "partition #{partition}:\n " + MessagePack.unpack(m.value).to_s