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.
- data/.gitignore +8 -0
- data/.rspec +3 -0
- data/.travis.yml +15 -0
- data/.yardopts +9 -0
- data/CHANGELOG +3 -0
- data/Gemfile +39 -0
- data/Gemfile.lock +34 -0
- data/LICENSE +5 -4
- data/README.textile +54 -0
- data/Rakefile +15 -13
- data/bunny.gemspec +42 -61
- data/examples/simple_08.rb +4 -2
- data/examples/simple_09.rb +4 -2
- data/examples/simple_ack_08.rb +3 -1
- data/examples/simple_ack_09.rb +3 -1
- data/examples/simple_consumer_08.rb +4 -2
- data/examples/simple_consumer_09.rb +4 -2
- data/examples/simple_fanout_08.rb +3 -1
- data/examples/simple_fanout_09.rb +3 -1
- data/examples/simple_headers_08.rb +5 -3
- data/examples/simple_headers_09.rb +5 -3
- data/examples/simple_publisher_08.rb +3 -1
- data/examples/simple_publisher_09.rb +3 -1
- data/examples/simple_topic_08.rb +5 -3
- data/examples/simple_topic_09.rb +5 -3
- data/ext/amqp-0.8.json +616 -0
- data/ext/amqp-0.9.1.json +388 -0
- data/ext/config.yml +4 -0
- data/ext/qparser.rb +463 -0
- data/lib/bunny.rb +88 -66
- data/lib/bunny/channel08.rb +38 -38
- data/lib/bunny/channel09.rb +37 -37
- data/lib/bunny/client08.rb +184 -206
- data/lib/bunny/client09.rb +277 -363
- data/lib/bunny/consumer.rb +35 -0
- data/lib/bunny/exchange08.rb +37 -41
- data/lib/bunny/exchange09.rb +106 -124
- data/lib/bunny/queue08.rb +216 -202
- data/lib/bunny/queue09.rb +256 -326
- data/lib/bunny/subscription08.rb +30 -29
- data/lib/bunny/subscription09.rb +84 -83
- data/lib/bunny/version.rb +5 -0
- data/lib/qrack/amq-client-url.rb +165 -0
- data/lib/qrack/channel.rb +19 -17
- data/lib/qrack/client.rb +152 -151
- data/lib/qrack/errors.rb +5 -0
- data/lib/qrack/protocol/protocol08.rb +132 -130
- data/lib/qrack/protocol/protocol09.rb +133 -131
- data/lib/qrack/protocol/spec08.rb +2 -0
- data/lib/qrack/protocol/spec09.rb +2 -0
- data/lib/qrack/qrack08.rb +7 -10
- data/lib/qrack/qrack09.rb +7 -10
- data/lib/qrack/queue.rb +27 -40
- data/lib/qrack/subscription.rb +102 -101
- data/lib/qrack/transport/buffer08.rb +266 -264
- data/lib/qrack/transport/buffer09.rb +268 -264
- data/lib/qrack/transport/frame08.rb +13 -11
- data/lib/qrack/transport/frame09.rb +9 -7
- data/spec/spec_08/bunny_spec.rb +48 -45
- data/spec/spec_08/connection_spec.rb +10 -7
- data/spec/spec_08/exchange_spec.rb +145 -143
- data/spec/spec_08/queue_spec.rb +161 -161
- data/spec/spec_09/bunny_spec.rb +46 -44
- data/spec/spec_09/connection_spec.rb +15 -8
- data/spec/spec_09/exchange_spec.rb +147 -145
- data/spec/spec_09/queue_spec.rb +182 -184
- metadata +60 -41
- data/README.rdoc +0 -66
data/spec/spec_08/queue_spec.rb
CHANGED
@@ -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
|
-
|
14
|
+
|
15
|
+
before(:each) do
|
14
16
|
@b = Bunny.new
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
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
|
-
|
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
|
-
|
174
|
+
break
|
174
175
|
end
|
175
176
|
|
176
177
|
5.times {|i| q.publish("#{i}")}
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
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
|
data/spec/spec_09/bunny_spec.rb
CHANGED
@@ -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
|
11
|
+
require "bunny"
|
10
12
|
|
11
13
|
describe Bunny do
|
12
|
-
|
13
|
-
|
14
|
+
|
15
|
+
before(:each) do
|
14
16
|
@b = Bunny.new(:spec => '09')
|
15
|
-
|
16
|
-
|
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
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
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
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
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
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
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
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
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
|
-
|
62
|
-
|
63
|
-
|
63
|
+
it "should be able to set QoS" do
|
64
|
+
@b.qos.should == :qos_ok
|
65
|
+
end
|
64
66
|
|
65
|
-
end
|
67
|
+
end
|