Module: Karafka::Pro::Cleaner::Messages::Message

Defined in:
lib/karafka/pro/cleaner/messages/message.rb

Overview

Extensions to the message that allow for granular memory control on a per message basis

Instance Method Summary collapse

Instance Method Details

#clean!(metadata: true) ⇒ Object

Note:

Cleaning of message means we also clean its metadata (headers and key)

Note:

Metadata cleaning (headers and key) can be disabled by setting the ‘metadata` argument to `false`.

Cleans the message payload, headers, key and removes the deserialized data references This is useful when working with big messages that take a lot of space.

After the message content is no longer needed, it can be removed so it does not consume space anymore.

Parameters:

  • metadata (Boolean) (defaults to: true)

    should we also clean metadata alongside the payload. This can be useful when working with iterator and other things that may require only metadata available, while not payload. ‘true` by default.



37
38
39
40
41
42
43
# File 'lib/karafka/pro/cleaner/messages/message.rb', line 37

def clean!(metadata: true)
  @deserialized = false
  @raw_payload = false
  @payload = nil

  @metadata.clean! if 
end

#cleaned?Boolean

Returns true if the message has been cleaned.

Returns:

  • (Boolean)

    true if the message has been cleaned



20
21
22
# File 'lib/karafka/pro/cleaner/messages/message.rb', line 20

def cleaned?
  @raw_payload == false
end

#payloadObject

Returns lazy-deserialized data (deserialized upon first request).

Returns:

  • (Object)

    lazy-deserialized data (deserialized upon first request)



14
15
16
17
# File 'lib/karafka/pro/cleaner/messages/message.rb', line 14

def payload
  # If message has already been cleaned, it cannot be deserialized again
  cleaned? ? raise(Errors::MessageCleanedError) : super
end