Sha256: 74d866d31167a3c37ef4067bbe7364ad6ba7b1641bd43f949e5c03e4b29185f2

Contents?: true

Size: 1.4 KB

Versions: 1

Compression:

Stored size: 1.4 KB

Contents

$:.unshift File.expand_path(File.dirname(__FILE__))

# Ruby standard libraries
%w[socket thread timeout logger].each do |file|
	require file
end

module Bunny

	class ProtocolError < StandardError; end
	class ServerDownError < StandardError; end
	class ConnectionError < StandardError; end
	class MessageError < StandardError; end
	
	VERSION = '0.4.3'
	
	# Returns the Bunny version number

	def self.version
		VERSION
	end
	
	# Instantiates new Bunny::Client

	def self.new(opts = {})
		# Set up Bunny according to AMQP spec version required
		spec_version = opts[:spec] || '08'
		setup(spec_version)
		
		Bunny::Client.new(opts)
	end
	
	# Runs a code block using a short-lived connection

  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'
		setup(spec_version)
		
    client = Bunny::Client.new(opts)
    client.start

    block.call(client)

    client.stop

		# Return success
		:run_ok
  end

	private
	
	def self.setup(version)

		if version == '08'
			# AMQP 0-8 specification
			require 'qrack/qrack08'
			require 'bunny/client08'
			require 'bunny/exchange08'
			require 'bunny/queue08'
		else
			# AMQP 0-9-1 specification
			require 'qrack/qrack091'
			require 'bunny/client091'
			require 'bunny/exchange091'
			require 'bunny/queue091'
		end			
		
		include Qrack
	end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
celldee-bunny-0.4.4 lib/bunny.rb