Class: Karafka::Messages::Message
- Inherits:
-
Object
- Object
- Karafka::Messages::Message
- Extended by:
- Forwardable
- Defined in:
- lib/karafka/messages/message.rb
Overview
It provides lazy loading not only until the first usage, but also allows us to skip using deserializer until we execute our logic. That way we can operate with heavy-deserialization data without slowing down the whole application.
Instance Attribute Summary collapse
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#raw_payload ⇒ Object
raw payload needs to be mutable as we want to have option to change it in the parser prior to the final deserialization.
Class Method Summary collapse
-
.parser ⇒ Object
General parser.
Instance Method Summary collapse
-
#deserialized? ⇒ Boolean
Did we deserialize payload already.
-
#initialize(raw_payload, metadata) ⇒ Message
constructor
A new instance of Message.
-
#payload ⇒ Object
Lazy-deserialized data (deserialized upon first request).
Constructor Details
#initialize(raw_payload, metadata) ⇒ Message
Returns a new instance of Message.
31 32 33 34 35 36 |
# File 'lib/karafka/messages/message.rb', line 31 def initialize(raw_payload, ) @raw_payload = raw_payload @metadata = @deserialized = false @payload = nil end |
Instance Attribute Details
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
21 22 23 |
# File 'lib/karafka/messages/message.rb', line 21 def @metadata end |
#raw_payload ⇒ Object
raw payload needs to be mutable as we want to have option to change it in the parser prior to the final deserialization
24 25 26 |
# File 'lib/karafka/messages/message.rb', line 24 def raw_payload @raw_payload end |
Class Method Details
Instance Method Details
#deserialized? ⇒ Boolean
Returns did we deserialize payload already.
50 51 52 |
# File 'lib/karafka/messages/message.rb', line 50 def deserialized? @deserialized end |
#payload ⇒ Object
Returns lazy-deserialized data (deserialized upon first request).
39 40 41 42 43 44 45 46 47 |
# File 'lib/karafka/messages/message.rb', line 39 def payload return @payload if deserialized? @payload = deserialize # We mark deserialization as successful after deserialization, as in case of an error # this won't be falsely set to true @deserialized = true @payload end |