Class: EventMachine::Kafka::Producer
- Inherits:
-
Object
- Object
- EventMachine::Kafka::Producer
- Defined in:
- lib/em-kafka/producer.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#host ⇒ Object
Returns the value of attribute host.
-
#partition ⇒ Object
Returns the value of attribute partition.
-
#port ⇒ Object
Returns the value of attribute port.
-
#topic ⇒ Object
Returns the value of attribute topic.
Instance Method Summary collapse
- #deliver(message) ⇒ Object
-
#initialize(uri) ⇒ Producer
constructor
A new instance of Producer.
Constructor Details
#initialize(uri) ⇒ Producer
Returns a new instance of Producer.
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/em-kafka/producer.rb', line 7 def initialize(uri) uri = URI(uri) self.host = uri.host self.port = uri.port self.topic = uri.user self.partition = uri.path[1..-1].to_i raise ArgumentError("topic required") unless topic self.client = EM::Kafka::Client.new(host, port) client.connect end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
5 6 7 |
# File 'lib/em-kafka/producer.rb', line 5 def client @client end |
#host ⇒ Object
Returns the value of attribute host.
5 6 7 |
# File 'lib/em-kafka/producer.rb', line 5 def host @host end |
#partition ⇒ Object
Returns the value of attribute partition.
5 6 7 |
# File 'lib/em-kafka/producer.rb', line 5 def partition @partition end |
#port ⇒ Object
Returns the value of attribute port.
5 6 7 |
# File 'lib/em-kafka/producer.rb', line 5 def port @port end |
#topic ⇒ Object
Returns the value of attribute topic.
5 6 7 |
# File 'lib/em-kafka/producer.rb', line 5 def topic @topic end |
Instance Method Details
#deliver(message) ⇒ Object
20 21 22 23 |
# File 'lib/em-kafka/producer.rb', line 20 def deliver() request = EM::Kafka::ProducerRequest.new(topic, partition, ) client.send_data(request.encode) end |