Method: Bunny::Queue#initialize

Defined in:
lib/bunny/queue.rb

#initialize(channel, name = AMQ::Protocol::EMPTY_STRING, opts = {}) ⇒ Queue

Returns a new instance of Queue.

Parameters:

  • channel (Bunny::Channel)

    Channel this queue will use.

  • name (String) (defaults to: AMQ::Protocol::EMPTY_STRING)

    Queue name. Pass an empty string to make RabbitMQ generate a unique one.

  • opts (Hash) (defaults to: {})

    Queue properties

Options Hash (opts):

  • :durable (Boolean) — default: false

    Should this queue be durable?

  • :auto_delete (Boolean) — default: false

    Should this queue be automatically deleted when the last consumer disconnects?

  • :exclusive (Boolean) — default: false

    Should this queue be exclusive (only can be used by this connection, removed when the connection is closed)?

  • :type (String) — default: nil

    Type of the declared queue (classic, quorum or stream)

  • :arguments (Hash) — default: nil

    Additional optional arguments (typically used by RabbitMQ extensions and plugins)

See Also:



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/bunny/queue.rb', line 54

def initialize(channel, name = AMQ::Protocol::EMPTY_STRING, opts = {})
  # old Bunny versions pass a connection here. In that case,
  # we just use default channel from it. MK.
  @channel          = channel
  @name             = name
  @options          = self.class.add_default_options(name, opts)

  @durable          = @options[:durable]
  @exclusive        = @options[:exclusive]
  @server_named     = @name.empty?
  @auto_delete      = @options[:auto_delete]
  @type             = @options[:type]

  @arguments        = if @type and !@type.empty? then
    (@options[:arguments] || {}).merge({XArgs::QUEUE_TYPE => @type})
  else
    @options[:arguments]
  end
  verify_type!(@arguments)
  # reassigns updated and verified arguments because Bunny::Channel#declare_queue
  # accepts a map of options
  @options[:arguments] = @arguments

  @bindings         = Array.new

  @default_consumer = nil

  declare! unless opts[:no_declare]

  # for basic.deliver dispatch and such
  @channel.register_queue(self)
  # for topology recovery
  @channel.record_queue(self)
end