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