class Karafka::Params::ParamsBatch
Params
batch represents a set of messages received from Kafka. @note Params
internally are lazy loaded before first use. That way we can skip
deserialization process if we have after_fetch that rejects some incoming messages without using params It can be also used when handling really heavy data.
Public Class Methods
@param params_array [Array<Karafka::Params::Params>] array with karafka params @return [Karafka::Params::ParamsBatch] lazy evaluated params batch object
# File lib/karafka/params/params_batch.rb, line 14 def initialize(params_array) @params_array = params_array end
Public Instance Methods
@return [Array<Karafka::Params::Params>] returns all the params in a loaded state, so they
can be used for batch insert, etc. Without invoking all, up until first use, they won't be deserialized
# File lib/karafka/params/params_batch.rb, line 28 def deserialize! each(&:payload) end
@yieldparam [Karafka::Params::Params] each params instance @note Invocation of this method will not cause loading and deserializing each param after
another.
# File lib/karafka/params/params_batch.rb, line 21 def each @params_array.each { |param| yield(param) } end
@return [Karafka::Params::Params] first element
# File lib/karafka/params/params_batch.rb, line 40 def first @params_array.first end
@return [Karafka::Params::Params] last element
# File lib/karafka/params/params_batch.rb, line 45 def last @params_array.last end
@return [Array<Object>] array with deserialized payloads. This method can be useful when
we don't care about metadata and just want to extract all the data payloads from the batch
# File lib/karafka/params/params_batch.rb, line 35 def payloads map(&:payload) end
@return [Integer] number of messages in the batch
# File lib/karafka/params/params_batch.rb, line 50 def size @params_array.size end
@return [Array<Karafka::Params::Params>] pure array with params
# File lib/karafka/params/params_batch.rb, line 55 def to_a @params_array end