Class: WaterDrop::Producer::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/waterdrop/producer/builder.rb

Overview

Class used to construct the rdkafka producer client

Instance Method Summary collapse

Instance Method Details

#call(producer, config) ⇒ Rdkafka::Producer, Producer::DummyClient

Returns raw rdkafka producer or a dummy producer when we don't want to dispatch any messages.

Parameters:

  • producer (Producer)

    not yet configured producer for which we want to build the client

  • config (Object)

    dry-configurable based configuration object

Returns:

  • (Rdkafka::Producer, Producer::DummyClient)

    raw rdkafka producer or a dummy producer when we don't want to dispatch any messages



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/waterdrop/producer/builder.rb', line 12

def call(producer, config)
  return DummyClient.new unless config.deliver

  client = Rdkafka::Config.new(config.kafka.to_h).producer

  # This callback is not global and is per client, thus we do not have to wrap it with a
  # callbacks manager to make it work
  client.delivery_callback = Instrumentation::Callbacks::Delivery.new(
    producer.id,
    config.monitor
  )

  client
end