Class: Rafka::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/rafka/message.rb

Overview

Message represents a message consumed from a topic.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(msg) ⇒ Message

Returns a new instance of Message.

Examples:

Message.new(
  ["topic", "greetings", "partition", 2, "offset", 321123, "value", "Hi!"]
)

Parameters:

  • msg (Array)

    a message as received by the server

Raises:



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rafka/message.rb', line 14

def initialize(msg)
  if !msg.is_a?(Array) || msg.size != 8
    raise MalformedMessageError, msg
  end

  @topic = msg[1]

  begin
    @partition = Integer(msg[3])
    @offset = Integer(msg[5])
  rescue ArgumentError
    raise MalformedMessageError, msg
  end

  @value = msg[7]
end

Instance Attribute Details

#offsetObject (readonly)

Returns the value of attribute offset.



4
5
6
# File 'lib/rafka/message.rb', line 4

def offset
  @offset
end

#partitionObject (readonly)

Returns the value of attribute partition.



4
5
6
# File 'lib/rafka/message.rb', line 4

def partition
  @partition
end

#topicObject (readonly)

Returns the value of attribute topic.



4
5
6
# File 'lib/rafka/message.rb', line 4

def topic
  @topic
end

#valueObject (readonly)

Returns the value of attribute value.



4
5
6
# File 'lib/rafka/message.rb', line 4

def value
  @value
end