Class: Karafka::Web::Deserializer

Inherits:
Object
  • Object
show all
Defined in:
lib/karafka/web/deserializer.rb

Overview

Note:

We use symbolize_names because we want to use the same convention of hash building for producing, consuming and displaying metrics related data

Note:

We have to check if we compress the data, because older Web-UI versions were not compressing the payload.

Web reporting deserializer

Instance Method Summary collapse

Instance Method Details

#call(message) ⇒ Object

Returns deserialized data.

Parameters:

  • message (::Karafka::Messages::Message)

Returns:

  • (Object)

    deserialized data



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/karafka/web/deserializer.rb', line 15

def call(message)
  raw_payload = if message.headers.key?('zlib')
                  Zlib::Inflate.inflate(message.raw_payload)
                else
                  message.raw_payload
                end

  ::JSON.parse(
    raw_payload,
    symbolize_names: true,
    # We allow duplicates keys because of a fixed bug that was causing duplicated process
    # ids to leak into the consumers states data. Once a proper migration is written, this
    # can be retired
    # @see https://github.com/karafka/karafka-web/issues/741
    allow_duplicate_key: true
  )
end