bunny 0.6.3.rc2 → 0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. data/.gitignore +8 -0
  2. data/.rspec +3 -0
  3. data/.travis.yml +15 -0
  4. data/.yardopts +9 -0
  5. data/CHANGELOG +3 -0
  6. data/Gemfile +39 -0
  7. data/Gemfile.lock +34 -0
  8. data/LICENSE +5 -4
  9. data/README.textile +54 -0
  10. data/Rakefile +15 -13
  11. data/bunny.gemspec +42 -61
  12. data/examples/simple_08.rb +4 -2
  13. data/examples/simple_09.rb +4 -2
  14. data/examples/simple_ack_08.rb +3 -1
  15. data/examples/simple_ack_09.rb +3 -1
  16. data/examples/simple_consumer_08.rb +4 -2
  17. data/examples/simple_consumer_09.rb +4 -2
  18. data/examples/simple_fanout_08.rb +3 -1
  19. data/examples/simple_fanout_09.rb +3 -1
  20. data/examples/simple_headers_08.rb +5 -3
  21. data/examples/simple_headers_09.rb +5 -3
  22. data/examples/simple_publisher_08.rb +3 -1
  23. data/examples/simple_publisher_09.rb +3 -1
  24. data/examples/simple_topic_08.rb +5 -3
  25. data/examples/simple_topic_09.rb +5 -3
  26. data/ext/amqp-0.8.json +616 -0
  27. data/ext/amqp-0.9.1.json +388 -0
  28. data/ext/config.yml +4 -0
  29. data/ext/qparser.rb +463 -0
  30. data/lib/bunny.rb +88 -66
  31. data/lib/bunny/channel08.rb +38 -38
  32. data/lib/bunny/channel09.rb +37 -37
  33. data/lib/bunny/client08.rb +184 -206
  34. data/lib/bunny/client09.rb +277 -363
  35. data/lib/bunny/consumer.rb +35 -0
  36. data/lib/bunny/exchange08.rb +37 -41
  37. data/lib/bunny/exchange09.rb +106 -124
  38. data/lib/bunny/queue08.rb +216 -202
  39. data/lib/bunny/queue09.rb +256 -326
  40. data/lib/bunny/subscription08.rb +30 -29
  41. data/lib/bunny/subscription09.rb +84 -83
  42. data/lib/bunny/version.rb +5 -0
  43. data/lib/qrack/amq-client-url.rb +165 -0
  44. data/lib/qrack/channel.rb +19 -17
  45. data/lib/qrack/client.rb +152 -151
  46. data/lib/qrack/errors.rb +5 -0
  47. data/lib/qrack/protocol/protocol08.rb +132 -130
  48. data/lib/qrack/protocol/protocol09.rb +133 -131
  49. data/lib/qrack/protocol/spec08.rb +2 -0
  50. data/lib/qrack/protocol/spec09.rb +2 -0
  51. data/lib/qrack/qrack08.rb +7 -10
  52. data/lib/qrack/qrack09.rb +7 -10
  53. data/lib/qrack/queue.rb +27 -40
  54. data/lib/qrack/subscription.rb +102 -101
  55. data/lib/qrack/transport/buffer08.rb +266 -264
  56. data/lib/qrack/transport/buffer09.rb +268 -264
  57. data/lib/qrack/transport/frame08.rb +13 -11
  58. data/lib/qrack/transport/frame09.rb +9 -7
  59. data/spec/spec_08/bunny_spec.rb +48 -45
  60. data/spec/spec_08/connection_spec.rb +10 -7
  61. data/spec/spec_08/exchange_spec.rb +145 -143
  62. data/spec/spec_08/queue_spec.rb +161 -161
  63. data/spec/spec_09/bunny_spec.rb +46 -44
  64. data/spec/spec_09/connection_spec.rb +15 -8
  65. data/spec/spec_09/exchange_spec.rb +147 -145
  66. data/spec/spec_09/queue_spec.rb +182 -184
  67. metadata +60 -41
  68. data/README.rdoc +0 -66
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
 
2
4
  #:stopdoc:
3
5
  # this file was autogenerated on 2009-12-13 13:40:20 +0000
@@ -12,15 +14,15 @@ module Qrack
12
14
  ID = 0
13
15
 
14
16
  @types = {
15
- 1 => 'Method',
16
- 2 => 'Header',
17
- 3 => 'Body',
18
- 4 => 'OobMethod',
19
- 5 => 'OobHeader',
20
- 6 => 'OobBody',
21
- 7 => 'Trace',
22
- 8 => 'Heartbeat',
23
- }
17
+ 1 => 'Method',
18
+ 2 => 'Header',
19
+ 3 => 'Body',
20
+ 4 => 'OobMethod',
21
+ 5 => 'OobHeader',
22
+ 6 => 'OobBody',
23
+ 7 => 'Trace',
24
+ 8 => 'Heartbeat',
25
+ }
24
26
 
25
27
  attr_accessor :channel, :payload
26
28
 
@@ -63,9 +65,9 @@ module Qrack
63
65
  end
64
66
 
65
67
  class Method < Frame
66
-
68
+
67
69
  ID = 1
68
-
70
+
69
71
  def initialize payload = nil, channel = 0
70
72
  super
71
73
  unless @payload.is_a? Protocol::Class::Method or @payload.nil?
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
 
2
4
  #:stopdoc:
3
5
  # this file was autogenerated on 2009-12-13 13:38:22 +0000
@@ -12,11 +14,11 @@ module Qrack
12
14
  ID = 0
13
15
 
14
16
  @types = {
15
- 1 => 'Method',
16
- 2 => 'Header',
17
- 3 => 'Body',
18
- 8 => 'Heartbeat',
19
- }
17
+ 1 => 'Method',
18
+ 2 => 'Header',
19
+ 3 => 'Body',
20
+ 8 => 'Heartbeat',
21
+ }
20
22
 
21
23
  attr_accessor :channel, :payload
22
24
 
@@ -59,9 +61,9 @@ module Qrack
59
61
  end
60
62
 
61
63
  class Method < Frame
62
-
64
+
63
65
  ID = 1
64
-
66
+
65
67
  def initialize payload = nil, channel = 0
66
68
  super
67
69
  unless @payload.is_a? Protocol09::Class::Method or @payload.nil?
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  # bunny_spec.rb
2
4
 
3
5
  # Assumes that target message broker/server has a user called 'guest' with a password 'guest'
@@ -10,56 +12,57 @@ require File.expand_path(File.join(File.dirname(__FILE__), %w[.. .. lib bunny]))
10
12
 
11
13
  describe Bunny do
12
14
 
13
- before(:each) do
15
+ before(:each) do
14
16
  @b = Bunny.new
15
- @b.start
16
- end
17
+ @b.start
18
+ end
17
19
 
18
20
  it "should connect to an AMQP server" do
19
21
  @b.status.should == :connected
20
22
  end
21
23
 
22
- it "should be able to create and open a new channel" do
23
- c = @b.create_channel
24
- c.number.should == 2
25
- c.should be_an_instance_of(Bunny::Channel)
26
- @b.channels.size.should == 3
27
- c.open.should == :open_ok
28
- @b.channel.number.should == 2
29
- end
30
-
31
- it "should be able to switch between channels" do
32
- @b.channel.number.should == 1
33
- @b.switch_channel(0)
34
- @b.channel.number.should == 0
35
- end
36
-
37
- it "should raise an error if trying to switch to a non-existent channel" do
38
- lambda { @b.switch_channel(5)}.should raise_error(RuntimeError)
39
- end
40
-
41
- it "should be able to create an exchange" do
42
- exch = @b.exchange('test_exchange')
43
- exch.should be_an_instance_of(Bunny::Exchange)
44
- exch.name.should == 'test_exchange'
45
- @b.exchanges.has_key?('test_exchange').should be(true)
46
- end
47
-
48
- it "should be able to create a queue" do
49
- q = @b.queue('test1')
50
- q.should be_an_instance_of(Bunny::Queue)
51
- q.name.should == 'test1'
52
- @b.queues.has_key?('test1').should be(true)
24
+ it "should be able to create and open a new channel" do
25
+ c = @b.create_channel
26
+ c.number.should == 2
27
+ c.should be_an_instance_of(Bunny::Channel)
28
+ @b.channels.size.should == 3
29
+ c.open.should == :open_ok
30
+ @b.channel.number.should == 2
31
+ end
32
+
33
+ it "should be able to switch between channels" do
34
+ @b.channel.number.should == 1
35
+ @b.switch_channel(0)
36
+ @b.channel.number.should == 0
37
+ end
38
+
39
+ it "should raise an error if trying to switch to a non-existent channel" do
40
+ lambda { @b.switch_channel(5)}.should raise_error(RuntimeError)
41
+ end
42
+
43
+ it "should be able to create an exchange" do
44
+ exch = @b.exchange('test_exchange')
45
+ exch.should be_an_instance_of(Bunny::Exchange)
46
+ exch.name.should == 'test_exchange'
47
+ @b.exchanges.has_key?('test_exchange').should be(true)
53
48
  end
54
49
 
55
- # Current RabbitMQ has not implemented some functionality
56
- it "should raise an error if setting of QoS fails" do
57
- lambda { @b.qos(:global => true) }.should raise_error(Bunny::ForcedConnectionCloseError)
58
- @b.status.should == :not_connected
59
- end
60
-
61
- it "should be able to set QoS" do
62
- @b.qos.should == :qos_ok
63
- end
64
-
65
- end
50
+ it "should be able to create a queue" do
51
+ q = @b.queue('test1')
52
+ q.should be_an_instance_of(Bunny::Queue)
53
+ q.name.should == 'test1'
54
+ @b.queues.has_key?('test1').should be(true)
55
+ end
56
+
57
+ # Current RabbitMQ has not implemented some functionality
58
+ it "should raise an error if setting of QoS fails" do
59
+ lambda { @b.qos(:global => true) }.should raise_error(Bunny::ForcedConnectionCloseError)
60
+ @b.status.should == :not_connected
61
+ end
62
+
63
+ it "should be able to set QoS" do
64
+ @b.qos.should == :qos_ok
65
+ end
66
+
67
+ end
68
+
@@ -1,12 +1,15 @@
1
+ # encoding: utf-8
2
+
1
3
  # connection_spec.rb
2
4
 
3
5
  require File.expand_path(File.join(File.dirname(__FILE__), %w[.. .. lib bunny]))
4
6
 
5
7
  describe Bunny do
6
-
7
- it "should raise an error if the wrong user name or password is used" do
8
- b = Bunny.new(:user => 'wrong')
9
- lambda { b.start}.should raise_error(Bunny::ProtocolError)
10
- end
11
-
12
- end
8
+
9
+ it "should raise an error if the wrong user name or password is used" do
10
+ b = Bunny.new(:user => 'wrong')
11
+ lambda { b.start}.should raise_error(Bunny::ProtocolError)
12
+ end
13
+
14
+ end
15
+
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  # exchange_spec.rb
2
4
 
3
5
  # Assumes that target message broker/server has a user called 'guest' with a password 'guest'
@@ -10,153 +12,153 @@ require File.expand_path(File.join(File.dirname(__FILE__), %w[.. .. lib bunny]))
10
12
 
11
13
  describe 'Exchange' do
12
14
 
13
- before(:each) do
15
+ before(:each) do
14
16
  @b = Bunny.new
15
- @b.start
16
- end
17
-
18
- it "should raise an error if instantiated as non-existent type" do
19
- lambda { @b.exchange('bogus_ex', :type => :bogus) }.should raise_error(Bunny::ForcedConnectionCloseError)
20
- @b.status.should == :not_connected
21
- end
22
-
23
- it "should allow a default direct exchange to be instantiated by specifying :type" do
24
- exch = @b.exchange('amq.direct', :type => :direct)
25
- exch.should be_an_instance_of(Bunny::Exchange)
26
- exch.name.should == 'amq.direct'
27
- exch.type.should == :direct
28
- @b.exchanges.has_key?('amq.direct').should be(true)
29
- end
30
-
31
- it "should allow a default direct exchange to be instantiated without specifying :type" do
32
- exch = @b.exchange('amq.direct')
33
- exch.should be_an_instance_of(Bunny::Exchange)
34
- exch.name.should == 'amq.direct'
35
- exch.type.should == :direct
36
- @b.exchanges.has_key?('amq.direct').should be(true)
37
- end
38
-
39
- it "should allow a default fanout exchange to be instantiated without specifying :type" do
40
- exch = @b.exchange('amq.fanout')
41
- exch.should be_an_instance_of(Bunny::Exchange)
42
- exch.name.should == 'amq.fanout'
43
- exch.type.should == :fanout
44
- @b.exchanges.has_key?('amq.fanout').should be(true)
45
- end
46
-
47
- it "should allow a default topic exchange to be instantiated without specifying :type" do
48
- exch = @b.exchange('amq.topic')
49
- exch.should be_an_instance_of(Bunny::Exchange)
50
- exch.name.should == 'amq.topic'
51
- exch.type.should == :topic
52
- @b.exchanges.has_key?('amq.topic').should be(true)
53
- end
54
-
55
- it "should allow a default headers (amq.match) exchange to be instantiated without specifying :type" do
56
- exch = @b.exchange('amq.match')
57
- exch.should be_an_instance_of(Bunny::Exchange)
58
- exch.name.should == 'amq.match'
59
- exch.type.should == :headers
60
- @b.exchanges.has_key?('amq.match').should be(true)
61
- end
62
-
63
- it "should allow a default headers (amq.headers) exchange to be instantiated without specifying :type" do
64
- exch = @b.exchange('amq.headers')
65
- exch.should be_an_instance_of(Bunny::Exchange)
66
- exch.name.should == 'amq.headers'
67
- exch.type.should == :headers
68
- @b.exchanges.has_key?('amq.headers').should be(true)
69
- end
70
-
71
- it "should create an exchange as direct by default" do
72
- exch = @b.exchange('direct_defaultex')
73
- exch.should be_an_instance_of(Bunny::Exchange)
74
- exch.name.should == 'direct_defaultex'
75
- exch.type.should == :direct
76
- @b.exchanges.has_key?('direct_defaultex').should be(true)
77
- end
78
-
79
- it "should be able to be instantiated as a direct exchange" do
80
- exch = @b.exchange('direct_exchange', :type => :direct)
81
- exch.should be_an_instance_of(Bunny::Exchange)
82
- exch.name.should == 'direct_exchange'
83
- exch.type.should == :direct
84
- @b.exchanges.has_key?('direct_exchange').should be(true)
85
- end
86
-
87
- it "should be able to be instantiated as a topic exchange" do
88
- exch = @b.exchange('topic_exchange', :type => :topic)
89
- exch.should be_an_instance_of(Bunny::Exchange)
90
- exch.name.should == 'topic_exchange'
91
- exch.type.should == :topic
92
- @b.exchanges.has_key?('topic_exchange').should be(true)
93
- end
94
-
95
- it "should be able to be instantiated as a fanout exchange" do
96
- exch = @b.exchange('fanout_exchange', :type => :fanout)
97
- exch.should be_an_instance_of(Bunny::Exchange)
98
- exch.name.should == 'fanout_exchange'
99
- exch.type.should == :fanout
100
- @b.exchanges.has_key?('fanout_exchange').should be(true)
101
- end
102
-
103
- it "should be able to be instantiated as a headers exchange" do
104
- exch = @b.exchange('headers_exchange', :type => :headers)
105
- exch.should be_an_instance_of(Bunny::Exchange)
106
- exch.name.should == 'headers_exchange'
107
- exch.type.should == :headers
108
- @b.exchanges.has_key?('headers_exchange').should be(true)
109
- end
110
-
111
- it "should ignore the :nowait option when instantiated" do
112
- exch = @b.exchange('direct2_exchange', :nowait => true)
113
- end
114
-
115
- it "should be able to publish a message" do
116
- exch = @b.exchange('direct_exchange')
117
- exch.publish('This is a published message')
118
- end
17
+ @b.start
18
+ end
19
+
20
+ it "should raise an error if instantiated as non-existent type" do
21
+ lambda { @b.exchange('bogus_ex', :type => :bogus) }.should raise_error(Bunny::ForcedConnectionCloseError)
22
+ @b.status.should == :not_connected
23
+ end
24
+
25
+ it "should allow a default direct exchange to be instantiated by specifying :type" do
26
+ exch = @b.exchange('amq.direct', :type => :direct)
27
+ exch.should be_an_instance_of(Bunny::Exchange)
28
+ exch.name.should == 'amq.direct'
29
+ exch.type.should == :direct
30
+ @b.exchanges.has_key?('amq.direct').should be(true)
31
+ end
32
+
33
+ it "should allow a default direct exchange to be instantiated without specifying :type" do
34
+ exch = @b.exchange('amq.direct')
35
+ exch.should be_an_instance_of(Bunny::Exchange)
36
+ exch.name.should == 'amq.direct'
37
+ exch.type.should == :direct
38
+ @b.exchanges.has_key?('amq.direct').should be(true)
39
+ end
40
+
41
+ it "should allow a default fanout exchange to be instantiated without specifying :type" do
42
+ exch = @b.exchange('amq.fanout')
43
+ exch.should be_an_instance_of(Bunny::Exchange)
44
+ exch.name.should == 'amq.fanout'
45
+ exch.type.should == :fanout
46
+ @b.exchanges.has_key?('amq.fanout').should be(true)
47
+ end
48
+
49
+ it "should allow a default topic exchange to be instantiated without specifying :type" do
50
+ exch = @b.exchange('amq.topic')
51
+ exch.should be_an_instance_of(Bunny::Exchange)
52
+ exch.name.should == 'amq.topic'
53
+ exch.type.should == :topic
54
+ @b.exchanges.has_key?('amq.topic').should be(true)
55
+ end
56
+
57
+ it "should allow a default headers (amq.match) exchange to be instantiated without specifying :type" do
58
+ exch = @b.exchange('amq.match')
59
+ exch.should be_an_instance_of(Bunny::Exchange)
60
+ exch.name.should == 'amq.match'
61
+ exch.type.should == :headers
62
+ @b.exchanges.has_key?('amq.match').should be(true)
63
+ end
64
+
65
+ it "should allow a default headers (amq.headers) exchange to be instantiated without specifying :type" do
66
+ exch = @b.exchange('amq.headers')
67
+ exch.should be_an_instance_of(Bunny::Exchange)
68
+ exch.name.should == 'amq.headers'
69
+ exch.type.should == :headers
70
+ @b.exchanges.has_key?('amq.headers').should be(true)
71
+ end
72
+
73
+ it "should create an exchange as direct by default" do
74
+ exch = @b.exchange('direct_defaultex')
75
+ exch.should be_an_instance_of(Bunny::Exchange)
76
+ exch.name.should == 'direct_defaultex'
77
+ exch.type.should == :direct
78
+ @b.exchanges.has_key?('direct_defaultex').should be(true)
79
+ end
80
+
81
+ it "should be able to be instantiated as a direct exchange" do
82
+ exch = @b.exchange('direct_exchange', :type => :direct)
83
+ exch.should be_an_instance_of(Bunny::Exchange)
84
+ exch.name.should == 'direct_exchange'
85
+ exch.type.should == :direct
86
+ @b.exchanges.has_key?('direct_exchange').should be(true)
87
+ end
88
+
89
+ it "should be able to be instantiated as a topic exchange" do
90
+ exch = @b.exchange('topic_exchange', :type => :topic)
91
+ exch.should be_an_instance_of(Bunny::Exchange)
92
+ exch.name.should == 'topic_exchange'
93
+ exch.type.should == :topic
94
+ @b.exchanges.has_key?('topic_exchange').should be(true)
95
+ end
96
+
97
+ it "should be able to be instantiated as a fanout exchange" do
98
+ exch = @b.exchange('fanout_exchange', :type => :fanout)
99
+ exch.should be_an_instance_of(Bunny::Exchange)
100
+ exch.name.should == 'fanout_exchange'
101
+ exch.type.should == :fanout
102
+ @b.exchanges.has_key?('fanout_exchange').should be(true)
103
+ end
104
+
105
+ it "should be able to be instantiated as a headers exchange" do
106
+ exch = @b.exchange('headers_exchange', :type => :headers)
107
+ exch.should be_an_instance_of(Bunny::Exchange)
108
+ exch.name.should == 'headers_exchange'
109
+ exch.type.should == :headers
110
+ @b.exchanges.has_key?('headers_exchange').should be(true)
111
+ end
112
+
113
+ it "should ignore the :nowait option when instantiated" do
114
+ exch = @b.exchange('direct2_exchange', :nowait => true)
115
+ end
116
+
117
+ it "should be able to publish a message" do
118
+ exch = @b.exchange('direct_exchange')
119
+ exch.publish('This is a published message')
120
+ end
119
121
 
120
122
  it "should not modify the passed options hash when publishing a message" do
121
- exch = @b.exchange('direct_exchange')
123
+ exch = @b.exchange('direct_exchange')
122
124
  opts = {:key => 'a', :persistent => true}
123
- exch.publish('', opts)
125
+ exch.publish('', opts)
124
126
  opts.should == {:key => 'a', :persistent => true}
125
127
  end
126
-
127
- it "should be able to return an undeliverable message" do
128
- exch = @b.exchange('return_exch')
129
- exch.publish('This message should be undeliverable', :immediate => true)
130
- ret_msg = @b.returned_message
131
- ret_msg.should be_an_instance_of(Hash)
132
- ret_msg[:payload].should == 'This message should be undeliverable'
133
- end
134
-
135
- it "should be able to return a message that exceeds maximum frame size" do
136
- exch = @b.exchange('return_exch')
137
- lg_msg = 'z' * 142000
138
- exch.publish(lg_msg, :immediate => true)
139
- ret_msg = @b.returned_message
140
- ret_msg.should be_an_instance_of(Hash)
141
- ret_msg[:payload].should == lg_msg
142
- end
143
-
144
- it "should report an error if delete fails" do
145
- exch = @b.exchange('direct_exchange')
146
- lambda { exch.delete(:exchange => 'bogus_ex') }.should raise_error(Bunny::ForcedChannelCloseError)
147
- @b.channel.active.should == false
148
- end
149
-
150
- it "should be able to be deleted" do
151
- exch = @b.exchange('direct_exchange')
152
- res = exch.delete
153
- res.should == :delete_ok
154
- @b.exchanges.has_key?('direct_exchange').should be(false)
155
- end
156
-
157
- it "should ignore the :nowait option when deleted" do
158
- exch = @b.exchange('direct2_exchange')
159
- exch.delete(:nowait => true)
160
- end
161
-
128
+
129
+ it "should be able to return an undeliverable message" do
130
+ exch = @b.exchange('return_exch')
131
+ exch.publish('This message should be undeliverable', :immediate => true)
132
+ ret_msg = @b.returned_message
133
+ ret_msg.should be_an_instance_of(Hash)
134
+ ret_msg[:payload].should == 'This message should be undeliverable'
135
+ end
136
+
137
+ it "should be able to return a message that exceeds maximum frame size" do
138
+ exch = @b.exchange('return_exch')
139
+ lg_msg = 'z' * 142000
140
+ exch.publish(lg_msg, :immediate => true)
141
+ ret_msg = @b.returned_message
142
+ ret_msg.should be_an_instance_of(Hash)
143
+ ret_msg[:payload].should == lg_msg
144
+ end
145
+
146
+ it "should report an error if delete fails" do
147
+ exch = @b.exchange('direct_exchange')
148
+ lambda { exch.delete(:exchange => 'bogus_ex') }.should raise_error(Bunny::ForcedChannelCloseError)
149
+ @b.channel.active.should == false
150
+ end
151
+
152
+ it "should be able to be deleted" do
153
+ exch = @b.exchange('direct_exchange')
154
+ res = exch.delete
155
+ res.should == :delete_ok
156
+ @b.exchanges.has_key?('direct_exchange').should be(false)
157
+ end
158
+
159
+ it "should ignore the :nowait option when deleted" do
160
+ exch = @b.exchange('direct2_exchange')
161
+ exch.delete(:nowait => true)
162
+ end
163
+
162
164
  end