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_string) ⇒ Mixed

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:

  • (Mixed)

    the unmarshaled+base64 decoded data



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

def decode(params_string)
  Marshal.load(Base64.decode64(super)).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 (Mixed)

    the raw message(s) to encode

Returns:

  • (String)

    the marshaled+base64 encoded data



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

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