Class: Deimos::Backends::KafkaAsync

Inherits:
Base
  • Object
show all
Includes:
Phobos::Producer
Defined in:
lib/deimos/backends/kafka_async.rb

Overview

Backend which produces to Kafka via an async producer.

Class Method Summary collapse

Methods inherited from Base

publish

Class Method Details

.execute(producer_class:, messages:) ⇒ Object

:nodoc:



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/deimos/backends/kafka_async.rb', line 17

def self.execute(producer_class:, messages:)
  Deimos.instrument(
    'produce',
    producer: producer_class,
    topic: producer_class.topic,
    payloads: messages.map(&:payload)
  ) do
    producer.async_publish_list(messages.map(&:encoded_hash))
    Deimos.config.metrics&.increment(
      'publish',
      tags: %W(status:success topic:#{producer_class.topic}),
      by: messages.size
    )
  end
end

.shutdown_producervoid

This method returns an undefined value.

Shut down the producer cleanly.



11
12
13
14
# File 'lib/deimos/backends/kafka_async.rb', line 11

def self.shutdown_producer
  producer.async_producer_shutdown
  producer.kafka_client&.close
end