Class: Kafka::Producer

Inherits:
Object
  • Object
show all
Defined in:
lib/fluent/plugin/kafka_producer_ext.rb

Instance Method Summary collapse

Instance Method Details

#produce_for_buffered(value, key: nil, topic:, partition: nil, partition_key: nil) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/fluent/plugin/kafka_producer_ext.rb', line 15

def produce_for_buffered(value, key: nil, topic:, partition: nil, partition_key: nil)
  create_time = Time.now

  message = PendingMessage.new(
    value: value,
    key: key,
    headers: EMPTY_HEADER,
    topic: topic,
    partition: partition,
    partition_key: partition_key,
    create_time: create_time
  )

  # If the producer is in transactional mode, all the message production
  # must be used when the producer is currently in transaction
  if @transaction_manager.transactional? && !@transaction_manager.in_transaction?
    raise 'You must trigger begin_transaction before producing messages'
  end

  @target_topics.add(topic)
  @pending_message_queue.write(message)

  nil
end