Exception: Racecar::MessageDeliveryError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/racecar/message_delivery_error.rb

Overview

MessageDeliveryError wraps an Rdkafka error and tries to give specific hints on how to debug or resolve the error within the Racecar context.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rdkafka_error, delivery_handle) ⇒ MessageDeliveryError

Returns a new instance of MessageDeliveryError.



18
19
20
21
22
23
# File 'lib/racecar/message_delivery_error.rb', line 18

def initialize(rdkafka_error, delivery_handle)
  raise rdkafka_error unless rdkafka_error.is_a?(Rdkafka::RdkafkaError)

  @rdkafka_error = rdkafka_error
  @delivery_handle = delivery_handle
end

Instance Attribute Details

#rdkafka_errorObject (readonly)

Returns the value of attribute rdkafka_error.



25
26
27
# File 'lib/racecar/message_delivery_error.rb', line 25

def rdkafka_error
  @rdkafka_error
end

Class Method Details

.partition_from_delivery_handle(delivery_handle) ⇒ Object

partition_from_delivery_handle takes an rdkafka delivery handle and returns a human readable version of the partition. It handles the case where the partition is unknown.



11
12
13
14
15
16
# File 'lib/racecar/message_delivery_error.rb', line 11

def self.partition_from_delivery_handle(delivery_handle)
  partition = delivery_handle&.create_result&.partition
  # -1 is rdkafka-ruby's default value, which gets eventually set by librdkafka
  return "no yet known" if partition.nil? || partition == -1
  partition.to_s
end

Instance Method Details

#codeObject



27
28
29
# File 'lib/racecar/message_delivery_error.rb', line 27

def code
  @rdkafka_error.code
end

#to_sObject



31
32
33
34
35
36
37
38
# File 'lib/racecar/message_delivery_error.rb', line 31

def to_s
  msg = <<~EOM
    Message delivery finally failed:
    #{@rdkafka_error.to_s}

    #{explain}
  EOM
end