Class: Rimless::Karafka::Base64Interchanger

Inherits:
Karafka::Interchanger
  • Object
show all
Defined in:
lib/rimless/karafka/base64_interchanger.rb

Overview

Allow the karafka-sidekiq-backend gem to transfer binary Apache Kafka messages to the actual Sidekiq job.

rubocop:disable Security/MarshalLoad because we encode/decode the

messages in our own controlled context

Instance Method Summary collapse

Instance Method Details

#decode(params_batch) ⇒ Array<Hash>

Decode the binary Apache Kafka message(s) so they can be processed by the Sidekiq Rimless::ConsumerJob.

Parameters:

  • params_string (String)

    the marshaled+base64 encoded data

Returns:

  • (Array<Hash>)

    the unmarshaled+base64 decoded data



26
27
28
# File 'lib/rimless/karafka/base64_interchanger.rb', line 26

def decode(params_batch)
  super(Marshal.load(Base64.decode64(params_batch))).map(&:stringify_keys)
end

#encode(params_batch) ⇒ String

Encode a binary Apache Kafka message(s) so they can be passed to the Sidekiq Rimless::ConsumerJob.

Parameters:

  • params_batch (Karafka::Params::ParamsBatch)

    the karafka params batch object

Returns:

  • (String)

    the marshaled+base64 encoded data



17
18
19
# File 'lib/rimless/karafka/base64_interchanger.rb', line 17

def encode(params_batch)
  Base64.encode64(Marshal.dump(super))
end