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!Object

Cleans the message payload 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.



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

def clean!
  @deserialized = false
  @raw_payload = false
  @payload = nil
end

#cleaned?Boolean

Returns true if the message has been cleaned.

Returns:

  • (Boolean)

    true if the message has been cleaned



28
29
30
# File 'lib/karafka/pro/cleaner/messages/message.rb', line 28

def cleaned?
  @raw_payload == false
end

#payloadObject

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

Returns:

  • (Object)

    lazy-deserialized data (deserialized upon first request)



22
23
24
25
# File 'lib/karafka/pro/cleaner/messages/message.rb', line 22

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