Class: Rimless::Karafka::Base64Interchanger

Inherits:
Object
  • 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

Class Method Summary collapse

Class 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 self.decode(params_string)
  Marshal.load(Base64.decode64(params_string))
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 self.encode(params_batch)
  Base64.encode64(Marshal.dump(params_batch.to_a))
end