Class: Karafka::Web::Producer

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/karafka/web/producer.rb

Overview

Note:

This uses SimpleDelegator to transparently proxy all producer methods

Note:

The variant is created lazily on first access to ensure the default producer is fully initialized

A lazy-evaluated producer wrapper that creates a low-intensity variant of the default Karafka producer when possible.

Web UI reporting is not mission-critical and serves primarily analytical purposes. Users typically want stronger delivery warranties for their business producers. For web UI reporting, we can use lower acknowledgment levels to reduce overhead.

This wrapper:

  • Returns the default producer unchanged if it’s idempotent or transactional (since acks cannot be altered for these producer types)

  • Creates a variant with ‘acks: 1` for non-idempotent, non-transactional producers to reduce latency while maintaining basic delivery confirmation

Instance Method Summary collapse

Constructor Details

#initializeProducer

Returns a new instance of Producer.



22
23
24
25
26
# File 'lib/karafka/web/producer.rb', line 22

def initialize
  @initialized = false
  # Initialize with nil - will be set on first access
  super(nil)
end

Instance Method Details

#__getobj__WaterDrop::Producer, WaterDrop::Producer::Variant

Note:

accept block to avoid Ruby 3.4’s ‘strict_unused_block` warning from SimpleDelegator.

Returns the underlying producer or its low-ack variant.

Returns:

  • (WaterDrop::Producer, WaterDrop::Producer::Variant)

    the underlying producer or its low-ack variant



31
32
33
34
35
36
37
38
# File 'lib/karafka/web/producer.rb', line 31

def __getobj__(&)
  unless @initialized
    @delegate_sd_obj = build_producer
    @initialized = true
  end

  @delegate_sd_obj
end