Method: Bunny::Channel#queue_declare

Defined in:
lib/bunny/channel.rb

#queue_declare(name, opts = {}) ⇒ AMQ::Protocol::Queue::DeclareOk

Declares a queue using queue.declare AMQP 0.9.1 method.

Parameters:

  • name (String)

    The name of the queue or an empty string to let RabbitMQ generate a name. Note that LF and CR characters will be stripped from the value.

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

    Queue properties

Options Hash (opts):

  • durable (Boolean) — default: false

    Should information about this queue be persisted to disk so that it can survive broker restarts? Typically set to true for long-lived queues.

  • auto_delete (Boolean) — default: false

    Should this queue be deleted when the last consumer is cancelled?

  • exclusive (Boolean) — default: false

    Should only this connection be able to use this queue? If true, the queue will be automatically deleted when this connection is closed

  • passive (Boolean) — default: false

    If true, queue will be checked for existence. If it does not exist, NotFound will be raised.

  • :arguments (Hash) — default: {}

    Optional queue arguments (x-arguments)

Returns:

  • (AMQ::Protocol::Queue::DeclareOk)

    RabbitMQ response

See Also:



1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
# File 'lib/bunny/channel.rb', line 1249

def queue_declare(name, opts = {})
  # strip trailing new line and carriage returns
  # just like RabbitMQ does
  safe_name = name.gsub(/[\r\n]/, "")
  is_server_named = (safe_name == AMQ::Protocol::EMPTY_STRING)
  passive = opts.fetch(:passive, false)
  durable = opts.fetch(:durable, false)
  exclusive = opts.fetch(:exclusive, false)
  auto_delete = opts.fetch(:auto_delete, false)
  args = opts[:arguments]

  result = self.queue_declare_without_recording_topology(name, opts)
  self.record_queue_with(self, result.queue, is_server_named, durable, exclusive, auto_delete, args) unless passive

  result
end