bunny 0.6.3.rc2 → 0.7
Sign up to get free protection for your applications and to get access to all the features.
- 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,3 +1,5 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
|
2
4
|
#:stopdoc:
|
3
5
|
# this file was autogenerated on 2009-12-13 13:40:20 +0000
|
@@ -12,15 +14,15 @@ module Qrack
|
|
12
14
|
ID = 0
|
13
15
|
|
14
16
|
@types = {
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
17
|
+
1 => 'Method',
|
18
|
+
2 => 'Header',
|
19
|
+
3 => 'Body',
|
20
|
+
4 => 'OobMethod',
|
21
|
+
5 => 'OobHeader',
|
22
|
+
6 => 'OobBody',
|
23
|
+
7 => 'Trace',
|
24
|
+
8 => 'Heartbeat',
|
25
|
+
}
|
24
26
|
|
25
27
|
attr_accessor :channel, :payload
|
26
28
|
|
@@ -63,9 +65,9 @@ module Qrack
|
|
63
65
|
end
|
64
66
|
|
65
67
|
class Method < Frame
|
66
|
-
|
68
|
+
|
67
69
|
ID = 1
|
68
|
-
|
70
|
+
|
69
71
|
def initialize payload = nil, channel = 0
|
70
72
|
super
|
71
73
|
unless @payload.is_a? Protocol::Class::Method or @payload.nil?
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
|
2
4
|
#:stopdoc:
|
3
5
|
# this file was autogenerated on 2009-12-13 13:38:22 +0000
|
@@ -12,11 +14,11 @@ module Qrack
|
|
12
14
|
ID = 0
|
13
15
|
|
14
16
|
@types = {
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
1 => 'Method',
|
18
|
+
2 => 'Header',
|
19
|
+
3 => 'Body',
|
20
|
+
8 => 'Heartbeat',
|
21
|
+
}
|
20
22
|
|
21
23
|
attr_accessor :channel, :payload
|
22
24
|
|
@@ -59,9 +61,9 @@ module Qrack
|
|
59
61
|
end
|
60
62
|
|
61
63
|
class Method < Frame
|
62
|
-
|
64
|
+
|
63
65
|
ID = 1
|
64
|
-
|
66
|
+
|
65
67
|
def initialize payload = nil, channel = 0
|
66
68
|
super
|
67
69
|
unless @payload.is_a? Protocol09::Class::Method or @payload.nil?
|
data/spec/spec_08/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'
|
@@ -10,56 +12,57 @@ require File.expand_path(File.join(File.dirname(__FILE__), %w[.. .. lib bunny]))
|
|
10
12
|
|
11
13
|
describe Bunny do
|
12
14
|
|
13
|
-
|
15
|
+
before(:each) do
|
14
16
|
@b = Bunny.new
|
15
|
-
|
16
|
-
|
17
|
+
@b.start
|
18
|
+
end
|
17
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
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
end
|
47
|
-
|
48
|
-
it "should be able to create a queue" do
|
49
|
-
q = @b.queue('test1')
|
50
|
-
q.should be_an_instance_of(Bunny::Queue)
|
51
|
-
q.name.should == 'test1'
|
52
|
-
@b.queues.has_key?('test1').should be(true)
|
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::Channel)
|
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
|
42
|
+
|
43
|
+
it "should be able to create an exchange" do
|
44
|
+
exch = @b.exchange('test_exchange')
|
45
|
+
exch.should be_an_instance_of(Bunny::Exchange)
|
46
|
+
exch.name.should == 'test_exchange'
|
47
|
+
@b.exchanges.has_key?('test_exchange').should be(true)
|
53
48
|
end
|
54
49
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
50
|
+
it "should be able to create a queue" do
|
51
|
+
q = @b.queue('test1')
|
52
|
+
q.should be_an_instance_of(Bunny::Queue)
|
53
|
+
q.name.should == 'test1'
|
54
|
+
@b.queues.has_key?('test1').should be(true)
|
55
|
+
end
|
56
|
+
|
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
|
62
|
+
|
63
|
+
it "should be able to set QoS" do
|
64
|
+
@b.qos.should == :qos_ok
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
@@ -1,12 +1,15 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
# connection_spec.rb
|
2
4
|
|
3
5
|
require File.expand_path(File.join(File.dirname(__FILE__), %w[.. .. lib bunny]))
|
4
6
|
|
5
7
|
describe Bunny do
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
end
|
8
|
+
|
9
|
+
it "should raise an error if the wrong user name or password is used" do
|
10
|
+
b = Bunny.new(:user => 'wrong')
|
11
|
+
lambda { b.start}.should raise_error(Bunny::ProtocolError)
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
@@ -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'
|
@@ -10,153 +12,153 @@ require File.expand_path(File.join(File.dirname(__FILE__), %w[.. .. lib bunny]))
|
|
10
12
|
|
11
13
|
describe 'Exchange' do
|
12
14
|
|
13
|
-
|
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
|
-
|
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::Exchange)
|
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::Exchange)
|
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::Exchange)
|
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::Exchange)
|
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::Exchange)
|
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::Exchange)
|
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::Exchange)
|
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::Exchange)
|
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::Exchange)
|
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::Exchange)
|
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::Exchange)
|
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
|