Class: Deimos::Backends::Kafka

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

Overview

Default backend to produce to Kafka.

Class Method Summary collapse

Methods inherited from Base

publish

Class Method Details

.execute(producer_class:, messages:) ⇒ Object

:nodoc:



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

def self.execute(producer_class:, messages:)
  Deimos.instrument(
    'produce',
    producer: producer_class,
    topic: producer_class.topic,
    payloads: messages.map(&:payload)
  ) do
    producer.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_producerObject

Shut down the producer if necessary.



10
11
12
13
# File 'lib/deimos/backends/kafka.rb', line 10

def self.shutdown_producer
  producer.sync_producer_shutdown if producer.respond_to?(:sync_producer_shutdown)
  producer.kafka_client&.close
end