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

#headers ⇒ Hash{String => String} (readonly)

Returns message headers.

Returns:

  • (Hash{String => String}) —

    message headers



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

def headers
  @headers
end

#key ⇒ String? (readonly)

This message's key

Returns:

  • (String, nil)


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

def key
  @key
end

#offset ⇒ Integer (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

#partition ⇒ Integer (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

#payload ⇒ String? (readonly)

This message's payload

Returns:

  • (String, nil)


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

def payload
  @payload
end

#timestamp ⇒ Time? (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

#topic ⇒ String (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_s ⇒ String

Human readable representation of this message.

Returns:

  • (String)


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

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