Module: WaterDrop::Producer::Buffer
- Included in:
- WaterDrop::Producer
- Defined in:
- lib/waterdrop/producer/buffer.rb
Overview
Component for buffered operations
Instance Method Summary collapse
-
#buffer(message) ⇒ Object
Adds given message into the internal producer buffer without flushing it to Kafka.
-
#buffer_many(messages) ⇒ Object
Adds given messages into the internal producer buffer without flushing them to Kafka.
-
#flush_async ⇒ Array<Rdkafka::Producer::DeliveryHandle>
Flushes the internal buffer to Kafka in an async way.
-
#flush_sync ⇒ Array<Rdkafka::Producer::DeliveryReport>
Flushes the internal buffer to Kafka in a sync way.
Instance Method Details
#buffer(message) ⇒ Object
Adds given message into the internal producer buffer without flushing it to Kafka
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/waterdrop/producer/buffer.rb', line 12 def buffer() ensure_active! @monitor.instrument( 'message.buffered', producer_id: id, message: , buffer: @messages ) { @messages << } end |
#buffer_many(messages) ⇒ Object
Adds given messages into the internal producer buffer without flushing them to Kafka
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/waterdrop/producer/buffer.rb', line 29 def buffer_many() ensure_active! @monitor.instrument( 'messages.buffered', producer_id: id, messages: , buffer: @messages ) do .each { || @messages << } end end |
#flush_async ⇒ Array<Rdkafka::Producer::DeliveryHandle>
Flushes the internal buffer to Kafka in an async way
46 47 48 49 50 51 52 |
# File 'lib/waterdrop/producer/buffer.rb', line 46 def flush_async @monitor.instrument( 'buffer.flushed_async', producer_id: id, messages: @messages ) { flush(false) } end |
#flush_sync ⇒ Array<Rdkafka::Producer::DeliveryReport>
Flushes the internal buffer to Kafka in a sync way
57 58 59 60 61 62 63 |
# File 'lib/waterdrop/producer/buffer.rb', line 57 def flush_sync @monitor.instrument( 'buffer.flushed_sync', producer_id: id, messages: @messages ) { flush(true) } end |