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

#headersHash<String, String> (readonly)

Returns a message headers.

Returns:

  • (Hash<String, String>)

    a message headers



32
33
34
# File 'lib/rdkafka/consumer/message.rb', line 32

def headers
  @headers
end

#keyString? (readonly)

This message's key

Returns:

  • (String, nil)


21
22
23
# File 'lib/rdkafka/consumer/message.rb', line 21

def key
  @key
end

#offsetInteger (readonly)

This message's offset in its partition

Returns:

  • (Integer)


25
26
27
# File 'lib/rdkafka/consumer/message.rb', line 25

def offset
  @offset
end

#partitionInteger (readonly)

The partition this message was consumed from

Returns:

  • (Integer)


13
14
15
# File 'lib/rdkafka/consumer/message.rb', line 13

def partition
  @partition
end

#payloadString? (readonly)

This message's payload

Returns:

  • (String, nil)


17
18
19
# File 'lib/rdkafka/consumer/message.rb', line 17

def payload
  @payload
end

#timestampTime? (readonly)

This message's timestamp, if provided by the broker

Returns:

  • (Time, nil)


29
30
31
# File 'lib/rdkafka/consumer/message.rb', line 29

def timestamp
  @timestamp
end

#topicString (readonly)

The topic this message was consumed from

Returns:

  • (String)


9
10
11
# File 'lib/rdkafka/consumer/message.rb', line 9

def topic
  @topic
end

Instance Method Details

#to_sString

Human readable representation of this message.

Returns:

  • (String)


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

def to_s
  is_headers = @headers.empty? ? "" : ", headers #{headers.size}"

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

#truncate(string) ⇒ Object



74
75
76
77
78
79
80
# File 'lib/rdkafka/consumer/message.rb', line 74

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