Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/apache-kafka/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby 红宝石线程不';不要打印卡夫卡消息_Ruby_Apache Kafka - Fatal编程技术网

Ruby 红宝石线程不';不要打印卡夫卡消息

Ruby 红宝石线程不';不要打印卡夫卡消息,ruby,apache-kafka,Ruby,Apache Kafka,我需要使用6个分区的主题中的一些kafka消息。我希望使用线程来执行此操作,例如: require 'poseidon' require 'msgpack' theads = []; 6.times do |partition| theads << Thread.new { puts "start thread #{partition}\n" consumer = Poseidon::PartitionConsumer.new("my_te

我需要使用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 }
需要“波塞冬”
需要“msgpack”
theads=[];
6.2倍做|分割|

嗯,我发现了问题,但是很奇怪。因为脚本会在长时间延迟后引发异常。 我没有隐式地将MessagePack.unpack(m.value)转换为字符串。 因此,一旦我在后面添加了一个。s,它就起作用了

puts "partition #{partition}:\n " + MessagePack.unpack(m.value).to_s

您可能需要
thread.abort\u on\u exception=true
。获取主线程中的异常。