Class: Deimos::BatchConsumer

Inherits:
BaseConsumer show all
Includes:
Phobos::BatchHandler
Defined in:
lib/deimos/batch_consumer.rb

Overview

Class to consume batches of messages in a topic Note: According to the docs, instances of your handler will be created for every incoming batch of messages. This class should be lightweight.

Instance Method Summary collapse

Methods inherited from BaseConsumer

#decode_key, decoder, key_decoder

Instance Method Details

#around_consume_batch(batch, metadata) ⇒ Object

:nodoc:



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/deimos/batch_consumer.rb', line 14

def around_consume_batch(batch, )
  payloads = []
  benchmark = Benchmark.measure do
    if self.class.config[:key_configured]
      [:keys] = batch.map do |message|
        decode_key(message.key)
      end
    end

    payloads = batch.map do |message|
      message.payload ? self.class.decoder.decode(message.payload) : nil
    end
    _received_batch(payloads, )
    _with_error_span(payloads, ) do
      yield payloads, 
    end
  end
  _handle_success(benchmark.real, payloads, )
end

#consume_batch(_payloads, _metadata) ⇒ Object

Consume a batch of incoming messages.

Parameters:

  • _payloads (Array<Phobos::BatchMessage>)
  • _metadata (Hash)

Raises:

  • (NotImplementedError)


37
38
39
# File 'lib/deimos/batch_consumer.rb', line 37

def consume_batch(_payloads, )
  raise NotImplementedError
end