Class: Kafka::Producer
Constant Summary
Constants included from IO
Instance Attribute Summary collapse
-
#partition ⇒ Object
Returns the value of attribute partition.
-
#topic ⇒ Object
Returns the value of attribute topic.
Attributes included from IO
Instance Method Summary collapse
- #batch(&block) ⇒ Object
-
#initialize(options = {}) ⇒ Producer
constructor
A new instance of Producer.
- #send(messages) ⇒ Object
Methods included from IO
#connect, #disconnect, #read, #reconnect, #write
Constructor Details
#initialize(options = {}) ⇒ Producer
Returns a new instance of Producer.
22 23 24 25 26 27 28 |
# File 'lib/kafka/producer.rb', line 22 def initialize( = {}) self.topic = [:topic] || "test" self.partition = [:partition] || 0 self.host = [:host] || HOST self.port = [:port] || PORT self.connect(self.host, self.port) end |
Instance Attribute Details
#partition ⇒ Object
Returns the value of attribute partition.
20 21 22 |
# File 'lib/kafka/producer.rb', line 20 def partition @partition end |
#topic ⇒ Object
Returns the value of attribute topic.
20 21 22 |
# File 'lib/kafka/producer.rb', line 20 def topic @topic end |
Instance Method Details
#batch(&block) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/kafka/producer.rb', line 34 def batch(&block) batch = Kafka::Batch.new block.call( batch ) self.send(batch.) batch..clear end |
#send(messages) ⇒ Object
30 31 32 |
# File 'lib/kafka/producer.rb', line 30 def send() self.write(Encoder.produce(self.topic, self.partition, )) end |