Class: Liebre::Publisher
- Inherits:
-
Object
- Object
- Liebre::Publisher
- Defined in:
- lib/liebre/publisher.rb
Instance Method Summary collapse
- #enqueue(message, options = {}) ⇒ Object
- #enqueue_and_wait(message, options = {}) ⇒ Object (also: #rpc)
-
#initialize(publisher_name) ⇒ Publisher
constructor
A new instance of Publisher.
Constructor Details
#initialize(publisher_name) ⇒ Publisher
Returns a new instance of Publisher.
4 5 6 |
# File 'lib/liebre/publisher.rb', line 4 def initialize publisher_name @publisher_name = publisher_name end |
Instance Method Details
#enqueue(message, options = {}) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/liebre/publisher.rb', line 8 def enqueue , = {} with_connection do exchange = exchange_for default_channel logger.debug "Liebre: Publishing '#{}' with '#{}' to exchange: #{exchange.name}" exchange.publish , end end |
#enqueue_and_wait(message, options = {}) ⇒ Object Also known as: rpc
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/liebre/publisher.rb', line 16 def enqueue_and_wait , = {} result = nil with_rpc_channel do |channel| correlation_id = [:correlation_id] ||= generate_uuid reply_queue = reply_queue channel, correlation_id [:reply_to] = reply_queue.name reply_queue.subscribe(:block => false) do |delivery_info, , payload| if [:correlation_id] == correlation_id result = payload logger.debug "Liebre: Received response '#{result}'" channel.consumers[delivery_info.consumer_tag].cancel end end exchange = exchange_for channel logger.debug "Liebre: Publishing '#{}' with '#{}' to exchange: #{exchange.name}" exchange.publish , begin Timeout.timeout(Liebre.config.rpc_request_timeout) do sleep 0.01 while result.nil? end rescue Timeout::Error #do nothing end end result end |