bunny 0.7.12 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. data/.gitignore +2 -2
  2. data/.travis.yml +7 -16
  3. data/CHANGELOG +3 -21
  4. data/Gemfile +2 -4
  5. data/README.textile +31 -9
  6. data/Rakefile +3 -3
  7. data/bunny.gemspec +6 -3
  8. data/examples/{simple_08.rb → simple.rb} +1 -1
  9. data/examples/{simple_ack_08.rb → simple_ack.rb} +1 -1
  10. data/examples/{simple_consumer_08.rb → simple_consumer.rb} +4 -4
  11. data/examples/{simple_fanout_08.rb → simple_fanout.rb} +1 -1
  12. data/examples/{simple_headers_08.rb → simple_headers.rb} +2 -2
  13. data/examples/{simple_publisher_09.rb → simple_publisher.rb} +1 -1
  14. data/examples/{simple_topic_09.rb → simple_topic.rb} +2 -2
  15. data/ext/amqp-0.9.1.json +1 -0
  16. data/ext/config.yml +3 -3
  17. data/ext/qparser.rb +9 -52
  18. data/lib/bunny.rb +15 -33
  19. data/lib/bunny/{channel08.rb → channel.rb} +0 -0
  20. data/lib/bunny/{client09.rb → client.rb} +34 -46
  21. data/lib/bunny/{exchange09.rb → exchange.rb} +16 -15
  22. data/lib/bunny/{queue09.rb → queue.rb} +26 -23
  23. data/lib/bunny/{subscription09.rb → subscription.rb} +11 -6
  24. data/lib/bunny/version.rb +1 -1
  25. data/lib/qrack/client.rb +30 -21
  26. data/lib/qrack/protocol/{protocol08.rb → protocol.rb} +2 -1
  27. data/lib/qrack/protocol/{spec09.rb → spec.rb} +8 -7
  28. data/lib/qrack/{qrack08.rb → qrack.rb} +4 -4
  29. data/lib/qrack/subscription.rb +58 -9
  30. data/lib/qrack/transport/{buffer08.rb → buffer.rb} +8 -0
  31. data/lib/qrack/transport/{frame08.rb → frame.rb} +7 -22
  32. data/spec/spec_09/bunny_spec.rb +10 -8
  33. data/spec/spec_09/connection_spec.rb +8 -3
  34. data/spec/spec_09/exchange_spec.rb +22 -19
  35. data/spec/spec_09/queue_spec.rb +32 -18
  36. metadata +69 -76
  37. checksums.yaml +0 -7
  38. data/examples/simple_09.rb +0 -32
  39. data/examples/simple_ack_09.rb +0 -35
  40. data/examples/simple_consumer_09.rb +0 -55
  41. data/examples/simple_fanout_09.rb +0 -41
  42. data/examples/simple_headers_09.rb +0 -42
  43. data/examples/simple_publisher_08.rb +0 -29
  44. data/examples/simple_topic_08.rb +0 -61
  45. data/ext/amqp-0.8.json +0 -616
  46. data/lib/bunny/channel09.rb +0 -39
  47. data/lib/bunny/client08.rb +0 -480
  48. data/lib/bunny/exchange08.rb +0 -177
  49. data/lib/bunny/queue08.rb +0 -403
  50. data/lib/bunny/subscription08.rb +0 -87
  51. data/lib/qrack/protocol/protocol09.rb +0 -135
  52. data/lib/qrack/protocol/spec08.rb +0 -828
  53. data/lib/qrack/qrack09.rb +0 -20
  54. data/lib/qrack/transport/buffer09.rb +0 -305
  55. data/lib/qrack/transport/frame09.rb +0 -97
  56. data/spec/spec_08/bunny_spec.rb +0 -75
  57. data/spec/spec_08/connection_spec.rb +0 -24
  58. data/spec/spec_08/exchange_spec.rb +0 -170
  59. data/spec/spec_08/queue_spec.rb +0 -239
@@ -1,24 +0,0 @@
1
- # encoding: utf-8
2
-
3
- # connection_spec.rb
4
-
5
- require File.expand_path(File.join(File.dirname(__FILE__), %w[.. .. lib bunny]))
6
-
7
- describe Bunny do
8
-
9
- it "should raise an error if the wrong user name or password is used" do
10
- b = Bunny.new(:spec => "0.8", :user => 'wrong')
11
- lambda { b.start}.should raise_error(Bunny::ProtocolError)
12
- end
13
-
14
- it "should be able to open a TCPSocket with a timeout" do
15
- b = Bunny.new(:spec => "0.8")
16
- connect_timeout = 5
17
- lambda {
18
- Bunny::Timer::timeout(connect_timeout, Qrack::ConnectionTimeout) do
19
- TCPSocket.new(b.host, b.port)
20
- end
21
- }.should_not raise_error(Exception)
22
- end
23
-
24
- end
@@ -1,170 +0,0 @@
1
- # encoding: utf-8
2
-
3
- # exchange_spec.rb
4
-
5
- # Assumes that target message broker/server has a user called 'guest' with a password 'guest'
6
- # and that it is running on 'localhost'.
7
-
8
- # If this is not the case, please change the 'Bunny.new' call below to include
9
- # the relevant arguments e.g. @b = Bunny.new(:user => 'john', :pass => 'doe', :host => 'foobar')
10
-
11
- require File.expand_path(File.join(File.dirname(__FILE__), %w[.. .. lib bunny]))
12
-
13
- describe 'Exchange' do
14
-
15
- before(:each) do
16
- @b = Bunny.new
17
- @b.start
18
- end
19
-
20
- after(:each) do
21
- begin
22
- @b.stop
23
- rescue Exception
24
- ensure
25
- @b = nil
26
- end
27
- end
28
-
29
- it "should raise an error if instantiated as non-existent type" do
30
- lambda { @b.exchange('bogus_ex', :type => :bogus) }.should raise_error(Bunny::ForcedConnectionCloseError)
31
- @b.status.should == :not_connected
32
- end
33
-
34
- it "should allow a default direct exchange to be instantiated by specifying :type" do
35
- exch = @b.exchange('amq.direct', :type => :direct)
36
- exch.should be_an_instance_of(Bunny::Exchange)
37
- exch.name.should == 'amq.direct'
38
- exch.type.should == :direct
39
- @b.exchanges.has_key?('amq.direct').should be(true)
40
- end
41
-
42
- it "should allow a default direct exchange to be instantiated without specifying :type" do
43
- exch = @b.exchange('amq.direct')
44
- exch.should be_an_instance_of(Bunny::Exchange)
45
- exch.name.should == 'amq.direct'
46
- exch.type.should == :direct
47
- @b.exchanges.has_key?('amq.direct').should be(true)
48
- end
49
-
50
- it "should allow a default fanout exchange to be instantiated without specifying :type" do
51
- exch = @b.exchange('amq.fanout')
52
- exch.should be_an_instance_of(Bunny::Exchange)
53
- exch.name.should == 'amq.fanout'
54
- exch.type.should == :fanout
55
- @b.exchanges.has_key?('amq.fanout').should be(true)
56
- end
57
-
58
- it "should allow a default topic exchange to be instantiated without specifying :type" do
59
- exch = @b.exchange('amq.topic')
60
- exch.should be_an_instance_of(Bunny::Exchange)
61
- exch.name.should == 'amq.topic'
62
- exch.type.should == :topic
63
- @b.exchanges.has_key?('amq.topic').should be(true)
64
- end
65
-
66
- it "should allow a default headers (amq.match) exchange to be instantiated without specifying :type" do
67
- exch = @b.exchange('amq.match')
68
- exch.should be_an_instance_of(Bunny::Exchange)
69
- exch.name.should == 'amq.match'
70
- exch.type.should == :headers
71
- @b.exchanges.has_key?('amq.match').should be(true)
72
- end
73
-
74
- it "should allow a default headers (amq.headers) exchange to be instantiated without specifying :type" do
75
- exch = @b.exchange('amq.headers')
76
- exch.should be_an_instance_of(Bunny::Exchange)
77
- exch.name.should == 'amq.headers'
78
- exch.type.should == :headers
79
- @b.exchanges.has_key?('amq.headers').should be(true)
80
- end
81
-
82
- it "should create an exchange as direct by default" do
83
- exch = @b.exchange('direct_defaultex')
84
- exch.should be_an_instance_of(Bunny::Exchange)
85
- exch.name.should == 'direct_defaultex'
86
- exch.type.should == :direct
87
- @b.exchanges.has_key?('direct_defaultex').should be(true)
88
- end
89
-
90
- it "should be able to be instantiated as a direct exchange" do
91
- exch = @b.exchange('direct_exchange', :type => :direct)
92
- exch.should be_an_instance_of(Bunny::Exchange)
93
- exch.name.should == 'direct_exchange'
94
- exch.type.should == :direct
95
- @b.exchanges.has_key?('direct_exchange').should be(true)
96
- end
97
-
98
- it "should be able to be instantiated as a topic exchange" do
99
- exch = @b.exchange('topic_exchange', :type => :topic)
100
- exch.should be_an_instance_of(Bunny::Exchange)
101
- exch.name.should == 'topic_exchange'
102
- exch.type.should == :topic
103
- @b.exchanges.has_key?('topic_exchange').should be(true)
104
- end
105
-
106
- it "should be able to be instantiated as a fanout exchange" do
107
- exch = @b.exchange('fanout_exchange', :type => :fanout)
108
- exch.should be_an_instance_of(Bunny::Exchange)
109
- exch.name.should == 'fanout_exchange'
110
- exch.type.should == :fanout
111
- @b.exchanges.has_key?('fanout_exchange').should be(true)
112
- end
113
-
114
- it "should be able to be instantiated as a headers exchange" do
115
- exch = @b.exchange('headers_exchange', :type => :headers)
116
- exch.should be_an_instance_of(Bunny::Exchange)
117
- exch.name.should == 'headers_exchange'
118
- exch.type.should == :headers
119
- @b.exchanges.has_key?('headers_exchange').should be(true)
120
- end
121
-
122
- it "should ignore the :nowait option when instantiated" do
123
- exch = @b.exchange('direct2_exchange', :nowait => true)
124
- end
125
-
126
- it "should be able to publish a message" do
127
- exch = @b.exchange('direct_exchange')
128
- exch.publish('This is a published message')
129
- end
130
-
131
- it "should not modify the passed options hash when publishing a message" do
132
- exch = @b.exchange('direct_exchange')
133
- opts = {:key => 'a', :persistent => true}
134
- exch.publish('', opts)
135
- opts.should == {:key => 'a', :persistent => true}
136
- end
137
-
138
- it "should be able to return an undeliverable message" do
139
- exch = @b.exchange('return_exch')
140
- exch.publish('This message should be undeliverable', :mandatory => true)
141
- ret_msg = @b.returned_message
142
- ret_msg.should be_an_instance_of(Hash)
143
- ret_msg[:payload].should == 'This message should be undeliverable'
144
- end
145
-
146
- it "should be able to handle connection close on trying to publish with immediate=true" do
147
- exch = @b.exchange('return_exch')
148
- exch.publish('This message should force a connection close', :immediate => true)
149
- lambda { @b.returned_message }.should raise_error(Bunny::ForcedConnectionCloseError)
150
- end
151
-
152
- it "should not close the connection when trying to delete a non existent exchange" do
153
- exch = @b.exchange('direct_exchange')
154
- exch.delete(:exchange => 'bogus_ex').should == :delete_ok
155
- @b.channel.active.should == true
156
- end
157
-
158
- it "should be able to be deleted" do
159
- exch = @b.exchange('direct_exchange')
160
- res = exch.delete
161
- res.should == :delete_ok
162
- @b.exchanges.has_key?('direct_exchange').should be(false)
163
- end
164
-
165
- it "should ignore the :nowait option when deleted" do
166
- exch = @b.exchange('direct2_exchange')
167
- exch.delete(:nowait => true)
168
- end
169
-
170
- end
@@ -1,239 +0,0 @@
1
- # encoding: utf-8
2
-
3
- # queue_spec.rb
4
-
5
- # Assumes that target message broker/server has a user called 'guest' with a password 'guest'
6
- # and that it is running on 'localhost'.
7
-
8
- # If this is not the case, please change the 'Bunny.new' call below to include
9
- # the relevant arguments e.g. @b = Bunny.new(:user => 'john', :pass => 'doe', :host => 'foobar')
10
-
11
- require File.expand_path(File.join(File.dirname(__FILE__), %w[.. .. lib bunny]))
12
-
13
- describe 'Queue' do
14
-
15
- def expect_deprecation_warning_for_publishing_on_queue(q, n=1)
16
- Bunny.should_receive(:deprecation_warning).with("Qrack::Queue#publish", "0.8", anything).exactly(n).times
17
- end
18
-
19
- def message_count(queue, sleep_time = 0.1)
20
- sleep sleep_time
21
- queue.message_count
22
- end
23
-
24
- before(:each) do
25
- @b = Bunny.new
26
- @b.start
27
- end
28
-
29
- after(:each) do
30
- begin
31
- @b.stop
32
- rescue Exception
33
- ensure
34
- @b = nil
35
- end
36
- end
37
-
38
- it "should ignore the :nowait option when instantiated" do
39
- q = @b.queue('test0', :nowait => true)
40
- end
41
-
42
- it "should ignore the :nowait option when binding to an exchange" do
43
- exch = @b.exchange('direct_exch')
44
- q = @b.queue('test0')
45
- q.bind(exch, :nowait => true).should == :bind_ok
46
- end
47
-
48
- it "should be able to bind to an existing exchange" do
49
- exch = @b.exchange('direct_exch')
50
- q = @b.queue('test1')
51
- q.bind(exch).should == :bind_ok
52
- end
53
-
54
- it "should ignore the :nowait option when unbinding from an exchange" do
55
- exch = @b.exchange('direct_exch')
56
- q = @b.queue('test0')
57
- q.unbind(exch, :nowait => true).should == :unbind_ok
58
- end
59
-
60
- it "should not raise an error if unbinding from a non-existent exchange" do
61
- q = @b.queue('test1')
62
- q.unbind('bogus').should == :unbind_ok
63
- @b.channel.active.should == true
64
- end
65
-
66
- it "should be able to unbind from an existing exchange" do
67
- exch = @b.exchange('direct_exch')
68
- q = @b.queue('test1')
69
- q.unbind(exch).should == :unbind_ok
70
- end
71
-
72
- it "should be able to publish a message" do
73
- q = @b.queue('test1')
74
- expect_deprecation_warning_for_publishing_on_queue(q)
75
- q.publish('This is a test message')
76
- message_count(q).should == 1
77
- end
78
-
79
- it "should be able to pop a message complete with header and delivery details" do
80
- q = @b.queue('test1')
81
- msg = q.pop()
82
- msg.should be_an_instance_of(Hash)
83
- msg[:header].should be_an_instance_of(Bunny::Protocol::Header)
84
- msg[:payload].should == 'This is a test message'
85
- msg[:delivery_details].should be_an_instance_of(Hash)
86
- message_count(q).should == 0
87
- end
88
-
89
- it "should be able to pop a message and just get the payload" do
90
- q = @b.queue('test1')
91
- expect_deprecation_warning_for_publishing_on_queue(q)
92
- q.publish('This is another test message')
93
- msg = q.pop[:payload]
94
- msg.should == 'This is another test message'
95
- message_count(q).should == 0
96
- end
97
-
98
- it "should be able to pop a message where body length exceeds max frame size" do
99
- q = @b.queue('test1')
100
- lg_msg = 'z' * 142000
101
- expect_deprecation_warning_for_publishing_on_queue(q)
102
- q.publish(lg_msg)
103
- msg = q.pop[:payload]
104
- msg.should == lg_msg
105
- end
106
-
107
- it "should be able to send and receive messages where body length is an exact multiple of frame_max minus framing bytes" do
108
- limit = @b.frame_max-8
109
- q = @b.queue('test1')
110
- lg_msg = 'a' * (5*limit)
111
- expect_deprecation_warning_for_publishing_on_queue(q)
112
- q.publish(lg_msg)
113
- msg = q.pop[:payload]
114
- msg.should == lg_msg
115
- end
116
-
117
- it "should be able call a block when popping a message" do
118
- q = @b.queue('test1')
119
- expect_deprecation_warning_for_publishing_on_queue(q)
120
- q.publish('This is another test message')
121
- q.pop { |msg| msg[:payload].should == 'This is another test message' }
122
- q.pop { |msg| msg[:payload].should == :queue_empty }
123
- end
124
-
125
- it "should raise an error if purge fails" do
126
- q = @b.queue('test1')
127
- expect_deprecation_warning_for_publishing_on_queue(q, 5)
128
- 5.times {q.publish('This is another test message')}
129
- message_count(q).should == 5
130
- lambda {q.purge(:queue => 'bogus')}.should raise_error(Bunny::ForcedChannelCloseError)
131
- end
132
-
133
- it "should be able to be purged to remove all of its messages" do
134
- q = @b.queue('test1')
135
- message_count(q).should == 5
136
- q.purge.should == :purge_ok
137
- message_count(q).should == 0
138
- end
139
-
140
- it "should return an empty message when popping an empty queue" do
141
- q = @b.queue('test1')
142
- expect_deprecation_warning_for_publishing_on_queue(q)
143
- q.publish('This is another test message')
144
- q.pop
145
- msg = q.pop[:payload]
146
- msg.should == :queue_empty
147
- end
148
-
149
- it "should stop subscription without processing messages if max specified is 0" do
150
- q = @b.queue('test1')
151
- expect_deprecation_warning_for_publishing_on_queue(q, 5)
152
- 5.times {q.publish('Yet another test message')}
153
- message_count(q).should == 5
154
- q.subscribe(:message_max => 0)
155
- message_count(q).should == 5
156
- q.purge.should == :purge_ok
157
- end
158
-
159
- it "should stop subscription after processing number of messages specified > 0" do
160
- q = @b.queue('test1')
161
- expect_deprecation_warning_for_publishing_on_queue(q, 5)
162
- 5.times {q.publish('Yet another test message')}
163
- message_count(q).should == 5
164
- q.subscribe(:message_max => 5)
165
- end
166
-
167
- it "should stop subscription after processing message_max messages < total in queue" do
168
- q = @b.queue('test1')
169
- @b.qos()
170
- expect_deprecation_warning_for_publishing_on_queue(q, 10)
171
- 10.times {q.publish('Yet another test message')}
172
- message_count(q).should == 10
173
- q.subscribe(:message_max => 5, :ack => true)
174
- message_count(q).should == 5
175
- q.purge.should == :purge_ok
176
- end
177
-
178
- it "should not close the connections when deleting a non existent queue" do
179
- q = @b.queue('test1')
180
- q.delete(:queue => 'bogus').should == :delete_ok
181
- @b.channel.active.should == true
182
- end
183
-
184
- it "should pass correct block parameters through on subscribe" do
185
- q = @b.queue('test1')
186
- expect_deprecation_warning_for_publishing_on_queue(q)
187
- q.publish("messages pop\'n")
188
-
189
- q.subscribe do |msg|
190
- msg[:header].should be_an_instance_of Qrack::Protocol::Header
191
- msg[:payload].should == "messages pop'n"
192
- msg[:delivery_details].should_not be_nil
193
-
194
- q.unsubscribe
195
- break
196
- end
197
- end
198
-
199
- it "should finish processing subscription messages if break is called in block" do
200
- q = @b.queue('test1')
201
- expect_deprecation_warning_for_publishing_on_queue(q, 6)
202
- q.publish('messages in my quezen')
203
-
204
- q.subscribe do |msg|
205
- msg[:payload].should == 'messages in my quezen'
206
- q.unsubscribe
207
- break
208
- end
209
-
210
- 5.times {|i| q.publish("#{i}")}
211
- q.subscribe do |msg|
212
- if msg[:payload] == '4'
213
- q.unsubscribe
214
- break
215
- end
216
- end
217
- end
218
-
219
- it "should be able to be deleted" do
220
- q = @b.queue('test1')
221
- res = q.delete
222
- res.should == :delete_ok
223
- @b.queues.has_key?('test1').should be(false)
224
- end
225
-
226
- it "should ignore the :nowait option when deleted" do
227
- q = @b.queue('test0')
228
- q.delete(:nowait => true)
229
- end
230
-
231
- it "should support server named queues" do
232
- q = @b.queue
233
- q.name.should_not == nil
234
-
235
- @b.queue(q.name).should == q
236
- q.delete
237
- end
238
-
239
- end