Class: Kafka::KafkaProducer

Inherits:
Object
  • Object
show all
Defined in:
lib/jruby-kafka/kafka-producer.rb

Overview

noinspection JRubyStringImportInspection

Defined Under Namespace

Classes: RubyCallback

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ KafkaProducer

Create a Kafka producer.

For other configuration properties and their default values see kafka.apache.org/documentation.html#producerconfigs and kafka.apache.org/0100/javadoc/index.html?org/apache/kafka/clients/consumer/KafkaConsumer.html.

Parameters:

  • config (Hash)

    the producer configuration.



35
36
37
38
# File 'lib/jruby-kafka/kafka-producer.rb', line 35

def initialize(opts = {})
  @properties = opts.clone
  super Kafka::Utility.java_properties @properties
end

Instance Attribute Details

#propertiesObject (readonly)

Returns the value of attribute properties.



21
22
23
# File 'lib/jruby-kafka/kafka-producer.rb', line 21

def properties
  @properties
end

Instance Method Details

#send_msg(topic, partition, key, value, &block) ⇒ Object

throws FailedToSendMessageException or if not connected, StandardError.



44
45
46
47
48
49
50
# File 'lib/jruby-kafka/kafka-producer.rb', line 44

def send_msg(topic, partition, key, value, &block)
  if block
    send_cb_method ProducerRecord.new(topic, partition, key, value), RubyCallback.new(block)
  else
    send_method ProducerRecord.new(topic, partition, key, value)
  end
end