Class: Sneakers::Publisher
- Inherits:
-
Object
- Object
- Sneakers::Publisher
- Defined in:
- lib/sneakers/publisher.rb
Instance Attribute Summary collapse
-
#channel ⇒ Object
readonly
Returns the value of attribute channel.
-
#exchange ⇒ Object
readonly
Returns the value of attribute exchange.
Instance Method Summary collapse
- #ensure_connection! ⇒ Object
-
#initialize(opts = {}) ⇒ Publisher
constructor
A new instance of Publisher.
- #publish(msg, options = {}) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Publisher
Returns a new instance of Publisher.
6 7 8 9 10 11 12 |
# File 'lib/sneakers/publisher.rb', line 6 def initialize(opts = {}) @mutex = Mutex.new @opts = Sneakers::CONFIG.merge(opts) # If we've already got a bunny object, use it. This allows people to # specify all kinds of options we don't need to know about (e.g. for ssl). @bunny = @opts[:connection] end |
Instance Attribute Details
#channel ⇒ Object (readonly)
Returns the value of attribute channel.
4 5 6 |
# File 'lib/sneakers/publisher.rb', line 4 def channel @channel end |
#exchange ⇒ Object (readonly)
Returns the value of attribute exchange.
4 5 6 |
# File 'lib/sneakers/publisher.rb', line 4 def exchange @exchange end |
Instance Method Details
#ensure_connection! ⇒ Object
24 25 26 27 28 |
# File 'lib/sneakers/publisher.rb', line 24 def ensure_connection! @mutex.synchronize do connect! unless connected? end end |
#publish(msg, options = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/sneakers/publisher.rb', line 14 def publish(msg, = {}) ensure_connection! to_queue = .delete(:to_queue) [:routing_key] ||= to_queue Sneakers.logger.info {"publishing <#{msg}> to [#{[:routing_key]}]"} serialized_msg = Sneakers::ContentType.serialize(msg, [:content_type]) encoded_msg = Sneakers::ContentEncoding.encode(serialized_msg, [:content_encoding]) @exchange.publish(encoded_msg, ) end |