bunny 0.5.3 → 0.6.0

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 (41) hide show
  1. data/{README → README.rdoc} +9 -2
  2. data/bunny.gemspec +12 -7
  3. data/examples/simple_08.rb +1 -1
  4. data/examples/simple_09.rb +1 -1
  5. data/examples/simple_ack_08.rb +1 -1
  6. data/examples/simple_ack_09.rb +1 -1
  7. data/examples/simple_consumer_08.rb +6 -14
  8. data/examples/simple_consumer_09.rb +6 -14
  9. data/examples/simple_fanout_08.rb +2 -2
  10. data/examples/simple_fanout_09.rb +2 -2
  11. data/examples/simple_headers_08.rb +1 -1
  12. data/examples/simple_headers_09.rb +1 -1
  13. data/examples/simple_topic_08.rb +4 -4
  14. data/examples/simple_topic_09.rb +4 -4
  15. data/lib/bunny.rb +23 -15
  16. data/lib/bunny/channel08.rb +8 -2
  17. data/lib/bunny/channel09.rb +8 -2
  18. data/lib/bunny/client08.rb +67 -24
  19. data/lib/bunny/client09.rb +88 -48
  20. data/lib/bunny/exchange08.rb +55 -43
  21. data/lib/bunny/exchange09.rb +67 -54
  22. data/lib/bunny/queue08.rb +79 -137
  23. data/lib/bunny/queue09.rb +79 -141
  24. data/lib/bunny/subscription08.rb +85 -0
  25. data/lib/bunny/subscription09.rb +85 -0
  26. data/lib/qrack/client.rb +29 -10
  27. data/lib/qrack/protocol/spec08.rb +1 -0
  28. data/lib/qrack/protocol/spec09.rb +1 -0
  29. data/lib/qrack/qrack08.rb +1 -0
  30. data/lib/qrack/qrack09.rb +1 -0
  31. data/lib/qrack/queue.rb +1 -1
  32. data/lib/qrack/subscription.rb +102 -0
  33. data/spec/spec_08/bunny_spec.rb +6 -0
  34. data/spec/spec_08/connection_spec.rb +12 -0
  35. data/spec/spec_08/exchange_spec.rb +19 -3
  36. data/spec/spec_08/queue_spec.rb +87 -13
  37. data/spec/spec_09/bunny_spec.rb +7 -1
  38. data/spec/spec_09/connection_spec.rb +12 -0
  39. data/spec/spec_09/exchange_spec.rb +19 -3
  40. data/spec/spec_09/queue_spec.rb +94 -21
  41. metadata +11 -6
@@ -8,7 +8,7 @@
8
8
 
9
9
  require File.expand_path(File.join(File.dirname(__FILE__), %w[.. .. lib bunny]))
10
10
 
11
- describe Bunny do
11
+ describe 'Queue' do
12
12
 
13
13
  before(:each) do
14
14
  @b = Bunny.new
@@ -25,7 +25,13 @@ describe Bunny do
25
25
  q.bind(exch, :nowait => true).should == :bind_ok
26
26
  end
27
27
 
28
- it "should be able to bind to an exchange" do
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
29
35
  exch = @b.exchange('direct_exch')
30
36
  q = @b.queue('test1')
31
37
  q.bind(exch).should == :bind_ok
@@ -37,7 +43,13 @@ describe Bunny do
37
43
  q.unbind(exch, :nowait => true).should == :unbind_ok
38
44
  end
39
45
 
40
- it "should be able to unbind from an exchange" do
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
41
53
  exch = @b.exchange('direct_exch')
42
54
  q = @b.queue('test1')
43
55
  q.unbind(exch).should == :unbind_ok
@@ -51,7 +63,7 @@ describe Bunny do
51
63
 
52
64
  it "should be able to pop a message complete with header and delivery details" do
53
65
  q = @b.queue('test1')
54
- msg = q.pop(:header => true)
66
+ msg = q.pop()
55
67
  msg.should be_an_instance_of(Hash)
56
68
  msg[:header].should be_an_instance_of(Bunny::Protocol::Header)
57
69
  msg[:payload].should == 'This is a test message'
@@ -62,7 +74,7 @@ describe Bunny do
62
74
  it "should be able to pop a message and just get the payload" do
63
75
  q = @b.queue('test1')
64
76
  q.publish('This is another test message')
65
- msg = q.pop
77
+ msg = q.pop[:payload]
66
78
  msg.should == 'This is another test message'
67
79
  q.message_count.should == 0
68
80
  end
@@ -71,15 +83,28 @@ describe Bunny do
71
83
  q = @b.queue('test1')
72
84
  lg_msg = 'z' * 142000
73
85
  q.publish(lg_msg)
74
- msg = q.pop
86
+ msg = q.pop[:payload]
75
87
  msg.should == lg_msg
76
88
  end
77
89
 
78
- it "should be able to be purged to remove all of its messages" do
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
79
98
  q = @b.queue('test1')
80
99
  5.times {q.publish('This is another test message')}
81
100
  q.message_count.should == 5
82
- q.purge
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
83
108
  q.message_count.should == 0
84
109
  end
85
110
 
@@ -87,7 +112,7 @@ describe Bunny do
87
112
  q = @b.queue('test1')
88
113
  q.publish('This is another test message')
89
114
  q.pop
90
- msg = q.pop
115
+ msg = q.pop[:payload]
91
116
  msg.should == :queue_empty
92
117
  end
93
118
 
@@ -95,9 +120,8 @@ describe Bunny do
95
120
  q = @b.queue('test1')
96
121
  5.times {q.publish('Yet another test message')}
97
122
  q.message_count.should == 5
98
- q.subscribe(:message_max => 0){|msg| x = 1}
123
+ q.subscribe(:message_max => 0)
99
124
  q.message_count.should == 5
100
- q.unsubscribe.should == :unsubscribe_ok
101
125
  q.purge.should == :purge_ok
102
126
  end
103
127
 
@@ -105,10 +129,60 @@ describe Bunny do
105
129
  q = @b.queue('test1')
106
130
  5.times {q.publish('Yet another test message')}
107
131
  q.message_count.should == 5
108
- q.subscribe(:message_max => 5){|msg| x = 1}
109
- q.unsubscribe.should == :unsubscribe_ok
132
+ q.subscribe(:message_max => 5)
110
133
  end
111
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
150
+
151
+ it "should pass correct block parameters through on subscribe" do
152
+ q = @b.queue('test1')
153
+ q.publish("messages pop\'n")
154
+
155
+ q.subscribe do |msg|
156
+ msg[:header].should be_an_instance_of Qrack::Protocol::Header
157
+ msg[:payload].should == "messages pop'n"
158
+ msg[:delivery_details].should_not be_nil
159
+
160
+ q.unsubscribe
161
+ break
162
+ end
163
+
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
+
184
+ end
185
+
112
186
  it "should be able to be deleted" do
113
187
  q = @b.queue('test1')
114
188
  res = q.delete
@@ -35,7 +35,7 @@ describe Bunny do
35
35
  end
36
36
 
37
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)
38
+ lambda { @b.switch_channel(5) }.should raise_error(RuntimeError)
39
39
  end
40
40
 
41
41
  it "should be able to create an exchange" do
@@ -52,6 +52,12 @@ describe Bunny do
52
52
  @b.queues.has_key?('test1').should be(true)
53
53
  end
54
54
 
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
+
55
61
  it "should be able to set QoS" do
56
62
  @b.qos.should == :qos_ok
57
63
  end
@@ -0,0 +1,12 @@
1
+ # connection_spec.rb
2
+
3
+ require File.expand_path(File.join(File.dirname(__FILE__), %w[.. .. lib bunny]))
4
+
5
+ describe Bunny do
6
+
7
+ it "should raise an error if the wrong user name or password is used" do
8
+ b = Bunny.new(:spec => '0.9', :user => 'wrong')
9
+ lambda { b.start}.should raise_error(Bunny::ProtocolError)
10
+ end
11
+
12
+ end
@@ -8,7 +8,7 @@
8
8
 
9
9
  require File.expand_path(File.join(File.dirname(__FILE__), %w[.. .. lib bunny]))
10
10
 
11
- describe Bunny do
11
+ describe 'Exchange' do
12
12
 
13
13
  before(:each) do
14
14
  @b = Bunny.new(:spec => '09')
@@ -16,7 +16,8 @@ describe Bunny do
16
16
  end
17
17
 
18
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::ProtocolError)
19
+ lambda { @b.exchange('bogus_ex', :type => :bogus) }.should raise_error(Bunny::ForcedConnectionCloseError)
20
+ @b.status.should == :not_connected
20
21
  end
21
22
 
22
23
  it "should allow a default direct exchange to be instantiated by specifying :type" do
@@ -124,13 +125,28 @@ describe Bunny do
124
125
  end
125
126
 
126
127
  it "should be able to return an undeliverable message" do
127
- exch = @b.exchange('')
128
+ exch = @b.exchange('return_exch')
128
129
  exch.publish('This message should be undeliverable', :immediate => true)
129
130
  ret_msg = @b.returned_message
130
131
  ret_msg.should be_an_instance_of(Hash)
131
132
  ret_msg[:payload].should == 'This message should be undeliverable'
132
133
  end
133
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
+
134
150
  it "should be able to be deleted" do
135
151
  exch = @b.exchange('direct_exchange')
136
152
  res = exch.delete
@@ -8,7 +8,7 @@
8
8
 
9
9
  require File.expand_path(File.join(File.dirname(__FILE__), %w[.. .. lib bunny]))
10
10
 
11
- describe Bunny do
11
+ describe 'Queue' do
12
12
 
13
13
  before(:each) do
14
14
  @b = Bunny.new(:spec => '09')
@@ -25,18 +25,30 @@ describe Bunny do
25
25
  q.bind(exch, :nowait => true).should == :bind_ok
26
26
  end
27
27
 
28
- it "should be able to bind to an exchange" do
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
29
35
  exch = @b.exchange('direct_exch')
30
36
  q = @b.queue('test1')
31
37
  q.bind(exch).should == :bind_ok
32
38
  end
33
39
 
34
- it "should ignore the :nowait option when unbinding from an exchange" do
40
+ it "should ignore the :nowait option when unbinding from an existing exchange" do
35
41
  exch = @b.exchange('direct_exch')
36
42
  q = @b.queue('test0')
37
43
  q.unbind(exch, :nowait => true).should == :unbind_ok
38
44
  end
39
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
+
40
52
  it "should be able to unbind from an exchange" do
41
53
  exch = @b.exchange('direct_exch')
42
54
  q = @b.queue('test1')
@@ -51,7 +63,7 @@ describe Bunny do
51
63
 
52
64
  it "should be able to pop a message complete with header and delivery details" do
53
65
  q = @b.queue('test1')
54
- msg = q.pop(:header => true)
66
+ msg = q.pop()
55
67
  msg.should be_an_instance_of(Hash)
56
68
  msg[:header].should be_an_instance_of(Bunny::Protocol09::Header)
57
69
  msg[:payload].should == 'This is a test message'
@@ -62,7 +74,7 @@ describe Bunny do
62
74
  it "should be able to pop a message and just get the payload" do
63
75
  q = @b.queue('test1')
64
76
  q.publish('This is another test message')
65
- msg = q.pop
77
+ msg = q.pop[:payload]
66
78
  msg.should == 'This is another test message'
67
79
  q.message_count.should == 0
68
80
  end
@@ -71,15 +83,28 @@ describe Bunny do
71
83
  q = @b.queue('test1')
72
84
  lg_msg = 'z' * 142000
73
85
  q.publish(lg_msg)
74
- msg = q.pop
86
+ msg = q.pop[:payload]
75
87
  msg.should == lg_msg
76
88
  end
77
89
 
78
- it "should be able to be purged to remove all of its messages" do
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
79
98
  q = @b.queue('test1')
80
99
  5.times {q.publish('This is another test message')}
81
100
  q.message_count.should == 5
82
- q.purge
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
83
108
  q.message_count.should == 0
84
109
  end
85
110
 
@@ -87,17 +112,16 @@ describe Bunny do
87
112
  q = @b.queue('test1')
88
113
  q.publish('This is another test message')
89
114
  q.pop
90
- msg = q.pop
115
+ msg = q.pop[:payload]
91
116
  msg.should == :queue_empty
92
117
  end
93
-
118
+
94
119
  it "should stop subscription without processing messages if max specified is 0" do
95
120
  q = @b.queue('test1')
96
121
  5.times {q.publish('Yet another test message')}
97
122
  q.message_count.should == 5
98
- q.subscribe(:message_max => 0){|msg| x = 1}
123
+ q.subscribe(:message_max => 0)
99
124
  q.message_count.should == 5
100
- q.unsubscribe.should == :unsubscribe_ok
101
125
  q.purge.should == :purge_ok
102
126
  end
103
127
 
@@ -105,8 +129,57 @@ describe Bunny do
105
129
  q = @b.queue('test1')
106
130
  5.times {q.publish('Yet another test message')}
107
131
  q.message_count.should == 5
108
- q.subscribe(:message_max => 5){|msg| x = 1}
109
- q.unsubscribe.should == :unsubscribe_ok
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
150
+
151
+ it "should pass correct block parameters through on subscribe" do
152
+ q = @b.queue('test1')
153
+ q.publish("messages pop\'n")
154
+
155
+ q.subscribe do |msg|
156
+ msg[:header].should be_an_instance_of Qrack::Protocol09::Header
157
+ msg[:payload].should == "messages pop'n"
158
+ msg[:delivery_details].should_not be_nil
159
+
160
+ q.unsubscribe
161
+ break
162
+ end
163
+
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
110
183
  end
111
184
 
112
185
  it "should be able to be deleted" do
@@ -115,18 +188,18 @@ describe Bunny do
115
188
  res.should == :delete_ok
116
189
  @b.queues.has_key?('test1').should be(false)
117
190
  end
118
-
191
+
119
192
  it "should ignore the :nowait option when deleted" do
120
193
  q = @b.queue('test0')
121
194
  q.delete(:nowait => true)
122
195
  end
123
196
 
124
- it "should support server named queues" do
125
- q = @b.queue
126
- q.name.should_not == nil
197
+ it "should support server named queues" do
198
+ q = @b.queue
199
+ q.name.should_not == nil
127
200
 
128
- @b.queue(q.name).should == q
129
- q.delete
130
- end
201
+ @b.queue(q.name).should == q
202
+ q.delete
203
+ end
131
204
 
132
205
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bunny
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Duncan
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-07 00:00:00 +01:00
12
+ date: 2009-10-05 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -20,10 +20,10 @@ executables: []
20
20
  extensions: []
21
21
 
22
22
  extra_rdoc_files:
23
- - README
23
+ - README.rdoc
24
24
  files:
25
25
  - LICENSE
26
- - README
26
+ - README.rdoc
27
27
  - Rakefile
28
28
  - bunny.gemspec
29
29
  - examples/simple_08.rb
@@ -49,9 +49,12 @@ files:
49
49
  - lib/bunny/exchange09.rb
50
50
  - lib/bunny/queue08.rb
51
51
  - lib/bunny/queue09.rb
52
+ - lib/bunny/subscription08.rb
53
+ - lib/bunny/subscription09.rb
52
54
  - lib/qrack/client.rb
53
55
  - lib/qrack/channel.rb
54
56
  - lib/qrack/queue.rb
57
+ - lib/qrack/subscription.rb
55
58
  - lib/qrack/protocol/protocol08.rb
56
59
  - lib/qrack/protocol/protocol09.rb
57
60
  - lib/qrack/protocol/spec08.rb
@@ -65,9 +68,11 @@ files:
65
68
  - spec/spec_08/bunny_spec.rb
66
69
  - spec/spec_08/exchange_spec.rb
67
70
  - spec/spec_08/queue_spec.rb
71
+ - spec/spec_08/connection_spec.rb
68
72
  - spec/spec_09/bunny_spec.rb
69
73
  - spec/spec_09/exchange_spec.rb
70
74
  - spec/spec_09/queue_spec.rb
75
+ - spec/spec_09/connection_spec.rb
71
76
  has_rdoc: true
72
77
  homepage: http://github.com/celldee/bunny/tree/master
73
78
  licenses: []
@@ -75,7 +80,7 @@ licenses: []
75
80
  post_install_message:
76
81
  rdoc_options:
77
82
  - --main
78
- - README
83
+ - README.rdoc
79
84
  require_paths:
80
85
  - lib
81
86
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -93,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
98
  requirements: []
94
99
 
95
100
  rubyforge_project: bunny-amqp
96
- rubygems_version: 1.3.4
101
+ rubygems_version: 1.3.5
97
102
  signing_key:
98
103
  specification_version: 3
99
104
  summary: A synchronous Ruby AMQP client that enables interaction with AMQP-compliant brokers/servers.