Method: Rdkafka::Metadata#initialize
- Defined in:
- lib/rdkafka/metadata.rb
#initialize(native_client, topic_name = nil, timeout_ms = 250) ⇒ Metadata
Returns a new instance of Metadata.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/rdkafka/metadata.rb', line 7 def initialize(native_client, topic_name = nil, timeout_ms = 250) native_topic = if topic_name Rdkafka::Bindings.rd_kafka_topic_new(native_client, topic_name, nil) end ptr = FFI::MemoryPointer.new(:pointer) # If topic_flag is 1, we request info about *all* topics in the cluster. If topic_flag is 0, # we only request info about locally known topics (or a single topic if one is passed in). topic_flag = topic_name.nil? ? 1 : 0 # Retrieve the Metadata result = Rdkafka::Bindings.(native_client, topic_flag, native_topic, ptr, timeout_ms) # Error Handling raise Rdkafka::RdkafkaError.new(result) unless result.zero? (ptr.read_pointer) ensure Rdkafka::Bindings.rd_kafka_topic_destroy(native_topic) if topic_name Rdkafka::Bindings.(ptr.read_pointer) end |