Module: Bunny

Defined in:
lib/bunny.rb,
lib/bunny/queue08.rb,
lib/bunny/queue09.rb,
lib/bunny/version.rb,
lib/bunny/client08.rb,
lib/bunny/client09.rb,
lib/bunny/consumer.rb,
lib/bunny/channel08.rb,
lib/bunny/channel09.rb,
lib/bunny/exchange08.rb,
lib/bunny/exchange09.rb,
lib/bunny/system_timer.rb,
lib/bunny/subscription08.rb,
lib/bunny/subscription09.rb

Overview

NOTE: This file is rather a temporary hack to fix https://github.com/ruby-amqp/bunny/issues/9 then some permanent solution. It’s mostly copied from the AMQP and AMQ Client gems. Later on we should use AMQ Client directly and just inherit from the AMQ::Client::Sync::Consumer class.

Defined Under Namespace

Classes: AcknowledgementError, Channel, Channel09, Client, Client09, ConnectionError, Consumer, Exchange, Exchange09, ForcedChannelCloseError, ForcedConnectionCloseError, MessageError, ProtocolError, Queue, Queue09, ServerDownError, Subscription, Subscription09, SystemTimer, UnsubscribeError

Constant Summary collapse

Timer =
if RUBY_VERSION < "1.9"
  begin
    require File.expand_path(File.join(File.dirname(__FILE__), 'system_timer.rb'))
    Bunny::SystemTimer
  rescue LoadError
    Timeout
  end
else
  Timeout
end
VERSION =
"0.0.1"

Class Method Summary collapse

Class Method Details

.deprecation_warning(method, version, explanation) ⇒ Object

Print deprecation warning.



30
31
32
# File 'lib/bunny.rb', line 30

def self.deprecation_warning(method, version, explanation)
  warn "~ #{method} will be removed in Bunny #{version}. #{explanation}"
end

.new(connection_string_or_opts = Hash.new, opts = Hash.new) ⇒ Object

Instantiates new Bunny::Client



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/bunny.rb', line 36

def self.new(connection_string_or_opts = Hash.new, opts = Hash.new)
  # Set up Bunny according to AMQP spec version required
  if connection_string_or_opts.respond_to?(:keys) && opts.empty?
    opts = connection_string_or_opts
  end

  spec_version = opts[:spec] || '08'

  # Return client
  setup(spec_version, connection_string_or_opts, opts)
end

.run(opts = {}, &block) ⇒ Object

Runs a code block using a short-lived connection

Raises:

  • (ArgumentError)


50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/bunny.rb', line 50

def self.run(opts = {}, &block)
  raise ArgumentError, 'Bunny#run requires a block' unless block

  # Set up Bunny according to AMQP spec version required
  spec_version = opts[:spec] || '08'
  client = setup(spec_version, opts)

  begin
    client.start
    block.call(client)
  ensure
    client.stop
  end

  # Return success
  :run_ok
end

.versionObject

Returns the Bunny version number



25
26
27
# File 'lib/bunny.rb', line 25

def self.version
  VERSION
end