Class: Karafka::Messages::Messages
- Inherits:
-
Object
- Object
- Karafka::Messages::Messages
- Includes:
- Enumerable
- Defined in:
- lib/karafka/messages/messages.rb
Overview
Messages batch represents a set of messages received from Kafka of a single topic partition.
Instance Attribute Summary collapse
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
Instance Method Summary collapse
-
#deserialize! ⇒ Array<Karafka::Messages::Message>
Runs deserialization of all the messages and returns them.
- #each(&block) ⇒ Object
-
#empty? ⇒ Boolean
Is the messages batch empty.
-
#first ⇒ Karafka::Messages::Message
First message.
-
#initialize(messages_array, metadata) ⇒ Karafka::Messages::Messages
constructor
Lazy evaluated messages batch object.
-
#last ⇒ Karafka::Messages::Message
Last message.
-
#payloads ⇒ Array<Object>
Array with deserialized payloads.
-
#raw_payloads ⇒ Array<String>
Array with raw, not deserialized payloads.
-
#size ⇒ Integer
(also: #count)
Number of messages in the batch.
-
#to_a ⇒ Array<Karafka::Messages::Message>
Copy of the pure array with messages.
Constructor Details
#initialize(messages_array, metadata) ⇒ Karafka::Messages::Messages
Returns lazy evaluated messages batch object.
14 15 16 17 |
# File 'lib/karafka/messages/messages.rb', line 14 def initialize(, ) @messages_array = @metadata = end |
Instance Attribute Details
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
9 10 11 |
# File 'lib/karafka/messages/messages.rb', line 9 def @metadata end |
Instance Method Details
#deserialize! ⇒ Array<Karafka::Messages::Message>
Runs deserialization of all the messages and returns them
27 28 29 |
# File 'lib/karafka/messages/messages.rb', line 27 def deserialize! each(&:payload) end |
#each(&block) ⇒ Object
Invocation of this method will not cause loading and deserializing of messages.
21 22 23 |
# File 'lib/karafka/messages/messages.rb', line 21 def each(&block) @messages_array.each(&block) end |
#empty? ⇒ Boolean
Returns is the messages batch empty.
44 45 46 |
# File 'lib/karafka/messages/messages.rb', line 44 def empty? @messages_array.empty? end |
#first ⇒ Karafka::Messages::Message
Returns first message.
49 50 51 |
# File 'lib/karafka/messages/messages.rb', line 49 def first @messages_array.first end |
#last ⇒ Karafka::Messages::Message
Returns last message.
54 55 56 |
# File 'lib/karafka/messages/messages.rb', line 54 def last @messages_array.last end |
#payloads ⇒ Array<Object>
Returns array with deserialized payloads. This method can be useful when we don’t care about metadata and just want to extract all the data payloads from the batch.
34 35 36 |
# File 'lib/karafka/messages/messages.rb', line 34 def payloads map(&:payload) end |
#raw_payloads ⇒ Array<String>
Returns array with raw, not deserialized payloads.
39 40 41 |
# File 'lib/karafka/messages/messages.rb', line 39 def raw_payloads map(&:raw_payload) end |
#size ⇒ Integer Also known as: count
Returns number of messages in the batch.
59 60 61 |
# File 'lib/karafka/messages/messages.rb', line 59 def size @messages_array.size end |
#to_a ⇒ Array<Karafka::Messages::Message>
Returns copy of the pure array with messages.
64 65 66 |
# File 'lib/karafka/messages/messages.rb', line 64 def to_a @messages_array.dup end |