module Karafka::Extensions::ParamsBuilder

Extension for rebuilding params from a hash

Public Instance Methods

from_hash(hash, topic) click to toggle source

Builds params from a hash @param hash [Hash] hash with params details @param topic [Karafka::Routing::Topic] topic for which we build the params @return [Karafka::Params::Params] built params

# File lib/karafka/extensions/params_builder.rb, line 11
def from_hash(hash, topic)
  metadata = Karafka::Params::Metadata.new(
    **hash
      .fetch('metadata')
      .merge('deserializer' => topic.deserializer)
      .transform_keys(&:to_sym)
  ).freeze

  Karafka::Params::Params
    .new(hash.fetch('raw_payload'), metadata)
end