bunny 0.7.13 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -2
- data/.travis.yml +7 -16
- data/CHANGELOG +3 -21
- data/Gemfile +2 -4
- data/README.textile +31 -9
- data/Rakefile +3 -3
- data/bunny.gemspec +6 -3
- data/examples/{simple_08.rb → simple.rb} +1 -1
- data/examples/{simple_ack_08.rb → simple_ack.rb} +1 -1
- data/examples/{simple_consumer_08.rb → simple_consumer.rb} +4 -4
- data/examples/{simple_fanout_08.rb → simple_fanout.rb} +1 -1
- data/examples/{simple_headers_08.rb → simple_headers.rb} +2 -2
- data/examples/{simple_publisher_09.rb → simple_publisher.rb} +1 -1
- data/examples/{simple_topic_09.rb → simple_topic.rb} +2 -2
- data/ext/amqp-0.9.1.json +1 -0
- data/ext/config.yml +3 -3
- data/ext/qparser.rb +9 -52
- data/lib/bunny/{client09.rb → client.rb} +34 -46
- data/lib/bunny/{exchange09.rb → exchange.rb} +16 -15
- data/lib/bunny/{queue09.rb → queue.rb} +26 -23
- data/lib/bunny/{subscription09.rb → subscription.rb} +11 -6
- data/lib/bunny/version.rb +1 -1
- data/lib/bunny.rb +15 -33
- data/lib/qrack/client.rb +31 -22
- data/lib/qrack/protocol/{protocol08.rb → protocol.rb} +2 -1
- data/lib/qrack/protocol/{spec09.rb → spec.rb} +8 -7
- data/lib/qrack/{qrack08.rb → qrack.rb} +4 -4
- data/lib/qrack/subscription.rb +58 -9
- data/lib/qrack/transport/{buffer08.rb → buffer.rb} +9 -1
- data/lib/qrack/transport/{frame08.rb → frame.rb} +7 -22
- data/spec/spec_09/amqp_url_spec.rb +1 -1
- data/spec/spec_09/bunny_spec.rb +11 -9
- data/spec/spec_09/connection_spec.rb +9 -4
- data/spec/spec_09/exchange_spec.rb +23 -25
- data/spec/spec_09/queue_spec.rb +33 -19
- metadata +71 -81
- checksums.yaml +0 -7
- data/examples/simple_09.rb +0 -32
- data/examples/simple_ack_09.rb +0 -35
- data/examples/simple_consumer_09.rb +0 -55
- data/examples/simple_fanout_09.rb +0 -41
- data/examples/simple_headers_09.rb +0 -42
- data/examples/simple_publisher_08.rb +0 -29
- data/examples/simple_topic_08.rb +0 -61
- data/ext/amqp-0.8.json +0 -616
- data/lib/bunny/channel09.rb +0 -39
- data/lib/bunny/client08.rb +0 -480
- data/lib/bunny/exchange08.rb +0 -177
- data/lib/bunny/queue08.rb +0 -403
- data/lib/bunny/subscription08.rb +0 -87
- data/lib/qrack/protocol/protocol09.rb +0 -135
- data/lib/qrack/protocol/spec08.rb +0 -828
- data/lib/qrack/qrack09.rb +0 -20
- data/lib/qrack/transport/buffer09.rb +0 -305
- data/lib/qrack/transport/frame09.rb +0 -97
- data/spec/spec_08/bunny_spec.rb +0 -75
- data/spec/spec_08/connection_spec.rb +0 -24
- data/spec/spec_08/exchange_spec.rb +0 -175
- data/spec/spec_08/queue_spec.rb +0 -239
- data/spec/spec_helper.rb +0 -8
- /data/lib/bunny/{channel08.rb → channel.rb} +0 -0
data/spec/spec_09/queue_spec.rb
CHANGED
@@ -8,12 +8,12 @@
|
|
8
8
|
# If this is not the case, please change the 'Bunny.new' call below to include
|
9
9
|
# the relevant arguments e.g. @b = Bunny.new(:user => 'john', :pass => 'doe', :host => 'foobar')
|
10
10
|
|
11
|
-
|
11
|
+
require "bunny"
|
12
12
|
|
13
13
|
describe 'Queue' do
|
14
14
|
|
15
15
|
before(:each) do
|
16
|
-
@b = Bunny.new
|
16
|
+
@b = Bunny.new
|
17
17
|
@b.start
|
18
18
|
|
19
19
|
@default_exchange = @b.exchange("")
|
@@ -61,10 +61,10 @@ describe 'Queue' do
|
|
61
61
|
q.unbind(exch, :nowait => true).should == :unbind_ok
|
62
62
|
end
|
63
63
|
|
64
|
-
it "should
|
64
|
+
it "should raise an error if unbinding from a non-existent exchange" do
|
65
65
|
q = @b.queue('test1')
|
66
|
-
q.unbind('bogus').should
|
67
|
-
@b.channel.active.should ==
|
66
|
+
lambda {q.unbind('bogus')}.should raise_error(Bunny::ForcedChannelCloseError)
|
67
|
+
@b.channel.active.should == false
|
68
68
|
end
|
69
69
|
|
70
70
|
it "should be able to unbind from an exchange" do
|
@@ -78,12 +78,24 @@ describe 'Queue' do
|
|
78
78
|
@default_exchange.publish('This is a test message', :key => 'test1')
|
79
79
|
msg = q.pop()
|
80
80
|
msg.should be_an_instance_of(Hash)
|
81
|
-
msg[:header].should be_an_instance_of(Bunny::
|
81
|
+
msg[:header].should be_an_instance_of(Bunny::Protocol::Header)
|
82
82
|
msg[:payload].should == 'This is a test message'
|
83
83
|
msg[:delivery_details].should be_an_instance_of(Hash)
|
84
84
|
message_count(q).should == 0
|
85
85
|
end
|
86
86
|
|
87
|
+
it "should be able to send reply_to, correlation_id and user_id headers " do
|
88
|
+
q = @b.queue('test1')
|
89
|
+
@default_exchange.publish('This is a test message', :key => 'test1',
|
90
|
+
:reply_to => 'test_reply_to',
|
91
|
+
:correlation_id => '987654',
|
92
|
+
:user_id => 'guest')
|
93
|
+
msg = q.pop()
|
94
|
+
msg[:header].properties[:reply_to].should == 'test_reply_to'
|
95
|
+
msg[:header].properties[:correlation_id].should == '987654'
|
96
|
+
msg[:header].properties[:user_id].should == 'guest'
|
97
|
+
end
|
98
|
+
|
87
99
|
it "should be able to pop a message and just get the payload" do
|
88
100
|
q = @b.queue('test1')
|
89
101
|
@default_exchange.publish('This is another test message', :key => 'test1')
|
@@ -100,15 +112,6 @@ describe 'Queue' do
|
|
100
112
|
msg.should == lg_msg
|
101
113
|
end
|
102
114
|
|
103
|
-
it "should be able to send and receive messages where body length is an exact multiple of frame_max minus framing bytes" do
|
104
|
-
limit = @b.frame_max-8
|
105
|
-
q = @b.queue('test1')
|
106
|
-
lg_msg = 'a' * (5*limit)
|
107
|
-
@default_exchange.publish(lg_msg, :key => 'test1')
|
108
|
-
msg = q.pop[:payload]
|
109
|
-
msg.should == lg_msg
|
110
|
-
end
|
111
|
-
|
112
115
|
it "should be able call a block when popping a message" do
|
113
116
|
q = @b.queue('test1')
|
114
117
|
@default_exchange.publish('This is another test message', :key => 'test1')
|
@@ -164,10 +167,10 @@ describe 'Queue' do
|
|
164
167
|
q.purge.should == :purge_ok
|
165
168
|
end
|
166
169
|
|
167
|
-
it "should
|
170
|
+
it "should raise an error when delete fails" do
|
168
171
|
q = @b.queue('test1')
|
169
|
-
q.delete(:queue => 'bogus').should
|
170
|
-
@b.channel.active.should ==
|
172
|
+
lambda {q.delete(:queue => 'bogus')}.should raise_error(Bunny::ForcedChannelCloseError)
|
173
|
+
@b.channel.active.should == false
|
171
174
|
end
|
172
175
|
|
173
176
|
it "should pass correct block parameters through on subscribe" do
|
@@ -175,7 +178,7 @@ describe 'Queue' do
|
|
175
178
|
@default_exchange.publish("messages pop'n", :key => 'test1')
|
176
179
|
|
177
180
|
q.subscribe do |msg|
|
178
|
-
msg[:header].should be_an_instance_of Qrack::
|
181
|
+
msg[:header].should be_an_instance_of Qrack::Protocol::Header
|
179
182
|
msg[:payload].should == "messages pop'n"
|
180
183
|
msg[:delivery_details].should_not be_nil
|
181
184
|
|
@@ -183,6 +186,17 @@ describe 'Queue' do
|
|
183
186
|
break
|
184
187
|
end
|
185
188
|
end
|
189
|
+
|
190
|
+
specify "subscribe method should support cancellation through a cancellator IO object" do
|
191
|
+
q = @b.queue('test1')
|
192
|
+
a, b = IO.pipe
|
193
|
+
b.close
|
194
|
+
block_called = false
|
195
|
+
q.subscribe(:cancellator => a) do |msg|
|
196
|
+
block_called = true
|
197
|
+
end
|
198
|
+
block_called.should be_false
|
199
|
+
end
|
186
200
|
|
187
201
|
it "should finish processing subscription messages if break is called in block" do
|
188
202
|
q = @b.queue('test1')
|
metadata
CHANGED
@@ -1,134 +1,124 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: bunny
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 63
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 8
|
9
|
+
- 0
|
10
|
+
version: 0.8.0
|
5
11
|
platform: ruby
|
6
|
-
authors:
|
12
|
+
authors:
|
7
13
|
- Chris Duncan
|
8
14
|
- Eric Lindvall
|
9
15
|
- Jakub Stastny aka botanicus
|
10
16
|
- Michael S. Klishin
|
11
17
|
- Stefan Kaes
|
12
|
-
autorequire:
|
18
|
+
autorequire:
|
13
19
|
bindir: bin
|
14
20
|
cert_chain: []
|
15
|
-
|
21
|
+
|
22
|
+
date: 2012-06-23 00:00:00 Z
|
16
23
|
dependencies: []
|
17
|
-
|
18
|
-
|
19
|
-
email:
|
24
|
+
|
25
|
+
description: A synchronous Ruby AMQP client that enables interaction with AMQP-compliant brokers.
|
26
|
+
email:
|
20
27
|
- celldee@gmail.com
|
21
28
|
- eric@5stops.com
|
22
29
|
- stastny@101ideas.cz
|
23
30
|
- michael@novemberain.com
|
24
31
|
- skaes@railsexpress.de
|
25
32
|
executables: []
|
33
|
+
|
26
34
|
extensions: []
|
27
|
-
|
35
|
+
|
36
|
+
extra_rdoc_files:
|
28
37
|
- README.textile
|
29
|
-
files:
|
30
|
-
-
|
31
|
-
-
|
32
|
-
-
|
33
|
-
-
|
38
|
+
files:
|
39
|
+
- .gitignore
|
40
|
+
- .rspec
|
41
|
+
- .travis.yml
|
42
|
+
- .yardopts
|
34
43
|
- CHANGELOG
|
35
44
|
- Gemfile
|
36
45
|
- LICENSE
|
37
46
|
- README.textile
|
38
47
|
- Rakefile
|
39
48
|
- bunny.gemspec
|
40
|
-
- examples/
|
41
|
-
- examples/
|
42
|
-
- examples/
|
43
|
-
- examples/
|
44
|
-
- examples/
|
45
|
-
- examples/
|
46
|
-
- examples/
|
47
|
-
- examples/simple_fanout_09.rb
|
48
|
-
- examples/simple_headers_08.rb
|
49
|
-
- examples/simple_headers_09.rb
|
50
|
-
- examples/simple_publisher_08.rb
|
51
|
-
- examples/simple_publisher_09.rb
|
52
|
-
- examples/simple_topic_08.rb
|
53
|
-
- examples/simple_topic_09.rb
|
54
|
-
- ext/amqp-0.8.json
|
49
|
+
- examples/simple.rb
|
50
|
+
- examples/simple_ack.rb
|
51
|
+
- examples/simple_consumer.rb
|
52
|
+
- examples/simple_fanout.rb
|
53
|
+
- examples/simple_headers.rb
|
54
|
+
- examples/simple_publisher.rb
|
55
|
+
- examples/simple_topic.rb
|
55
56
|
- ext/amqp-0.9.1.json
|
56
57
|
- ext/config.yml
|
57
58
|
- ext/qparser.rb
|
58
59
|
- lib/bunny.rb
|
59
|
-
- lib/bunny/
|
60
|
-
- lib/bunny/
|
61
|
-
- lib/bunny/client08.rb
|
62
|
-
- lib/bunny/client09.rb
|
60
|
+
- lib/bunny/channel.rb
|
61
|
+
- lib/bunny/client.rb
|
63
62
|
- lib/bunny/consumer.rb
|
64
|
-
- lib/bunny/
|
65
|
-
- lib/bunny/
|
66
|
-
- lib/bunny/
|
67
|
-
- lib/bunny/queue09.rb
|
68
|
-
- lib/bunny/subscription08.rb
|
69
|
-
- lib/bunny/subscription09.rb
|
63
|
+
- lib/bunny/exchange.rb
|
64
|
+
- lib/bunny/queue.rb
|
65
|
+
- lib/bunny/subscription.rb
|
70
66
|
- lib/bunny/system_timer.rb
|
71
67
|
- lib/bunny/version.rb
|
72
68
|
- lib/qrack/amq-client-url.rb
|
73
69
|
- lib/qrack/channel.rb
|
74
70
|
- lib/qrack/client.rb
|
75
71
|
- lib/qrack/errors.rb
|
76
|
-
- lib/qrack/protocol/
|
77
|
-
- lib/qrack/protocol/
|
78
|
-
- lib/qrack/
|
79
|
-
- lib/qrack/protocol/spec09.rb
|
80
|
-
- lib/qrack/qrack08.rb
|
81
|
-
- lib/qrack/qrack09.rb
|
72
|
+
- lib/qrack/protocol/protocol.rb
|
73
|
+
- lib/qrack/protocol/spec.rb
|
74
|
+
- lib/qrack/qrack.rb
|
82
75
|
- lib/qrack/queue.rb
|
83
76
|
- lib/qrack/subscription.rb
|
84
|
-
- lib/qrack/transport/
|
85
|
-
- lib/qrack/transport/
|
86
|
-
- lib/qrack/transport/frame08.rb
|
87
|
-
- lib/qrack/transport/frame09.rb
|
88
|
-
- spec/spec_08/bunny_spec.rb
|
89
|
-
- spec/spec_08/connection_spec.rb
|
90
|
-
- spec/spec_08/exchange_spec.rb
|
91
|
-
- spec/spec_08/queue_spec.rb
|
77
|
+
- lib/qrack/transport/buffer.rb
|
78
|
+
- lib/qrack/transport/frame.rb
|
92
79
|
- spec/spec_09/amqp_url_spec.rb
|
93
80
|
- spec/spec_09/bunny_spec.rb
|
94
81
|
- spec/spec_09/connection_spec.rb
|
95
82
|
- spec/spec_09/exchange_spec.rb
|
96
83
|
- spec/spec_09/queue_spec.rb
|
97
|
-
- spec/spec_helper.rb
|
98
84
|
homepage: http://github.com/ruby-amqp/bunny
|
99
|
-
licenses:
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
rdoc_options:
|
105
|
-
- "--main"
|
85
|
+
licenses: []
|
86
|
+
|
87
|
+
post_install_message: "[\e[32mVersion 0.8.0\e[0m] AMQP 0.8 client is removed. Bunny is an AMQP 0.9.1 client only now.\n"
|
88
|
+
rdoc_options:
|
89
|
+
- --main
|
106
90
|
- README.rdoc
|
107
|
-
require_paths:
|
91
|
+
require_paths:
|
108
92
|
- lib
|
109
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
-
|
93
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
111
96
|
- - ">="
|
112
|
-
- !ruby/object:Gem::Version
|
113
|
-
|
114
|
-
|
115
|
-
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
hash: 3
|
99
|
+
segments:
|
100
|
+
- 0
|
101
|
+
version: "0"
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
none: false
|
104
|
+
requirements:
|
116
105
|
- - ">="
|
117
|
-
- !ruby/object:Gem::Version
|
118
|
-
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
hash: 3
|
108
|
+
segments:
|
109
|
+
- 0
|
110
|
+
version: "0"
|
119
111
|
requirements: []
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
- spec/spec_08/exchange_spec.rb
|
128
|
-
- spec/spec_08/queue_spec.rb
|
112
|
+
|
113
|
+
rubyforge_project: bunny-amqp
|
114
|
+
rubygems_version: 1.8.15
|
115
|
+
signing_key:
|
116
|
+
specification_version: 3
|
117
|
+
summary: Synchronous Ruby AMQP 0.8.0 client
|
118
|
+
test_files:
|
129
119
|
- spec/spec_09/amqp_url_spec.rb
|
130
120
|
- spec/spec_09/bunny_spec.rb
|
131
121
|
- spec/spec_09/connection_spec.rb
|
132
122
|
- spec/spec_09/exchange_spec.rb
|
133
123
|
- spec/spec_09/queue_spec.rb
|
134
|
-
|
124
|
+
has_rdoc: true
|
checksums.yaml
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
---
|
2
|
-
SHA256:
|
3
|
-
metadata.gz: 57852c2972d82a8c8a9742026c86d08bf3c7eb62486720fdff700bf86bbd1a6d
|
4
|
-
data.tar.gz: 64698a92d4a10ef741d965d5688bb7c5ca8a719ef4372616f59b35e6625afd6d
|
5
|
-
SHA512:
|
6
|
-
metadata.gz: af605621674f7d907ae4b8ce550dd178d95b9337e53cd7d4b36285b2060ce1014ee923357f80e74e0986a337388e131d20f7b1702788a4c2bbd38efb0b0303d6
|
7
|
-
data.tar.gz: 96378e392f16a5429fd690b1f9ce4c6c996c1f573a77bc0cbedce701279cb80969bf049219970a6503ee98dcafc9c67dc584bac8c8a2f59e9e5c166b2aee155b
|
data/examples/simple_09.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
# simple_09.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
|
-
$:.unshift File.dirname(__FILE__) + '/../lib'
|
12
|
-
|
13
|
-
require 'bunny'
|
14
|
-
|
15
|
-
b = Bunny.new(:logging => true, :spec => '09')
|
16
|
-
|
17
|
-
# start a communication session with the amqp server
|
18
|
-
b.start
|
19
|
-
|
20
|
-
# declare a queue
|
21
|
-
q = b.queue('test1')
|
22
|
-
|
23
|
-
# publish a message to the queue
|
24
|
-
q.publish('➸ Hello everybody ☺!')
|
25
|
-
|
26
|
-
# get message from the queue
|
27
|
-
msg = q.pop[:payload]
|
28
|
-
|
29
|
-
puts 'This is the message: ' + msg + "\n\n"
|
30
|
-
|
31
|
-
# close the client connection
|
32
|
-
b.stop
|
data/examples/simple_ack_09.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
# simple_ack_09.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
|
-
$:.unshift File.dirname(__FILE__) + '/../lib'
|
12
|
-
|
13
|
-
require 'bunny'
|
14
|
-
|
15
|
-
b = Bunny.new(:logging => true, :spec => '09')
|
16
|
-
|
17
|
-
# start a communication session with the amqp server
|
18
|
-
b.start
|
19
|
-
|
20
|
-
# declare a queue
|
21
|
-
q = b.queue('test1')
|
22
|
-
|
23
|
-
# publish a message to the queue
|
24
|
-
q.publish('Testing acknowledgements')
|
25
|
-
|
26
|
-
# get message from the queue
|
27
|
-
msg = q.pop(:ack => true)[:payload]
|
28
|
-
|
29
|
-
# acknowledge receipt of message
|
30
|
-
q.ack
|
31
|
-
|
32
|
-
puts 'This is the message: ' + msg + "\n\n"
|
33
|
-
|
34
|
-
# close the client connection
|
35
|
-
b.stop
|
@@ -1,55 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
# simple_consumer_09.rb
|
4
|
-
|
5
|
-
# N.B. To be used in conjunction with simple_publisher.rb
|
6
|
-
|
7
|
-
# Assumes that target message broker/server has a user called 'guest' with a password 'guest'
|
8
|
-
# and that it is running on 'localhost'.
|
9
|
-
|
10
|
-
# If this is not the case, please change the 'Bunny.new' call below to include
|
11
|
-
# the relevant arguments e.g. b = Bunny.new(:user => 'john', :pass => 'doe', :host => 'foobar')
|
12
|
-
|
13
|
-
# How this example works
|
14
|
-
#=======================
|
15
|
-
#
|
16
|
-
# Open up two console windows start this program in one of them by typing -
|
17
|
-
#
|
18
|
-
# ruby simple_consumer_09.rb
|
19
|
-
#
|
20
|
-
# Then switch to the other console window and type -
|
21
|
-
#
|
22
|
-
# ruby simple_publisher_09.rb
|
23
|
-
#
|
24
|
-
# A message will be printed out by the simple_consumer and it will wait for the next message
|
25
|
-
# until the timeout interval is reached.
|
26
|
-
#
|
27
|
-
# Run simple_publisher as many times as you like. When you want the program to stop just stop
|
28
|
-
# sending messages and the subscribe loop will timeout after 30 seconds, the program will
|
29
|
-
# unsubscribe from the queue and close the connection to the server.
|
30
|
-
|
31
|
-
$:.unshift File.dirname(__FILE__) + '/../lib'
|
32
|
-
|
33
|
-
require 'bunny'
|
34
|
-
|
35
|
-
b = Bunny.new(:logging => true, :spec => '09')
|
36
|
-
|
37
|
-
# start a communication session with the amqp server
|
38
|
-
b.start
|
39
|
-
|
40
|
-
# create/get queue
|
41
|
-
q = b.queue('po_box')
|
42
|
-
|
43
|
-
# create/get exchange
|
44
|
-
exch = b.exchange('sorting_room')
|
45
|
-
|
46
|
-
# bind queue to exchange
|
47
|
-
q.bind(exch, :key => 'fred')
|
48
|
-
|
49
|
-
# subscribe to queue
|
50
|
-
q.subscribe(:consumer_tag => 'testtag1', :timeout => 30) do |msg|
|
51
|
-
puts "#{q.subscription.message_count}: #{msg[:payload]}"
|
52
|
-
end
|
53
|
-
|
54
|
-
# Close client
|
55
|
-
b.stop
|
@@ -1,41 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
# simple_fanout_09.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
|
-
$:.unshift File.dirname(__FILE__) + '/../lib'
|
12
|
-
|
13
|
-
require 'bunny'
|
14
|
-
|
15
|
-
b = Bunny.new(:logging => true, :spec => '09')
|
16
|
-
|
17
|
-
# start a communication session with the amqp server
|
18
|
-
b.start
|
19
|
-
|
20
|
-
# declare queues
|
21
|
-
q1 = b.queue('test_fan1')
|
22
|
-
q2 = b.queue('test_fan2')
|
23
|
-
|
24
|
-
# create a fanout exchange
|
25
|
-
exch = b.exchange('test_fan', :type => :fanout)
|
26
|
-
|
27
|
-
# bind the queues to the exchange
|
28
|
-
q1.bind(exch)
|
29
|
-
q2.bind(exch)
|
30
|
-
|
31
|
-
# publish a message to the exchange
|
32
|
-
exch.publish('This message will be fanned out')
|
33
|
-
|
34
|
-
# get message from the queues
|
35
|
-
msg = q1.pop[:payload]
|
36
|
-
puts 'This is the message from q1: ' + msg + "\n\n"
|
37
|
-
msg = q2.pop[:payload]
|
38
|
-
puts 'This is the message from q2: ' + msg + "\n\n"
|
39
|
-
|
40
|
-
# close the client connection
|
41
|
-
b.stop
|
@@ -1,42 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
# simple_headers_09.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
|
-
$:.unshift File.dirname(__FILE__) + '/../lib'
|
12
|
-
|
13
|
-
require 'bunny'
|
14
|
-
|
15
|
-
b = Bunny.new(:spec => '09')
|
16
|
-
|
17
|
-
# start a communication session with the amqp server
|
18
|
-
b.start
|
19
|
-
|
20
|
-
# declare queues
|
21
|
-
q = b.queue('header_q1')
|
22
|
-
|
23
|
-
# create a headers exchange
|
24
|
-
header_exch = b.exchange('header_exch', :type => :headers)
|
25
|
-
|
26
|
-
# bind the queue to the exchange
|
27
|
-
q.bind(header_exch, :arguments => {'h1'=>'a','x-match'=>'all'})
|
28
|
-
|
29
|
-
# publish messages to the exchange
|
30
|
-
header_exch.publish('Headers test msg 1', :headers => {'h1'=>'a'})
|
31
|
-
header_exch.publish('Headers test msg 2', :headers => {'h1'=>'z'})
|
32
|
-
|
33
|
-
|
34
|
-
# get messages from the queue - should only be msg 1 that got through
|
35
|
-
msg = ""
|
36
|
-
until msg == :queue_empty do
|
37
|
-
msg = q.pop[:payload]
|
38
|
-
puts 'This is a message from the header_q1 queue: ' + msg + "\n" unless msg == :queue_empty
|
39
|
-
end
|
40
|
-
|
41
|
-
# close the client connection
|
42
|
-
b.stop
|
@@ -1,29 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
# simple_publisher_08.rb
|
4
|
-
|
5
|
-
# N.B. To be used in conjunction with simple_consumer_08.rb. See simple_consumer.rb for explanation.
|
6
|
-
|
7
|
-
# Assumes that target message broker/server has a user called 'guest' with a password 'guest'
|
8
|
-
# and that it is running on 'localhost'.
|
9
|
-
|
10
|
-
# If this is not the case, please change the 'Bunny.new' call below to include
|
11
|
-
# the relevant arguments e.g. b = Bunny.new(:user => 'john', :pass => 'doe', :host => 'foobar')
|
12
|
-
|
13
|
-
$:.unshift File.dirname(__FILE__) + '/../lib'
|
14
|
-
|
15
|
-
require 'bunny'
|
16
|
-
|
17
|
-
b = Bunny.new(:logging => true)
|
18
|
-
|
19
|
-
# start a communication session with the amqp server
|
20
|
-
b.start
|
21
|
-
|
22
|
-
# create/get exchange
|
23
|
-
exch = b.exchange('sorting_room')
|
24
|
-
|
25
|
-
# publish message to exchange
|
26
|
-
exch.publish('This is a message from the publisher', :key => 'fred')
|
27
|
-
|
28
|
-
# message should now be picked up by the consumer so we can stop
|
29
|
-
b.stop
|
data/examples/simple_topic_08.rb
DELETED
@@ -1,61 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
# simple_topic_08.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
|
-
$:.unshift File.dirname(__FILE__) + '/../lib'
|
12
|
-
|
13
|
-
require 'bunny'
|
14
|
-
|
15
|
-
b = Bunny.new
|
16
|
-
|
17
|
-
# start a communication session with the amqp server
|
18
|
-
b.start
|
19
|
-
|
20
|
-
# declare queues
|
21
|
-
soccer = b.queue('topic_soccer')
|
22
|
-
cricket = b.queue('topic_cricket')
|
23
|
-
rugby = b.queue('topic_rugby')
|
24
|
-
allsport = b.queue('topic_allsport')
|
25
|
-
|
26
|
-
# create a topic exchange
|
27
|
-
sports_results = b.exchange('sports_results', :type => :topic)
|
28
|
-
|
29
|
-
# bind the queues to the exchange
|
30
|
-
soccer.bind(sports_results, :key => 'soccer.*')
|
31
|
-
cricket.bind(sports_results, :key => 'cricket.*')
|
32
|
-
rugby.bind(sports_results, :key => 'rugby.*')
|
33
|
-
allsport.bind(sports_results, :key => '*.result')
|
34
|
-
|
35
|
-
# publish messages to the exchange
|
36
|
-
sports_results.publish('Manchester United 1 : Hull City 4', :key => 'soccer.result')
|
37
|
-
sports_results.publish('England beat Australia by 5 wickets in first test', :key => 'cricket.result')
|
38
|
-
sports_results.publish('British Lions 15 : South Africa 12', :key => 'rugby.result')
|
39
|
-
|
40
|
-
# get message from the queues
|
41
|
-
|
42
|
-
# soccer queue got the soccer message
|
43
|
-
msg = soccer.pop[:payload]
|
44
|
-
puts 'This is a message from the soccer q: ' + msg + "\n\n"
|
45
|
-
|
46
|
-
# cricket queue got the cricket message
|
47
|
-
msg = cricket.pop[:payload]
|
48
|
-
puts 'This is a message from the cricket q: ' + msg + "\n\n"
|
49
|
-
|
50
|
-
# rugby queue got the rugby message
|
51
|
-
msg = rugby.pop[:payload]
|
52
|
-
puts 'This is a message from the rugby q: ' + msg + "\n\n"
|
53
|
-
|
54
|
-
# allsport queue got all of the messages
|
55
|
-
until msg == :queue_empty do
|
56
|
-
msg = allsport.pop[:payload]
|
57
|
-
puts 'This is a message from the allsport q: ' + msg + "\n\n" unless msg == :queue_empty
|
58
|
-
end
|
59
|
-
|
60
|
-
# close the client connection
|
61
|
-
b.stop
|