Navigation Menu

Skip to content

Commit

Permalink
API reference docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Klishin committed Jan 19, 2013
1 parent 8a06eab commit 25e8563
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/bunny/channel.rb
Expand Up @@ -359,13 +359,14 @@ def exchange(name, opts = {})
# @param [String] name Queue name. Pass an empty string to declare a server-named queue (make RabbitMQ generate a unique name).
# @param [Hash] opts Queue properties and other options
#
# @option options [Symbol, String] :type (:direct) Exchange type: :direct, :fanout, :topic, :headers, or a string for custom types
# @option options [Boolean] :durable (false) Should this queue be durable?
# @option options [Boolean] :auto-delete (false) Should this queue be automatically deleted when the last consumer disconnects?
# @option options [Boolean] :exclusive (false) Should this queue be exclusive (only can be used by this connection, removed when the connection is closed)?
# @option options [Boolean] :arguments ({}) Additional optional arguments (typically used by RabbitMQ extensions and plugins)
#
# @return [Bunny::Queue] Queue that was declared or looked up in the cache
# @see http://rubybunny.info/articles/queues.html Queues and Consumers guide
# @see http://rubybunny.info/articles/extensions.html RabbitMQ Extensions guide
# @api public
def queue(name = AMQ::Protocol::EMPTY_STRING, opts = {})
q = find_queue(name) || Bunny::Queue.new(self, name, opts)
Expand Down
46 changes: 46 additions & 0 deletions lib/bunny/queue.rb
@@ -1,6 +1,10 @@
require "bunny/compatibility"

module Bunny
# Represents AMQP 0.9.1 queue.
#
# @see http://rubybunny.info/articles/queues.html Queues and Consumers guide
# @see http://rubybunny.info/articles/extensions.html RabbitMQ Extensions guide
class Queue

include Bunny::Compatibility
Expand All @@ -12,6 +16,20 @@ class Queue

attr_reader :channel, :name, :options

# @param [Bunny::Channel] channel_or_connection Channel this queue will use. {Bunny::Session} instances are supported only for
# backwards compatibility with 0.8.
# @param [String] name Queue name. Pass an empty string to make RabbitMQ generate a unique one.
# @param [Hash] opts Queue properties
#
# @option opts [Boolean] :durable (false) Should this queue be durable?
# @option opts [Boolean] :auto-delete (false) Should this queue be automatically deleted when the last consumer disconnects?
# @option opts [Boolean] :exclusive (false) Should this queue be exclusive (only can be used by this connection, removed when the connection is closed)?
# @option opts [Boolean] :arguments ({}) Additional optional arguments (typically used by RabbitMQ extensions and plugins)
#
# @see Bunny::Channel#queue
# @see http://rubybunny.info/articles/queues.html Queues and Consumers guide
# @see http://rubybunny.info/articles/extensions.html RabbitMQ Extensions guide
# @api public
def initialize(channel_or_connection, name = AMQ::Protocol::EMPTY_STRING, opts = {})
# old Bunny versions pass a connection here. In that case,
# we just use default channel from it. MK.
Expand Down Expand Up @@ -59,11 +77,24 @@ def server_named?
@server_named
end # server_named?

# @return [Hash] Additional optional arguments (typically used by RabbitMQ extensions and plugins)
# @api public
def arguments
@arguments
end


# Binds queue to an exchange
#
# @param [Bunny::Exchange,String] exchange Exchange to bind to
# @param [Hash] opts Binding properties
#
# @option opts [String] :routing_key Routing key
# @option opts [Hash] :arguments ({}) Additional optional binding arguments
#
# @see http://rubybunny.info/articles/queues.html Queues and Consumers guide
# @see http://rubybunny.info/articles/bindings.html Bindings guide
# @api public
def bind(exchange, opts = {})
@channel.queue_bind(@name, exchange, opts)

Expand All @@ -82,6 +113,17 @@ def bind(exchange, opts = {})
self
end

# Unbinds queue from an exchange
#
# @param [Bunny::Exchange,String] exchange Exchange to unbind from
# @param [Hash] opts Binding properties
#
# @option opts [String] :routing_key Routing key
# @option opts [Hash] :arguments ({}) Additional optional binding arguments
#
# @see http://rubybunny.info/articles/queues.html Queues and Consumers guide
# @see http://rubybunny.info/articles/bindings.html Bindings guide
# @api public
def unbind(exchange, opts = {})
@channel.queue_unbind(@name, exchange, opts)

Expand All @@ -97,6 +139,10 @@ def unbind(exchange, opts = {})
self
end

# Adds a consumer to the queue (subscribes for message deliveries).
#
# @see http://rubybunny.info/articles/queues.html Queues and Consumers guide
# @api public
def subscribe(opts = {
:consumer_tag => @channel.generate_consumer_tag,
:ack => false,
Expand Down

0 comments on commit 25e8563

Please sign in to comment.