Class: Karafka::Messages::Metadata

Inherits:
Struct
  • Object
show all
Defined in:
lib/karafka/messages/metadata.rb

Overview

Single message metadata details that can be accessed without the need of deserialization.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#deserializersObject

Returns the value of attribute deserializers

Returns:

  • (Object)

    the current value of deserializers



6
7
8
# File 'lib/karafka/messages/metadata.rb', line 6

def deserializers
  @deserializers
end

#messageObject

Returns the value of attribute message

Returns:

  • (Object)

    the current value of message



6
7
8
# File 'lib/karafka/messages/metadata.rb', line 6

def message
  @message
end

#offsetObject

Returns the value of attribute offset

Returns:

  • (Object)

    the current value of offset



6
7
8
# File 'lib/karafka/messages/metadata.rb', line 6

def offset
  @offset
end

#partitionObject

Returns the value of attribute partition

Returns:

  • (Object)

    the current value of partition



6
7
8
# File 'lib/karafka/messages/metadata.rb', line 6

def partition
  @partition
end

#raw_headersObject

Returns the value of attribute raw_headers

Returns:

  • (Object)

    the current value of raw_headers



6
7
8
# File 'lib/karafka/messages/metadata.rb', line 6

def raw_headers
  @raw_headers
end

#raw_keyObject

Returns the value of attribute raw_key

Returns:

  • (Object)

    the current value of raw_key



6
7
8
# File 'lib/karafka/messages/metadata.rb', line 6

def raw_key
  @raw_key
end

#received_atObject

Returns the value of attribute received_at

Returns:

  • (Object)

    the current value of received_at



6
7
8
# File 'lib/karafka/messages/metadata.rb', line 6

def received_at
  @received_at
end

#timestampObject

Returns the value of attribute timestamp

Returns:

  • (Object)

    the current value of timestamp



6
7
8
# File 'lib/karafka/messages/metadata.rb', line 6

def timestamp
  @timestamp
end

#topicObject

Returns the value of attribute topic

Returns:

  • (Object)

    the current value of topic



6
7
8
# File 'lib/karafka/messages/metadata.rb', line 6

def topic
  @topic
end

Instance Method Details

#headersObject

Note:

Caching works as in #key, including falsy results

Returns deserialized headers. By default its a hash with keys and payload being strings.

Returns:

  • (Object)

    deserialized headers. By default its a hash with keys and payload being strings



34
35
36
37
38
39
40
# File 'lib/karafka/messages/metadata.rb', line 34

def headers
  return @headers if @headers_deserialized

  @headers = deserializers.headers.call(self)
  @headers_deserialized = true
  @headers
end

#keyObject

Note:

The result is cached after the first deserialization, including nil and other falsy results (e.g. keyless messages), hence the explicit flag instead of a truthiness check. As with Message#payload, the flag is set only after a successful deserialization, so an error is not cached and the next access retries.

Returns deserialized key. By default in the raw string format.

Returns:

  • (Object)

    deserialized key. By default in the raw string format.



23
24
25
26
27
28
29
# File 'lib/karafka/messages/metadata.rb', line 23

def key
  return @key if @key_deserialized

  @key = deserializers.key.call(self)
  @key_deserialized = true
  @key
end