lib/bunny/channel.rb in bunny-1.4.1 vs lib/bunny/channel.rb in bunny-1.5.0.pre1

- old
+ new

@@ -35,29 +35,26 @@ # ## Opening Channels # # Channels can be opened either via `Bunny::Session#create_channel` (sufficient in the majority # of cases) or by instantiating `Bunny::Channel` directly: # - # @example Using {Bunny::Session#create_channel}: - # conn = Bunny.new - # conn.start + # conn = Bunny.new + # conn.start # - # ch = conn.create_channel + # ch = conn.create_channel # # This will automatically allocate a channel id. # # ## Closing Channels # # Channels are closed via {Bunny::Channel#close}. Channels that get a channel-level exception are # closed, too. Closed channels can no longer be used. Attempts to use them will raise # {Bunny::ChannelAlreadyClosed}. # - # @example + # ch = conn.create_channel + # ch.close # - # ch = conn.create_channel - # ch.close - # # ## Higher-level API # # Bunny offers two sets of methods on {Bunny::Channel}: known as higher-level and lower-level # APIs, respectively. Higher-level API mimics {http://rubyamqp.info amqp gem} API where # exchanges and queues are objects (instance of {Bunny::Exchange} and {Bunny::Queue}, respectively). @@ -402,10 +399,20 @@ q = find_queue(name) || Bunny::Queue.new(self, name, opts) register_queue(q) end + # Declares a new server-named queue that is automatically deleted when the + # connection is closed. + # + # @return [Bunny::Queue] Queue that was declared + # @see #queue + # @api public + def temporary_queue(opts = {}) + queue("", opts.merge(:exclusive => true)) + end + # @endgroup # @group QoS and Flow Control @@ -564,28 +571,34 @@ # throughput. # # @param [String] queue Queue name # @param [Hash] opts Options # - # @option opts [Boolean] :ack (true) Will this message be acknowledged manually? + # @option opts [Boolean] :ack (true) [DEPRECATED] Use :manual_ack instead + # @option opts [Boolean] :manual_ack (true) Will this message be acknowledged manually? # # @return [Array] A triple of delivery info, message properties and message content # # @example Using Bunny::Channel#basic_get with manual acknowledgements # conn = Bunny.new # conn.start # ch = conn.create_channel # # here we assume the queue already exists and has messages - # delivery_info, properties, payload = ch.basic_get("bunny.examples.queue1", :ack => true) + # delivery_info, properties, payload = ch.basic_get("bunny.examples.queue1", :manual_ack => true) # ch.acknowledge(delivery_info.delivery_tag) # @see Bunny::Queue#pop # @see http://rubybunny.info/articles/queues.html Queues and Consumers guide # @api public - def basic_get(queue, opts = {:ack => true}) + def basic_get(queue, opts = {:manual_ack => true}) raise_if_no_longer_open! - @connection.send_frame(AMQ::Protocol::Basic::Get.encode(@id, queue, !(opts[:ack]))) + unless opts[:ack].nil? + warn "[DEPRECATION] `:ack` is deprecated. Please use `:manual_ack` instead." + opts[:manual_ack] = opts[:ack] + end + + @connection.send_frame(AMQ::Protocol::Basic::Get.encode(@id, queue, !(opts[:manual_ack]))) # this is a workaround for the edge case when basic_get is called in a tight loop # and network goes down we need to perform recovery. The problem is, basic_get will # keep blocking the thread that calls it without clear way to constantly unblock it # from the network activity loop (where recovery happens) with the current continuations # implementation (and even more correct and convenient ones, such as wait/notify, should @@ -673,11 +686,11 @@ # conn = Bunny.new # conn.start # # ch = conn.create_channel # # we assume the queue exists and has messages - # delivery_info, properties, payload = ch.basic_get("bunny.examples.queue3", :ack => true) + # delivery_info, properties, payload = ch.basic_get("bunny.examples.queue3", :manual_ack => true) # ch.basic_reject(delivery_info.delivery_tag, true) # # @see Bunny::Channel#basic_nack # @see http://rubybunny.info/articles/queues.html Queues and Consumers guide # @api public @@ -708,22 +721,22 @@ # conn = Bunny.new # conn.start # # ch = conn.create_channel # # we assume the queue exists and has messages - # delivery_info, properties, payload = ch.basic_get("bunny.examples.queue3", :ack => true) + # delivery_info, properties, payload = ch.basic_get("bunny.examples.queue3", :manual_ack => true) # ch.basic_ack(delivery_info.delivery_tag) # # @example Ack multiple messages fetched via basic.get # conn = Bunny.new # conn.start # # ch = conn.create_channel # # we assume the queue exists and has messages - # _, _, payload1 = ch.basic_get("bunny.examples.queue3", :ack => true) - # _, _, payload2 = ch.basic_get("bunny.examples.queue3", :ack => true) - # delivery_info, properties, payload3 = ch.basic_get("bunny.examples.queue3", :ack => true) + # _, _, payload1 = ch.basic_get("bunny.examples.queue3", :manual_ack => true) + # _, _, payload2 = ch.basic_get("bunny.examples.queue3", :manual_ack => true) + # delivery_info, properties, payload3 = ch.basic_get("bunny.examples.queue3", :manual_ack => true) # # ack all fetched messages up to payload3 # ch.basic_ack(delivery_info.delivery_tag, true) # # @see http://rubybunny.info/articles/queues.html Queues and Consumers guide # @see #basic_ack_known_delivery_tag @@ -767,22 +780,22 @@ # conn = Bunny.new # conn.start # # ch = conn.create_channel # # we assume the queue exists and has messages - # delivery_info, properties, payload = ch.basic_get("bunny.examples.queue3", :ack => true) + # delivery_info, properties, payload = ch.basic_get("bunny.examples.queue3", :manual_ack => true) # ch.basic_nack(delivery_info.delivery_tag, false, true) # # # @example Requeue multiple messages fetched via basic.get # conn = Bunny.new # conn.start # # ch = conn.create_channel # # we assume the queue exists and has messages - # _, _, payload1 = ch.basic_get("bunny.examples.queue3", :ack => true) - # _, _, payload2 = ch.basic_get("bunny.examples.queue3", :ack => true) - # delivery_info, properties, payload3 = ch.basic_get("bunny.examples.queue3", :ack => true) + # _, _, payload1 = ch.basic_get("bunny.examples.queue3", :manual_ack => true) + # _, _, payload2 = ch.basic_get("bunny.examples.queue3", :manual_ack => true) + # delivery_info, properties, payload3 = ch.basic_get("bunny.examples.queue3", :manual_ack => true) # # requeue all fetched messages up to payload3 # ch.basic_nack(delivery_info.delivery_tag, true, true) # # @see http://rubybunny.info/articles/queues.html Queues and Consumers guide # @see http://rubybunny.info/articles/extensions.html RabbitMQ Extensions guide