Class: Nsqrb::Producer
- Inherits:
-
Object
- Object
- Nsqrb::Producer
- Defined in:
- lib/nsqrb/producer.rb
Instance Method Summary collapse
-
#initialize(host, port, topic) ⇒ Producer
constructor
A new instance of Producer.
- #post!(obj) ⇒ Object
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 |