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.



5
6
7
8
# File 'lib/nsqrb/producer.rb', line 5

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

Instance Method Details

#post!(obj) ⇒ Object



10
11
12
13
14
# File 'lib/nsqrb/producer.rb', line 10

def post!(obj)
  res = @http.post("/pub?topic=#{@topic}", obj.to_s)
  return if res.code == "200"
  res.error!
end