Class: Rdkafka::Consumer::Partition

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

Overview

Information about a partition, used in TopicPartitionList.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(partition, offset, err = Rdkafka::Bindings::RD_KAFKA_RESP_ERR_NO_ERROR, metadata = nil) ⇒ Partition

Returns a new instance of Partition.

Parameters:

  • partition (Integer)

    partition number

  • offset (Integer, nil)

    partition offset

  • err (Integer) (defaults to: Rdkafka::Bindings::RD_KAFKA_RESP_ERR_NO_ERROR)

    error code from librdkafka

  • metadata (String, nil) (defaults to: nil)

    partition metadata



28
29
30
31
32
33
# File 'lib/rdkafka/consumer/partition.rb', line 28

def initialize(partition, offset, err = Rdkafka::Bindings::RD_KAFKA_RESP_ERR_NO_ERROR,  = nil)
  @partition = partition
  @offset = offset
  @err = err
  @metadata = 
end

Instance Attribute Details

#errInteger (readonly)

Partition’s error code

Returns:

  • (Integer)


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

def err
  @err
end

#metadataString? (readonly)

Partition metadata in the context of a consumer

Returns:

  • (String, nil)


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

def 
  @metadata
end

#offsetInteger? (readonly)

Partition’s offset

Returns:

  • (Integer, nil)


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

def offset
  @offset
end

#partitionInteger (readonly)

Partition number

Returns:

  • (Integer)


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

def partition
  @partition
end

Instance Method Details

#==(other) ⇒ Boolean

Whether another partition is equal to this

Parameters:

  • other (Object)

    object to compare with

Returns:

  • (Boolean)


55
56
57
58
59
# File 'lib/rdkafka/consumer/partition.rb', line 55

def ==(other)
  self.class == other.class &&
    self.partition == other.partition &&
    self.offset == other.offset
end

#inspectString

Human readable representation of this partition.

Returns:

  • (String)


48
49
50
# File 'lib/rdkafka/consumer/partition.rb', line 48

def inspect
  to_s
end

#to_sString

Human readable representation of this partition.

Returns:

  • (String)


37
38
39
40
41
42
43
44
# File 'lib/rdkafka/consumer/partition.rb', line 37

def to_s
  message = "<Partition #{partition}"
  message += " offset=#{offset}" if offset
  message += " err=#{err}" if err != Rdkafka::Bindings::RD_KAFKA_RESP_ERR_NO_ERROR
  message += " metadata=#{}" if  != nil
  message += ">"
  message
end