Class: Untied::Publisher::Bunny::Producer
- Inherits:
-
Untied::Publisher::BaseProducer
- Object
- Untied::Publisher::BaseProducer
- Untied::Publisher::Bunny::Producer
- Defined in:
- lib/untied-publisher/bunny/producer.rb
Instance Attribute Summary
Attributes inherited from Untied::Publisher::BaseProducer
#deliver_messages, #routing_key, #service_name
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Producer
constructor
A new instance of Producer.
-
#safe_publish(event) ⇒ Object
Publish the given event.
Methods inherited from Untied::Publisher::BaseProducer
Constructor Details
#initialize(opts = {}) ⇒ Producer
Returns a new instance of Producer.
7 8 9 10 11 12 13 14 15 |
# File 'lib/untied-publisher/bunny/producer.rb', line 7 def initialize(opts={}) super begin connection.start rescue ::Bunny::TCPConnectionFailed => e say "Can't connect to RabbitMQ: #{e.}" end end |
Instance Method Details
#safe_publish(event) ⇒ Object
Publish the given event.
event: object which is going to be serialized and sent through the
wire. It should respond to #to_json.
20 21 22 23 24 25 26 27 |
# File 'lib/untied-publisher/bunny/producer.rb', line 20 def safe_publish(event) if connection.status == :open exchange.publish(event.to_json, :routing_key => routing_key) else say "Event not sent. Connection status is #{connection.status}: " + \ "#{event.to_json}" end end |