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 |
# File 'lib/sneakers/publisher.rb', line 6 def initialize(opts = {}) @mutex = Mutex.new @opts = Sneakers::CONFIG.merge(opts) 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
21 22 23 24 25 |
# File 'lib/sneakers/publisher.rb', line 21 def ensure_connection! @mutex.synchronize do connect! unless connected? end end |
#publish(msg, options = {}) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/sneakers/publisher.rb', line 11 def publish(msg, = {}) ensure_connection! to_queue = .delete(:to_queue) [:routing_key] ||= to_queue Sneakers.logger.info {"publishing <#{msg}> to [#{options[:routing_key]}]"} serialized_msg = Sneakers::ContentType.serialize(msg, [:content_type]) encoded_msg = Sneakers::ContentEncoding.encode(serialized_msg, [:content_encoding]) @exchange.publish(encoded_msg, ) end |