Class: Rdkafka::Consumer::Message

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

Overview

A message that was consumed from a topic.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#keyString? (readonly)

This message's key

Returns:

  • (String, nil)

19
20
21
# File 'lib/rdkafka/consumer/message.rb', line 19

def key
  @key
end

#offsetInteger (readonly)

This message's offset in it's partition

Returns:

  • (Integer)

23
24
25
# File 'lib/rdkafka/consumer/message.rb', line 23

def offset
  @offset
end

#partitionInteger (readonly)

The partition this message was consumed from

Returns:

  • (Integer)

11
12
13
# File 'lib/rdkafka/consumer/message.rb', line 11

def partition
  @partition
end

#payloadString? (readonly)

This message's payload

Returns:

  • (String, nil)

15
16
17
# File 'lib/rdkafka/consumer/message.rb', line 15

def payload
  @payload
end

#timestampTime? (readonly)

This message's timestamp, if provided by the broker

Returns:

  • (Time, nil)

27
28
29
# File 'lib/rdkafka/consumer/message.rb', line 27

def timestamp
  @timestamp
end

#topicString (readonly)

The topic this message was consumed from

Returns:

  • (String)

7
8
9
# File 'lib/rdkafka/consumer/message.rb', line 7

def topic
  @topic
end

Instance Method Details

#to_sString

Human readable representation of this message.

Returns:

  • (String)

61
62
63
# File 'lib/rdkafka/consumer/message.rb', line 61

def to_s
  "<Message in '#{topic}' with key '#{truncate(key)}', payload '#{truncate(payload)}', partition #{partition}, offset #{offset}, timestamp #{timestamp}>"
end

#truncate(string) ⇒ Object


65
66
67
68
69
70
71
# File 'lib/rdkafka/consumer/message.rb', line 65

def truncate(string)
  if string && string.length > 40
    "#{string[0..39]}..."
  else
    string
  end
end