Method: Bunny::Channel#basic_cancel

Defined in:
lib/bunny/channel.rb

#basic_cancel(consumer_tag, opts = {}) ⇒ AMQ::Protocol::Basic::CancelOk?

Removes a consumer. Messages for this consumer will no longer be delivered. If the queue it was on is auto-deleted and this consumer was the last one, the queue will be deleted.

Parameters:

  • consumer_tag (String)

    Consumer tag (unique identifier) to cancel

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

    ({}) Optional arguments

Options Hash (opts):

  • :no_wait (Boolean) — default: false

    if set to true, this method won't receive a response and will immediately return nil

Returns:

  • (AMQ::Protocol::Basic::CancelOk, nil)

    RabbitMQ response or nil, if the no_wait option is used

See Also:



1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
# File 'lib/bunny/channel.rb', line 1084

def basic_cancel(consumer_tag, opts = {})
  no_wait = opts.fetch(:no_wait, false)
  @connection.send_frame(AMQ::Protocol::Basic::Cancel.encode(@id, consumer_tag, no_wait))

  if no_wait
    @last_basic_cancel_ok = nil
  else
    with_continuation_timeout do
      @last_basic_cancel_ok = wait_on_continuations
    end
  end

  # reduces thread usage for channels that don't have any
  # consumers
  @work_pool.shutdown(true) unless self.any_consumers?
  self.delete_recorded_consumer(consumer_tag)

  @last_basic_cancel_ok
end