Class: Avro2Kafka::KafkaPublisher
- Inherits:
-
Object
- Object
- Avro2Kafka::KafkaPublisher
- Defined in:
- lib/avro2kafka/kafka_publisher.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#keys ⇒ Object
readonly
Returns the value of attribute keys.
-
#producer ⇒ Object
readonly
Returns the value of attribute producer.
-
#topic ⇒ Object
readonly
Returns the value of attribute topic.
Instance Method Summary collapse
-
#initialize(broker_list:, topic:, keys: [], data: {}) ⇒ KafkaPublisher
constructor
A new instance of KafkaPublisher.
- #publish(records) ⇒ Object
Constructor Details
#initialize(broker_list:, topic:, keys: [], data: {}) ⇒ KafkaPublisher
Returns a new instance of KafkaPublisher.
8 9 10 11 12 13 |
# File 'lib/avro2kafka/kafka_publisher.rb', line 8 def initialize(broker_list:, topic:, keys: [], data: {}) @producer = Poseidon::Producer.new(broker_list, 'avro2kafka') @topic = topic @keys = keys @data = data end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
6 7 8 |
# File 'lib/avro2kafka/kafka_publisher.rb', line 6 def data @data end |
#keys ⇒ Object (readonly)
Returns the value of attribute keys.
6 7 8 |
# File 'lib/avro2kafka/kafka_publisher.rb', line 6 def keys @keys end |
#producer ⇒ Object (readonly)
Returns the value of attribute producer.
6 7 8 |
# File 'lib/avro2kafka/kafka_publisher.rb', line 6 def producer @producer end |
#topic ⇒ Object (readonly)
Returns the value of attribute topic.
6 7 8 |
# File 'lib/avro2kafka/kafka_publisher.rb', line 6 def topic @topic end |
Instance Method Details
#publish(records) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/avro2kafka/kafka_publisher.rb', line 15 def publish(records) records.each_slice(100) do |batch| = batch.map { |record| prepare_record(record) } producer.() end end |