ri > Bunny::Channel

= Bunny::Channel < Object

(from /home/chedong/.local/share/rdoc)
------------------------------------------------------------------------
## Channels in RabbitMQ

To quote {http://www.rabbitmq.com/resources/specs/amqp0-9-1.pdf AMQP
0.9.1 specification}:

AMQP 0.9.1 is a multi-channelled protocol. Channels provide a way to
multiplex a heavyweight TCP/IP connection into several light weight
connections. This makes the protocol more “firewall friendly” since port
usage is predictable. It also means that traffic shaping and other
network QoS features can be easily employed. Channels are independent of
each other and can perform different functions simultaneously with other
channels, the available bandwidth being shared between the concurrent
activities.

## Opening Channels

Channels can be opened either via `Bunny::Session#create_channel`
(sufficient in the majority of cases) or by instantiating Bunny::Channel
directly:

  conn = Bunny.new
  conn.start

  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}.

  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). Lower-level API is built around AMQP 0.9.1 methods
(commands), where queues and exchanges are passed as strings (à la
RabbitMQ Java client, {http://clojurerabbitmq.info Langohr} and Pika).

### Queue Operations In Higher-level API

* {Bunny::Channel#queue} is used to declare queues. The rest of the API
  is in {Bunny::Queue}.

### Exchange Operations In Higher-level API

* {Bunny::Channel#topic} declares a topic exchange. The rest of the API
  is in {Bunny::Exchange}.
* {Bunny::Channel#direct} declares a direct exchange.
* {Bunny::Channel#fanout} declares a fanout exchange.
* {Bunny::Channel#headers} declares a headers exchange.
* {Bunny::Channel#default_exchange}
* {Bunny::Channel#exchange} is used to declare exchanges with type
  specified as a symbol or string.

## Channel Qos (Prefetch Level)

It is possible to control how many messages at most a consumer will be
given (before it acknowledges or rejects previously consumed ones). This
setting is per channel and controlled via {Bunny::Channel#prefetch}.

## Channel IDs

Channels are identified by their ids which are integers. Bunny takes
care of allocating and releasing them as channels are opened and closed.
It is almost never necessary to specify channel ids explicitly.

There is a limit on the maximum number of channels per connection,
usually 65536. Note that allocating channels is very cheap on both
client and server so having tens, hundreds or even thousands of channels
is not a problem.

## Channels and Error Handling

Channel-level exceptions are more common than connection-level ones and
often indicate issues applications can recover from (such as consuming
from or trying to delete a queue that does not exist).

With Bunny, channel-level exceptions are raised as Ruby exceptions, for
example, {Bunny::NotFound}, that provide access to the underlying
channel.close method information.

@example Handling 404 NOT_FOUND
  begin
    ch.queue_delete("queue_that_should_not_exist#{rand}")
  rescue Bunny::NotFound => e
    puts "Channel-level exception! Code: #{e.channel_close.reply_code}, message: #{e.channel_close.reply_text}"
  end

@example Handling 406 PRECONDITION_FAILED
  begin
    ch2 = conn.create_channel
    q   = "bunny.examples.recovery.q#{rand}"

    ch2.queue_declare(q, :durable => false)
    ch2.queue_declare(q, :durable => true)
  rescue Bunny::PreconditionFailed => e
    puts "Channel-level exception! Code: #{e.channel_close.reply_code}, message: #{e.channel_close.reply_text}"
  ensure
    conn.create_channel.queue_delete(q)
  end

@see http://www.rabbitmq.com/tutorials/amqp-concepts.html AMQP 0.9.1
Model Concepts Guide @see
http://rubybunny.info/articles/getting_started.html Getting Started with
RabbitMQ Using Bunny @see http://rubybunny.info/articles/queues.html
Queues and Consumers @see http://rubybunny.info/articles/exchanges.html
Exchanges and Publishing @see
http://rubybunny.info/articles/error_handling.html Error Handling and
Recovery Guide
------------------------------------------------------------------------
= Constants:

DEFAULT_CONTENT_TYPE:
  [not documented]

MAX_PREFETCH_COUNT:
  prefetch_count is of type short in the protocol. MK.

SHORTSTR_LIMIT:
  [not documented]


= Class methods:

  new

= Instance methods:

  ack
  acknowledge
  active
  add_consumer
  any_consumers?
  basic_ack
  basic_cancel
  basic_consume
  basic_consume_with
  basic_get
  basic_nack
  basic_publish
  basic_qos
  basic_recover
  basic_reject
  can_accept_queue_declare_ok?
  channel_flow
  channel_level_exception_after_operation_that_has_no_response?
  client
  close
  closed!
  closed?
  confirm_select
  connection
  consume
  consume_with
  consumers
  default_exchange
  deregister_exchange
  deregister_queue
  deregister_queue_named
  direct
  exchange
  exchange_bind
  exchange_declare
  exchange_delete
  exchange_unbind
  exchanges
  fanout
  find_exchange
  find_queue
  flow
  frame_size
  generate_consumer_tag
  guarding_against_stale_delivery_tags
  handle_ack_or_nack
  handle_basic_get_empty
  handle_basic_get_ok
  handle_basic_return
  handle_frameset
  handle_method
  headers
  id
  increment_recoveries_counter
  inspect
  instantiate_channel_level_exception
  maybe_kill_consumer_work_pool!
  maybe_pause_consumer_work_pool!
  maybe_start_consumer_work_pool!
  nack
  nacked_set
  new_continuation
  next_publish_seq_no
  number
  on_error
  on_uncaught_exception
  open
  open?
  pending_server_named_queue_declaration?
  prefetch
  prefetch_count
  prefetch_global
  queue
  queue_bind
  queue_declare
  queue_delete
  queue_purge
  queue_unbind
  queues
  raise_if_channel_close!
  raise_if_continuation_resulted_in_a_channel_error!
  raise_if_no_longer_open!
  read_and_reset_only_acks_received
  read_next_frame
  recover
  recover_cancelled_consumers!
  recover_confirm_mode
  recover_consumers
  recover_exchanges
  recover_from_network_failure
  recover_prefetch_setting
  recover_queues
  recover_tx_mode
  recoveries_counter
  recovers_cancelled_consumers?
  register_consumer
  register_exchange
  register_queue
  reject
  release_all_continuations
  reset_continuations
  status
  synchronize
  temporary_queue
  to_s
  topic
  tx_commit
  tx_rollback
  tx_select
  unconfirmed_set
  unregister_consumer
  using_publisher_confirmations?
  using_publisher_confirms?
  using_tx?
  wait_for_confirms
  wait_on_basic_get_continuations
  wait_on_confirms_continuations
  wait_on_continuations
  wait_on_continuations_timeout
  with_continuation_timeout
  work_pool

= Attributes:

  attr_accessor id
  attr_reader connection
  attr_reader consumers
  attr_reader exchanges
  attr_reader nacked_set
  attr_reader next_publish_seq_no
  attr_reader prefetch_count
  attr_reader prefetch_global
  attr_reader queues
  attr_reader recoveries_counter
  attr_reader status
  attr_reader unconfirmed_set
  attr_reader work_pool

Bunny::Channel
Bunny::Channel < Object Constants: Class methods: Instance methods: Attributes:

Generated by phpman v4.9.26-1-g511901d · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-07-28 11:33 @216.73.217.46
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Valid XHTML 1.0 Transitional!Valid CSS!

^_top_^