bunny 0.6.3.rc2 → 0.7

Sign up to get free protection for your applications and to get access to all the features.
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
  # queue_spec.rb
2
4
 
3
5
  # Assumes that target message broker/server has a user called 'guest' with a password 'guest'
@@ -9,144 +11,144 @@
9
11
  require File.expand_path(File.join(File.dirname(__FILE__), %w[.. .. lib bunny]))
10
12
 
11
13
  describe 'Queue' do
12
-
13
- before(:each) do
14
+
15
+ before(:each) do
14
16
  @b = Bunny.new
15
- @b.start
16
- end
17
-
18
- it "should ignore the :nowait option when instantiated" do
19
- q = @b.queue('test0', :nowait => true)
20
- end
21
-
22
- it "should ignore the :nowait option when binding to an exchange" do
23
- exch = @b.exchange('direct_exch')
24
- q = @b.queue('test0')
25
- q.bind(exch, :nowait => true).should == :bind_ok
26
- end
27
-
28
- it "should raise an error when trying to bind to a non-existent exchange" do
29
- q = @b.queue('test1')
30
- lambda {q.bind('bogus')}.should raise_error(Bunny::ForcedChannelCloseError)
31
- @b.channel.active.should == false
32
- end
33
-
34
- it "should be able to bind to an existing exchange" do
35
- exch = @b.exchange('direct_exch')
36
- q = @b.queue('test1')
37
- q.bind(exch).should == :bind_ok
38
- end
39
-
40
- it "should ignore the :nowait option when unbinding from an exchange" do
41
- exch = @b.exchange('direct_exch')
42
- q = @b.queue('test0')
43
- q.unbind(exch, :nowait => true).should == :unbind_ok
44
- end
45
-
46
- it "should raise an error if unbinding from a non-existent exchange" do
47
- q = @b.queue('test1')
48
- lambda {q.unbind('bogus')}.should raise_error(Bunny::ForcedChannelCloseError)
49
- @b.channel.active.should == false
50
- end
51
-
52
- it "should be able to unbind from an existing exchange" do
53
- exch = @b.exchange('direct_exch')
54
- q = @b.queue('test1')
55
- q.unbind(exch).should == :unbind_ok
56
- end
57
-
58
- it "should be able to publish a message" do
59
- q = @b.queue('test1')
60
- q.publish('This is a test message')
61
- q.message_count.should == 1
62
- end
63
-
64
- it "should be able to pop a message complete with header and delivery details" do
65
- q = @b.queue('test1')
66
- msg = q.pop()
67
- msg.should be_an_instance_of(Hash)
68
- msg[:header].should be_an_instance_of(Bunny::Protocol::Header)
69
- msg[:payload].should == 'This is a test message'
70
- msg[:delivery_details].should be_an_instance_of(Hash)
71
- q.message_count.should == 0
72
- end
73
-
74
- it "should be able to pop a message and just get the payload" do
75
- q = @b.queue('test1')
76
- q.publish('This is another test message')
77
- msg = q.pop[:payload]
78
- msg.should == 'This is another test message'
79
- q.message_count.should == 0
80
- end
81
-
82
- it "should be able to pop a message where body length exceeds max frame size" do
83
- q = @b.queue('test1')
84
- lg_msg = 'z' * 142000
85
- q.publish(lg_msg)
86
- msg = q.pop[:payload]
87
- msg.should == lg_msg
88
- end
89
-
90
- it "should be able call a block when popping a message" do
91
- q = @b.queue('test1')
92
- q.publish('This is another test message')
93
- q.pop { |msg| msg[:payload].should == 'This is another test message' }
94
- q.pop { |msg| msg[:payload].should == :queue_empty }
95
- end
96
-
97
- it "should raise an error if purge fails" do
98
- q = @b.queue('test1')
99
- 5.times {q.publish('This is another test message')}
100
- q.message_count.should == 5
101
- lambda {q.purge(:queue => 'bogus')}.should raise_error(Bunny::ForcedChannelCloseError)
102
- end
103
-
104
- it "should be able to be purged to remove all of its messages" do
105
- q = @b.queue('test1')
106
- q.message_count.should == 5
107
- q.purge.should == :purge_ok
108
- q.message_count.should == 0
109
- end
110
-
111
- it "should return an empty message when popping an empty queue" do
112
- q = @b.queue('test1')
113
- q.publish('This is another test message')
114
- q.pop
115
- msg = q.pop[:payload]
116
- msg.should == :queue_empty
117
- end
118
-
119
- it "should stop subscription without processing messages if max specified is 0" do
120
- q = @b.queue('test1')
121
- 5.times {q.publish('Yet another test message')}
122
- q.message_count.should == 5
123
- q.subscribe(:message_max => 0)
124
- q.message_count.should == 5
125
- q.purge.should == :purge_ok
126
- end
127
-
128
- it "should stop subscription after processing number of messages specified > 0" do
129
- q = @b.queue('test1')
130
- 5.times {q.publish('Yet another test message')}
131
- q.message_count.should == 5
132
- q.subscribe(:message_max => 5)
133
- end
134
-
135
- it "should stop subscription after processing message_max messages < total in queue" do
136
- q = @b.queue('test1')
137
- @b.qos()
138
- 10.times {q.publish('Yet another test message')}
139
- q.message_count.should == 10
140
- q.subscribe(:message_max => 5, :ack => true)
141
- q.message_count.should == 5
142
- q.purge.should == :purge_ok
143
- end
144
-
145
- it "should raise an error when delete fails" do
146
- q = @b.queue('test1')
147
- lambda {q.delete(:queue => 'bogus')}.should raise_error(Bunny::ForcedChannelCloseError)
148
- @b.channel.active.should == false
149
- end
17
+ @b.start
18
+ end
19
+
20
+ it "should ignore the :nowait option when instantiated" do
21
+ q = @b.queue('test0', :nowait => true)
22
+ end
23
+
24
+ it "should ignore the :nowait option when binding to an exchange" do
25
+ exch = @b.exchange('direct_exch')
26
+ q = @b.queue('test0')
27
+ q.bind(exch, :nowait => true).should == :bind_ok
28
+ end
29
+
30
+ it "should raise an error when trying to bind to a non-existent exchange" do
31
+ q = @b.queue('test1')
32
+ lambda {q.bind('bogus')}.should raise_error(Bunny::ForcedChannelCloseError)
33
+ @b.channel.active.should == false
34
+ end
35
+
36
+ it "should be able to bind to an existing exchange" do
37
+ exch = @b.exchange('direct_exch')
38
+ q = @b.queue('test1')
39
+ q.bind(exch).should == :bind_ok
40
+ end
41
+
42
+ it "should ignore the :nowait option when unbinding from an exchange" do
43
+ exch = @b.exchange('direct_exch')
44
+ q = @b.queue('test0')
45
+ q.unbind(exch, :nowait => true).should == :unbind_ok
46
+ end
47
+
48
+ it "should raise an error if unbinding from a non-existent exchange" do
49
+ q = @b.queue('test1')
50
+ lambda {q.unbind('bogus')}.should raise_error(Bunny::ForcedChannelCloseError)
51
+ @b.channel.active.should == false
52
+ end
53
+
54
+ it "should be able to unbind from an existing exchange" do
55
+ exch = @b.exchange('direct_exch')
56
+ q = @b.queue('test1')
57
+ q.unbind(exch).should == :unbind_ok
58
+ end
59
+
60
+ it "should be able to publish a message" do
61
+ q = @b.queue('test1')
62
+ q.publish('This is a test message')
63
+ q.message_count.should == 1
64
+ end
65
+
66
+ it "should be able to pop a message complete with header and delivery details" do
67
+ q = @b.queue('test1')
68
+ msg = q.pop()
69
+ msg.should be_an_instance_of(Hash)
70
+ msg[:header].should be_an_instance_of(Bunny::Protocol::Header)
71
+ msg[:payload].should == 'This is a test message'
72
+ msg[:delivery_details].should be_an_instance_of(Hash)
73
+ q.message_count.should == 0
74
+ end
75
+
76
+ it "should be able to pop a message and just get the payload" do
77
+ q = @b.queue('test1')
78
+ q.publish('This is another test message')
79
+ msg = q.pop[:payload]
80
+ msg.should == 'This is another test message'
81
+ q.message_count.should == 0
82
+ end
83
+
84
+ it "should be able to pop a message where body length exceeds max frame size" do
85
+ q = @b.queue('test1')
86
+ lg_msg = 'z' * 142000
87
+ q.publish(lg_msg)
88
+ msg = q.pop[:payload]
89
+ msg.should == lg_msg
90
+ end
91
+
92
+ it "should be able call a block when popping a message" do
93
+ q = @b.queue('test1')
94
+ q.publish('This is another test message')
95
+ q.pop { |msg| msg[:payload].should == 'This is another test message' }
96
+ q.pop { |msg| msg[:payload].should == :queue_empty }
97
+ end
98
+
99
+ it "should raise an error if purge fails" do
100
+ q = @b.queue('test1')
101
+ 5.times {q.publish('This is another test message')}
102
+ q.message_count.should == 5
103
+ lambda {q.purge(:queue => 'bogus')}.should raise_error(Bunny::ForcedChannelCloseError)
104
+ end
105
+
106
+ it "should be able to be purged to remove all of its messages" do
107
+ q = @b.queue('test1')
108
+ q.message_count.should == 5
109
+ q.purge.should == :purge_ok
110
+ q.message_count.should == 0
111
+ end
112
+
113
+ it "should return an empty message when popping an empty queue" do
114
+ q = @b.queue('test1')
115
+ q.publish('This is another test message')
116
+ q.pop
117
+ msg = q.pop[:payload]
118
+ msg.should == :queue_empty
119
+ end
120
+
121
+ it "should stop subscription without processing messages if max specified is 0" do
122
+ q = @b.queue('test1')
123
+ 5.times {q.publish('Yet another test message')}
124
+ q.message_count.should == 5
125
+ q.subscribe(:message_max => 0)
126
+ q.message_count.should == 5
127
+ q.purge.should == :purge_ok
128
+ end
129
+
130
+ it "should stop subscription after processing number of messages specified > 0" do
131
+ q = @b.queue('test1')
132
+ 5.times {q.publish('Yet another test message')}
133
+ q.message_count.should == 5
134
+ q.subscribe(:message_max => 5)
135
+ end
136
+
137
+ it "should stop subscription after processing message_max messages < total in queue" do
138
+ q = @b.queue('test1')
139
+ @b.qos()
140
+ 10.times {q.publish('Yet another test message')}
141
+ q.message_count.should == 10
142
+ q.subscribe(:message_max => 5, :ack => true)
143
+ q.message_count.should == 5
144
+ q.purge.should == :purge_ok
145
+ end
146
+
147
+ it "should raise an error when delete fails" do
148
+ q = @b.queue('test1')
149
+ lambda {q.delete(:queue => 'bogus')}.should raise_error(Bunny::ForcedChannelCloseError)
150
+ @b.channel.active.should == false
151
+ end
150
152
 
151
153
  it "should pass correct block parameters through on subscribe" do
152
154
  q = @b.queue('test1')
@@ -158,9 +160,8 @@ describe 'Queue' do
158
160
  msg[:delivery_details].should_not be_nil
159
161
 
160
162
  q.unsubscribe
161
- break
163
+ break
162
164
  end
163
-
164
165
  end
165
166
 
166
167
  it "should finish processing subscription messages if break is called in block" do
@@ -170,30 +171,29 @@ describe 'Queue' do
170
171
  q.subscribe do |msg|
171
172
  msg[:payload].should == 'messages in my quezen'
172
173
  q.unsubscribe
173
- break
174
+ break
174
175
  end
175
176
 
176
177
  5.times {|i| q.publish("#{i}")}
177
- q.subscribe do |msg|
178
- if msg[:payload] == '4'
179
- q.unsubscribe
180
- break
181
- end
182
- end
183
-
184
- end
185
-
186
- it "should be able to be deleted" do
187
- q = @b.queue('test1')
188
- res = q.delete
189
- res.should == :delete_ok
190
- @b.queues.has_key?('test1').should be(false)
191
- end
192
-
193
- it "should ignore the :nowait option when deleted" do
194
- q = @b.queue('test0')
195
- q.delete(:nowait => true)
196
- end
178
+ q.subscribe do |msg|
179
+ if msg[:payload] == '4'
180
+ q.unsubscribe
181
+ break
182
+ end
183
+ end
184
+ end
185
+
186
+ it "should be able to be deleted" do
187
+ q = @b.queue('test1')
188
+ res = q.delete
189
+ res.should == :delete_ok
190
+ @b.queues.has_key?('test1').should be(false)
191
+ end
192
+
193
+ it "should ignore the :nowait option when deleted" do
194
+ q = @b.queue('test0')
195
+ q.delete(:nowait => true)
196
+ end
197
197
 
198
198
  it "should support server named queues" do
199
199
  q = @b.queue
@@ -202,5 +202,5 @@ describe 'Queue' do
202
202
  @b.queue(q.name).should == q
203
203
  q.delete
204
204
  end
205
-
205
+
206
206
  end
@@ -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'
@@ -6,60 +8,60 @@
6
8
  # If this is not the case, please change the 'Bunny.new' call below to include
7
9
  # the relevant arguments e.g. @b = Bunny.new(:user => 'john', :pass => 'doe', :host => 'foobar')
8
10
 
9
- require File.expand_path(File.join(File.dirname(__FILE__), %w[.. .. lib bunny]))
11
+ require "bunny"
10
12
 
11
13
  describe Bunny do
12
-
13
- before(:each) do
14
+
15
+ before(:each) do
14
16
  @b = Bunny.new(:spec => '09')
15
- @b.start
16
- end
17
-
17
+ @b.start
18
+ end
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::Channel09)
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
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::Channel09)
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
40
42
 
41
- it "should be able to create an exchange" do
42
- exch = @b.exchange('test_exchange')
43
- exch.should be_an_instance_of(Bunny::Exchange09)
44
- exch.name.should == 'test_exchange'
45
- @b.exchanges.has_key?('test_exchange').should be(true)
46
- end
43
+ it "should be able to create an exchange" do
44
+ exch = @b.exchange('test_exchange')
45
+ exch.should be_an_instance_of(Bunny::Exchange09)
46
+ exch.name.should == 'test_exchange'
47
+ @b.exchanges.has_key?('test_exchange').should be(true)
48
+ end
47
49
 
48
- it "should be able to create a queue" do
49
- q = @b.queue('test1')
50
- q.should be_an_instance_of(Bunny::Queue09)
51
- q.name.should == 'test1'
52
- @b.queues.has_key?('test1').should be(true)
50
+ it "should be able to create a queue" do
51
+ q = @b.queue('test1')
52
+ q.should be_an_instance_of(Bunny::Queue09)
53
+ q.name.should == 'test1'
54
+ @b.queues.has_key?('test1').should be(true)
53
55
  end
54
56
 
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
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
60
62
 
61
- it "should be able to set QoS" do
62
- @b.qos.should == :qos_ok
63
- end
63
+ it "should be able to set QoS" do
64
+ @b.qos.should == :qos_ok
65
+ end
64
66
 
65
- end
67
+ end