Ruby 红宝石线程不';不要打印卡夫卡消息
我需要使用6个分区的主题中的一些kafka消息。我希望使用线程来执行此操作,例如: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
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
。获取主线程中的异常。