| VERSION | = | '0.6.0' |
Instantiates new Bunny::Client
# File lib/bunny.rb, line 29
29: def self.new(opts = {})
30: # Set up Bunny according to AMQP spec version required
31: spec_version = opts[:spec] || '08'
32:
33: # Return client
34: setup(spec_version, opts)
35: end
Runs a code block using a short-lived connection
# File lib/bunny.rb, line 39
39: def self.run(opts = {}, &block)
40: raise ArgumentError, 'Bunny#run requires a block' unless block
41:
42: # Set up Bunny according to AMQP spec version required
43: spec_version = opts[:spec] || '08'
44: client = setup(spec_version, opts)
45:
46: begin
47: client.start
48: block.call(client)
49: ensure
50: client.stop
51: end
52:
53: # Return success
54: :run_ok
55: end
# File lib/bunny.rb, line 59
59: def self.setup(version, opts)
60: if version == '08'
61: # AMQP 0-8 specification
62: require 'qrack/qrack08'
63: require 'bunny/client08'
64: require 'bunny/exchange08'
65: require 'bunny/queue08'
66: require 'bunny/channel08'
67: require 'bunny/subscription08'
68:
69: client = Bunny::Client.new(opts)
70: else
71: # AMQP 0-9-1 specification
72: require 'qrack/qrack09'
73: require 'bunny/client09'
74: require 'bunny/exchange09'
75: require 'bunny/queue09'
76: require 'bunny/channel09'
77: require 'bunny/subscription09'
78:
79: client = Bunny::Client09.new(opts)
80: end
81:
82: include Qrack
83:
84: client
85: end