Class: Nsqrb::Producer

Inherits:
Object
  • Object
show all
Defined in:
lib/nsqrb/producer.rb

Instance Method Summary collapse

Constructor Details

#initialize(host, port, topic) ⇒ Producer

Returns a new instance of Producer.



3
4
5
6
# File 'lib/nsqrb/producer.rb', line 3

def initialize(host, port, topic)
  @http = ::Net::HTTP.new(host, port)
  @topic = topic
end

Instance Method Details

#post!(obj) ⇒ Object



8
9
10
11
12
# File 'lib/nsqrb/producer.rb', line 8

def post!(obj)
  res = @http.post("/pub?topic=" + @topic, obj.to_json)
  return if res.code == "200"
  res.error!
end