Class: Karafka::Web::Producer
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Karafka::Web::Producer
- Defined in:
- lib/karafka/web/producer.rb
Overview
This uses SimpleDelegator to transparently proxy all producer methods
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
-
#__getobj__ ⇒ WaterDrop::Producer, WaterDrop::Producer::Variant
The underlying producer or its low-ack variant.
-
#initialize ⇒ Producer
constructor
A new instance of Producer.
Constructor Details
#initialize ⇒ Producer
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
accept block to avoid Ruby 3.4’s ‘strict_unused_block` warning from SimpleDelegator.
Returns 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 |