module Karafka::Extensions::BatchMetadataBuilder

Extension for metadata builder to allow building metadata from a hash

Public Instance Methods

from_hash(hash, topic) click to toggle source

Builds metadata from hash @param hash [Hash] hash with metadata @param topic [Karafka::Routing::Topic] topic instance @return [Karafka::Params::Metadata] metadata instance

# File lib/karafka/extensions/batch_metadata_builder.rb, line 11
def from_hash(hash, topic)
  # Parser needs to be merged as this is the only non-serializable object
  # so it gets reconstructed from the topic
  Karafka::Params::BatchMetadata
    .new(
      **hash
        .merge('deserializer' => topic.deserializer)
        .transform_keys(&:to_sym)
    )
end