bunny 0.9.0.pre1 → 0.9.0.pre2
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog.md +58 -6
- data/examples/guides/getting_started/blabbr.rb +27 -0
- data/examples/guides/getting_started/hello_world.rb +21 -0
- data/examples/guides/getting_started/weathr.rb +47 -0
- data/lib/bunny/channel.rb +12 -5
- data/lib/bunny/delivery_info.rb +68 -0
- data/lib/bunny/exchange.rb +7 -1
- data/lib/bunny/{message_metadata.rb → message_properties.rb} +9 -38
- data/lib/bunny/queue.rb +25 -4
- data/lib/bunny/return_info.rb +63 -0
- data/lib/bunny/session.rb +32 -10
- data/lib/bunny/transport.rb +5 -1
- data/lib/bunny/version.rb +1 -1
- data/spec/higher_level_api/integration/basic_consume_spec.rb +2 -2
- data/spec/higher_level_api/integration/queue_bind_spec.rb +8 -8
- data/spec/lower_level_api/integration/basic_consume_spec.rb +4 -4
- metadata +8 -3
data/ChangeLog.md
CHANGED
@@ -1,6 +1,58 @@
|
|
1
|
-
|
1
|
+
## Changes between Bunny 0.9.0.pre1 and 0.9.0.pre2
|
2
2
|
|
3
|
-
|
3
|
+
### Change Bunny::Queue#pop default for :ack to false
|
4
|
+
|
5
|
+
It makes more sense for beginners that way.
|
6
|
+
|
7
|
+
|
8
|
+
### Bunny::Queue#subscribe now support the new :block option
|
9
|
+
|
10
|
+
`Bunny::Queue#subscribe` support the new `:block` option
|
11
|
+
(a boolean).
|
12
|
+
|
13
|
+
It controls whether the current thread will be blocked
|
14
|
+
by `Bunny::Queue#subscribe`.
|
15
|
+
|
16
|
+
|
17
|
+
### Bunny::Exchange#publish now supports :key again
|
18
|
+
|
19
|
+
`Bunny::Exchange#publish` now supports `:key` as an alias for
|
20
|
+
`:routing_key`.
|
21
|
+
|
22
|
+
|
23
|
+
### Bunny::Session#queue et al.
|
24
|
+
|
25
|
+
`Bunny::Session#queue`, `Bunny::Session#direct`, `Bunny::Session#fanout`, `Bunny::Session#topic`,
|
26
|
+
and `Bunny::Session#headers` were added to simplify migration. They all delegate to their respective
|
27
|
+
`Bunny::Channel` methods on the default channel every connection has.
|
28
|
+
|
29
|
+
|
30
|
+
### Bunny::Channel#exchange, Bunny::Session#exchange
|
31
|
+
|
32
|
+
`Bunny::Channel#exchange` and `Bunny::Session#exchange` were added to simplify
|
33
|
+
migration:
|
34
|
+
|
35
|
+
``` ruby
|
36
|
+
b = Bunny.new
|
37
|
+
b.start
|
38
|
+
|
39
|
+
# uses default connection channel
|
40
|
+
x = b.exchange("logs.events", :topic)
|
41
|
+
```
|
42
|
+
|
43
|
+
### Bunny::Queue#subscribe now properly takes 3 arguments
|
44
|
+
|
45
|
+
``` ruby
|
46
|
+
q.subscribe(:exclusive => false, :ack => false) do |delivery_info, properties, payload|
|
47
|
+
# ...
|
48
|
+
end
|
49
|
+
```
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
## Changes between Bunny 0.8.x and 0.9.0.pre1
|
54
|
+
|
55
|
+
### New convenience functions: Bunny::Channel#fanout, Bunny::Channel#topic
|
4
56
|
|
5
57
|
`Bunny::Channel#fanout`, `Bunny::Channel#topic`, `Bunny::Channel#direct`, `Bunny::Channel#headers`,
|
6
58
|
and`Bunny::Channel#default_exchange` are new convenience methods to instantiate exchanges:
|
@@ -14,7 +66,7 @@ x = ch.fanout("logging.events", :durable => true)
|
|
14
66
|
```
|
15
67
|
|
16
68
|
|
17
|
-
|
69
|
+
### Bunny::Queue#pop and consumer handlers (Bunny::Queue#subscribe) signatures have changed
|
18
70
|
|
19
71
|
Bunny `< 0.9.x` example:
|
20
72
|
|
@@ -51,13 +103,13 @@ The unification moment was the driving factor.
|
|
51
103
|
|
52
104
|
|
53
105
|
|
54
|
-
|
106
|
+
### Bunny::Client#write now raises Bunny::ConnectionError
|
55
107
|
|
56
108
|
Bunny::Client#write now raises `Bunny::ConnectionError` instead of `Bunny::ServerDownError` when network
|
57
109
|
I/O operations fail.
|
58
110
|
|
59
111
|
|
60
|
-
|
112
|
+
### Bunny::Client.create_channel now uses a bitset-based allocator
|
61
113
|
|
62
114
|
Instead of reusing channel instances, `Bunny::Client.create_channel` now opens new channels and
|
63
115
|
uses bitset-based allocator to keep track of used channel ids. This avoids situations when
|
@@ -67,6 +119,6 @@ long running applications that aggressively open and release channels.
|
|
67
119
|
This is also how amqp gem and RabbitMQ Java client manage channel ids.
|
68
120
|
|
69
121
|
|
70
|
-
|
122
|
+
### Bunny::ServerDownError is now Bunny::TCPConnectionFailed
|
71
123
|
|
72
124
|
`Bunny::ServerDownError` is now an alias for `Bunny::TCPConnectionFailed`
|
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
require "rubygems"
|
5
|
+
require "bunny"
|
6
|
+
|
7
|
+
conn = Bunny.new
|
8
|
+
conn.start
|
9
|
+
|
10
|
+
ch = conn.create_channel
|
11
|
+
x = ch.fanout("nba.scores")
|
12
|
+
|
13
|
+
ch.queue("joe", :auto_delete => true).bind(x).subscribe do |delivery_info, properties, payload|
|
14
|
+
puts "#{payload} => joe"
|
15
|
+
end
|
16
|
+
|
17
|
+
ch.queue("aaron", :auto_delete => true).bind(x).subscribe do |delivery_info, properties, payload|
|
18
|
+
puts "#{payload} => aaron"
|
19
|
+
end
|
20
|
+
|
21
|
+
ch.queue("bob", :auto_delete => true).bind(x).subscribe do |delivery_info, properties, payload|
|
22
|
+
puts "#{payload} => bob"
|
23
|
+
end
|
24
|
+
|
25
|
+
x.publish("BOS 101, NYK 89").publish("ORL 85, ALT 88")
|
26
|
+
|
27
|
+
conn.close
|
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
require "rubygems"
|
5
|
+
require "bunny"
|
6
|
+
|
7
|
+
conn = Bunny.new
|
8
|
+
conn.start
|
9
|
+
|
10
|
+
ch = conn.create_channel
|
11
|
+
q = ch.queue("bunny.examples.hello_world", :auto_delete => true)
|
12
|
+
x = ch.default_exchange
|
13
|
+
|
14
|
+
q.subscribe do |delivery_info, properties, payload|
|
15
|
+
puts "Received #{payload}"
|
16
|
+
end
|
17
|
+
|
18
|
+
x.publish("Hello!", :routing_key => q.name)
|
19
|
+
|
20
|
+
sleep 1.0
|
21
|
+
conn.close
|
@@ -0,0 +1,47 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
require "rubygems"
|
5
|
+
require "bunny"
|
6
|
+
|
7
|
+
connection = Bunny.new
|
8
|
+
connection.start
|
9
|
+
|
10
|
+
channel = connection.create_channel
|
11
|
+
# topic exchange name can be any string
|
12
|
+
exchange = channel.topic("weathr", :auto_delete => true)
|
13
|
+
|
14
|
+
# Subscribers.
|
15
|
+
channel.queue("", :exclusive => true).bind(exchange, :routing_key => "americas.north.#").subscribe do |delivery_info, properties, payload|
|
16
|
+
puts "An update for North America: #{payload}, routing key is #{delivery_info.routing_key}"
|
17
|
+
end
|
18
|
+
channel.queue("americas.south").bind(exchange, :routing_key => "americas.south.#").subscribe do |delivery_info, properties, payload|
|
19
|
+
puts "An update for South America: #{payload}, routing key is #{delivery_info.routing_key}"
|
20
|
+
end
|
21
|
+
channel.queue("us.california").bind(exchange, :routing_key => "americas.north.us.ca.*").subscribe do |delivery_info, properties, payload|
|
22
|
+
puts "An update for US/California: #{payload}, routing key is #{delivery_info.routing_key}"
|
23
|
+
end
|
24
|
+
channel.queue("us.tx.austin").bind(exchange, :routing_key => "#.tx.austin").subscribe do |delivery_info, properties, payload|
|
25
|
+
puts "An update for Austin, TX: #{payload}, routing key is #{delivery_info.routing_key}"
|
26
|
+
end
|
27
|
+
channel.queue("it.rome").bind(exchange, :routing_key => "europe.italy.rome").subscribe do |delivery_info, properties, payload|
|
28
|
+
puts "An update for Rome, Italy: #{payload}, routing key is #{delivery_info.routing_key}"
|
29
|
+
end
|
30
|
+
channel.queue("asia.hk").bind(exchange, :routing_key => "asia.southeast.hk.#").subscribe do |delivery_info, properties, payload|
|
31
|
+
puts "An update for Hong Kong: #{payload}, routing key is #{delivery_info.routing_key}"
|
32
|
+
end
|
33
|
+
|
34
|
+
exchange.publish("San Diego update", :routing_key => "americas.north.us.ca.sandiego").
|
35
|
+
publish("Berkeley update", :routing_key => "americas.north.us.ca.berkeley").
|
36
|
+
publish("San Francisco update", :routing_key => "americas.north.us.ca.sanfrancisco").
|
37
|
+
publish("New York update", :routing_key => "americas.north.us.ny.newyork").
|
38
|
+
publish("São Paolo update", :routing_key => "americas.south.brazil.saopaolo").
|
39
|
+
publish("Hong Kong update", :routing_key => "asia.southeast.hk.hongkong").
|
40
|
+
publish("Kyoto update", :routing_key => "asia.southeast.japan.kyoto").
|
41
|
+
publish("Shanghai update", :routing_key => "asia.southeast.prc.shanghai").
|
42
|
+
publish("Rome update", :routing_key => "europe.italy.roma").
|
43
|
+
publish("Paris update", :routing_key => "europe.france.paris")
|
44
|
+
|
45
|
+
sleep 1.0
|
46
|
+
|
47
|
+
connection.close
|
data/lib/bunny/channel.rb
CHANGED
@@ -5,7 +5,10 @@ require "bunny/consumer_work_pool"
|
|
5
5
|
|
6
6
|
require "bunny/exchange"
|
7
7
|
require "bunny/queue"
|
8
|
-
|
8
|
+
|
9
|
+
require "bunny/delivery_info"
|
10
|
+
require "bunny/return_info"
|
11
|
+
require "bunny/message_properties"
|
9
12
|
|
10
13
|
module Bunny
|
11
14
|
class Channel
|
@@ -106,7 +109,11 @@ module Bunny
|
|
106
109
|
end
|
107
110
|
|
108
111
|
def default_exchange
|
109
|
-
self.direct(
|
112
|
+
self.direct(AMQ::Protocol::EMPTY_STRING, :no_declare => true)
|
113
|
+
end
|
114
|
+
|
115
|
+
def exchange(name, opts = {})
|
116
|
+
Exchange.new(self, opts.fetch(:type, :direct), name, opts)
|
110
117
|
end
|
111
118
|
|
112
119
|
def prefetch(prefetch_count)
|
@@ -158,7 +165,7 @@ module Bunny
|
|
158
165
|
|
159
166
|
meta = { :priority => 0, :delivery_mode => 2, :content_type => "application/octet-stream" }.
|
160
167
|
merge(opts)
|
161
|
-
@connection.send_frameset(AMQ::Protocol::Basic::Publish.encode(@id, payload, meta, exchange_name, routing_key, meta[:mandatory], false,
|
168
|
+
@connection.send_frameset(AMQ::Protocol::Basic::Publish.encode(@id, payload, meta, exchange_name, routing_key, meta[:mandatory], false, @connection.frame_max), self)
|
162
169
|
|
163
170
|
self
|
164
171
|
end
|
@@ -540,7 +547,7 @@ module Bunny
|
|
540
547
|
consumer = @consumers[basic_deliver.consumer_tag]
|
541
548
|
if consumer
|
542
549
|
@work_pool.submit do
|
543
|
-
consumer.call(
|
550
|
+
consumer.call(DeliveryInfo.new(basic_deliver), MessageProperties.new(properties), content)
|
544
551
|
end
|
545
552
|
end
|
546
553
|
end
|
@@ -549,7 +556,7 @@ module Bunny
|
|
549
556
|
x = find_exchange(basic_return.exchange)
|
550
557
|
|
551
558
|
if x
|
552
|
-
x.handle_return(basic_return, properties, content)
|
559
|
+
x.handle_return(ReturnInfo.new(basic_return), MessageProperties.new(properties), content)
|
553
560
|
else
|
554
561
|
# TODO: log a warning
|
555
562
|
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module Bunny
|
2
|
+
# Wraps AMQ::Protocol::Basic::Deliver to
|
3
|
+
# provide access to the delivery properties as immutable hash as
|
4
|
+
# well as methods.
|
5
|
+
class DeliveryInfo
|
6
|
+
|
7
|
+
#
|
8
|
+
# Behaviors
|
9
|
+
#
|
10
|
+
|
11
|
+
include Enumerable
|
12
|
+
|
13
|
+
#
|
14
|
+
# API
|
15
|
+
#
|
16
|
+
|
17
|
+
def initialize(basic_deliver)
|
18
|
+
@basic_deliver = basic_deliver
|
19
|
+
@hash = {
|
20
|
+
:consumer_tag => basic_deliver.consumer_tag,
|
21
|
+
:delivery_tag => basic_deliver.delivery_tag,
|
22
|
+
:redelivered => basic_deliver.redelivered,
|
23
|
+
:exchange => basic_deliver.exchange,
|
24
|
+
:routing_key => basic_deliver.routing_key
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
def each(*args, &block)
|
29
|
+
@hash.each(*args, &block)
|
30
|
+
end
|
31
|
+
|
32
|
+
def [](k)
|
33
|
+
@hash[k]
|
34
|
+
end
|
35
|
+
|
36
|
+
def to_hash
|
37
|
+
@hash
|
38
|
+
end
|
39
|
+
|
40
|
+
def to_s
|
41
|
+
to_hash.to_s
|
42
|
+
end
|
43
|
+
|
44
|
+
def inspect
|
45
|
+
to_hash.inspect
|
46
|
+
end
|
47
|
+
|
48
|
+
def consumer_tag
|
49
|
+
@basic_deliver.consumer_tag
|
50
|
+
end
|
51
|
+
|
52
|
+
def deliver_tag
|
53
|
+
@basic_deliver.deliver_tag
|
54
|
+
end
|
55
|
+
|
56
|
+
def redelivered
|
57
|
+
@basic_deliver.redelivered
|
58
|
+
end
|
59
|
+
|
60
|
+
def exchange
|
61
|
+
@basic_deliver.exchange
|
62
|
+
end
|
63
|
+
|
64
|
+
def routing_key
|
65
|
+
@basic_deliver.routing_key
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
data/lib/bunny/exchange.rb
CHANGED
@@ -90,7 +90,7 @@ module Bunny
|
|
90
90
|
|
91
91
|
|
92
92
|
def publish(payload, opts = {})
|
93
|
-
@channel.basic_publish(payload, self.name, opts.delete(:routing_key), opts)
|
93
|
+
@channel.basic_publish(payload, self.name, (opts.delete(:routing_key) || opts.delete(:key)), opts)
|
94
94
|
|
95
95
|
self
|
96
96
|
end
|
@@ -105,15 +105,21 @@ module Bunny
|
|
105
105
|
|
106
106
|
def bind(source, opts = {})
|
107
107
|
@channel.exchange_bind(source, self, opts)
|
108
|
+
|
109
|
+
self
|
108
110
|
end
|
109
111
|
|
110
112
|
def unbind(source, opts = {})
|
111
113
|
@channel.exchange_unbind(source, self, opts)
|
114
|
+
|
115
|
+
self
|
112
116
|
end
|
113
117
|
|
114
118
|
|
115
119
|
def on_return(&block)
|
116
120
|
@on_return = block
|
121
|
+
|
122
|
+
self
|
117
123
|
end
|
118
124
|
|
119
125
|
|
@@ -1,7 +1,8 @@
|
|
1
1
|
module Bunny
|
2
|
-
#
|
3
|
-
#
|
4
|
-
|
2
|
+
# Wraps basic properties hash as returned by amq-protocol to
|
3
|
+
# provide access to the delivery properties as immutable hash as
|
4
|
+
# well as methods.
|
5
|
+
class MessageProperties
|
5
6
|
|
6
7
|
#
|
7
8
|
# Behaviors
|
@@ -13,30 +14,20 @@ module Bunny
|
|
13
14
|
# API
|
14
15
|
#
|
15
16
|
|
16
|
-
def initialize(
|
17
|
-
|
18
|
-
:consumer_tag => basic_deliver.consumer_tag,
|
19
|
-
:delivery_tag => basic_deliver.delivery_tag,
|
20
|
-
:redelivered => basic_deliver.redelivered,
|
21
|
-
:exchange => basic_deliver.exchange,
|
22
|
-
:routing_key => basic_deliver.routing_key
|
23
|
-
}
|
24
|
-
|
25
|
-
@basic_deliver = basic_deliver
|
26
|
-
@properties = properties
|
27
|
-
@combined = properties.merge(h)
|
17
|
+
def initialize(properties)
|
18
|
+
@properties = properties
|
28
19
|
end
|
29
20
|
|
30
21
|
def each(*args, &block)
|
31
|
-
@
|
22
|
+
@properties.each(*args, &block)
|
32
23
|
end
|
33
24
|
|
34
25
|
def [](k)
|
35
|
-
@
|
26
|
+
@properties[k]
|
36
27
|
end
|
37
28
|
|
38
29
|
def to_hash
|
39
|
-
@
|
30
|
+
@properties
|
40
31
|
end
|
41
32
|
|
42
33
|
def to_s
|
@@ -47,26 +38,6 @@ module Bunny
|
|
47
38
|
to_hash.inspect
|
48
39
|
end
|
49
40
|
|
50
|
-
def consumer_tag
|
51
|
-
@basic_deliver.consumer_tag
|
52
|
-
end
|
53
|
-
|
54
|
-
def deliver_tag
|
55
|
-
@basic_deliver.deliver_tag
|
56
|
-
end
|
57
|
-
|
58
|
-
def redelivered
|
59
|
-
@basic_deliver.redelivered
|
60
|
-
end
|
61
|
-
|
62
|
-
def exchange
|
63
|
-
@basic_deliver.exchange
|
64
|
-
end
|
65
|
-
|
66
|
-
def routing_key
|
67
|
-
@basic_deliver.routing_key
|
68
|
-
end
|
69
|
-
|
70
41
|
def content_type
|
71
42
|
@properties[:content_type]
|
72
43
|
end
|
data/lib/bunny/queue.rb
CHANGED
@@ -64,20 +64,27 @@ module Bunny
|
|
64
64
|
|
65
65
|
def bind(exchange, opts = {})
|
66
66
|
@channel.queue_bind(@name, exchange, opts)
|
67
|
+
|
68
|
+
self
|
67
69
|
end
|
68
70
|
|
69
71
|
def unbind(exchange, opts = {})
|
70
72
|
@channel.queue_unbind(@name, exchange, opts)
|
73
|
+
|
74
|
+
self
|
71
75
|
end
|
72
76
|
|
73
|
-
def subscribe(opts = {:consumer_tag => "", :ack => false, :exclusive => false}, &block)
|
77
|
+
def subscribe(opts = {:consumer_tag => "", :ack => false, :exclusive => false, :block => false}, &block)
|
74
78
|
@channel.basic_consume(@name, opts.fetch(:consumer_tag, ""), !opts[:ack], opts[:exclusive], opts[:arguments], &block)
|
75
79
|
|
76
|
-
|
77
|
-
|
80
|
+
if options[:block]
|
81
|
+
# joins current thread with the consumers pool, will block
|
82
|
+
# the current thread for as long as the consumer pool is active
|
83
|
+
@channel.work_pool.join
|
84
|
+
end
|
78
85
|
end
|
79
86
|
|
80
|
-
def pop(opts = {:ack =>
|
87
|
+
def pop(opts = {:ack => false}, &block)
|
81
88
|
delivery_info, properties, content = @channel.basic_get(@name, opts)
|
82
89
|
|
83
90
|
if block
|
@@ -88,6 +95,18 @@ module Bunny
|
|
88
95
|
end
|
89
96
|
alias get pop
|
90
97
|
|
98
|
+
def pop_as_hash(opts = {:ack => false}, &block)
|
99
|
+
delivery_info, properties, content = @channel.basic_get(@name, opts)
|
100
|
+
|
101
|
+
result = {:header => properties, :payload => content, :delivery_details => delivery_info}
|
102
|
+
|
103
|
+
if block
|
104
|
+
block.call(result)
|
105
|
+
else
|
106
|
+
result
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
91
110
|
|
92
111
|
# Deletes the queue
|
93
112
|
# @api public
|
@@ -97,6 +116,8 @@ module Bunny
|
|
97
116
|
|
98
117
|
def purge(opts = {})
|
99
118
|
@channel.queue_purge(@name, opts)
|
119
|
+
|
120
|
+
self
|
100
121
|
end
|
101
122
|
|
102
123
|
def status
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module Bunny
|
2
|
+
# Wraps AMQ::Protocol::Basic::Return to
|
3
|
+
# provide access to the delivery properties as immutable hash as
|
4
|
+
# well as methods.
|
5
|
+
class ReturnInfo
|
6
|
+
|
7
|
+
#
|
8
|
+
# Behaviors
|
9
|
+
#
|
10
|
+
|
11
|
+
include Enumerable
|
12
|
+
|
13
|
+
#
|
14
|
+
# API
|
15
|
+
#
|
16
|
+
|
17
|
+
def initialize(basic_return)
|
18
|
+
@basic_return = basic_return
|
19
|
+
@hash = {
|
20
|
+
:reply_code => basic_return.reply_code,
|
21
|
+
:reply_text => basic_return.reply_text,
|
22
|
+
:exchange => basic_return.exchange,
|
23
|
+
:routing_key => basic_return.routing_key
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
def each(*args, &block)
|
28
|
+
@hash.each(*args, &block)
|
29
|
+
end
|
30
|
+
|
31
|
+
def [](k)
|
32
|
+
@hash[k]
|
33
|
+
end
|
34
|
+
|
35
|
+
def to_hash
|
36
|
+
@hash
|
37
|
+
end
|
38
|
+
|
39
|
+
def to_s
|
40
|
+
to_hash.to_s
|
41
|
+
end
|
42
|
+
|
43
|
+
def inspect
|
44
|
+
to_hash.inspect
|
45
|
+
end
|
46
|
+
|
47
|
+
def reply_code
|
48
|
+
@basic_return.reply_code
|
49
|
+
end
|
50
|
+
|
51
|
+
def reply_text
|
52
|
+
@basic_return.reply_text
|
53
|
+
end
|
54
|
+
|
55
|
+
def exchange
|
56
|
+
@basic_return.exchange
|
57
|
+
end
|
58
|
+
|
59
|
+
def routing_key
|
60
|
+
@basic_return.routing_key
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/lib/bunny/session.rb
CHANGED
@@ -44,7 +44,7 @@ module Bunny
|
|
44
44
|
# API
|
45
45
|
#
|
46
46
|
|
47
|
-
attr_reader :status, :host, :port, :heartbeat, :user, :pass, :vhost, :frame_max
|
47
|
+
attr_reader :status, :host, :port, :heartbeat, :user, :pass, :vhost, :frame_max
|
48
48
|
attr_reader :server_capabilities, :server_properties, :server_authentication_mechanisms, :server_locales
|
49
49
|
attr_reader :default_channel
|
50
50
|
attr_reader :channel_id_allocator
|
@@ -105,11 +105,6 @@ module Bunny
|
|
105
105
|
@channel0
|
106
106
|
end
|
107
107
|
|
108
|
-
def channel
|
109
|
-
@default_channel
|
110
|
-
end
|
111
|
-
|
112
|
-
|
113
108
|
def start
|
114
109
|
@status = :connecting
|
115
110
|
|
@@ -133,6 +128,7 @@ module Bunny
|
|
133
128
|
ch
|
134
129
|
end
|
135
130
|
end
|
131
|
+
alias channel create_channel
|
136
132
|
|
137
133
|
def close
|
138
134
|
if @transport.open?
|
@@ -171,6 +167,36 @@ module Bunny
|
|
171
167
|
self.basic_qos(prefetch_count, true)
|
172
168
|
end
|
173
169
|
|
170
|
+
|
171
|
+
#
|
172
|
+
# Backwards compatibility
|
173
|
+
#
|
174
|
+
|
175
|
+
def queue(*args)
|
176
|
+
@default_channel.queue(*args)
|
177
|
+
end
|
178
|
+
|
179
|
+
def direct(*args)
|
180
|
+
@default_channel.direct(*args)
|
181
|
+
end
|
182
|
+
|
183
|
+
def fanout(*args)
|
184
|
+
@default_channel.fanout(*args)
|
185
|
+
end
|
186
|
+
|
187
|
+
def topic(*args)
|
188
|
+
@default_channel.topic(*args)
|
189
|
+
end
|
190
|
+
|
191
|
+
def headers(*args)
|
192
|
+
@default_channel.headers(*args)
|
193
|
+
end
|
194
|
+
|
195
|
+
def exchange(*args)
|
196
|
+
@default_channel.exchange(*args)
|
197
|
+
end
|
198
|
+
|
199
|
+
|
174
200
|
#
|
175
201
|
# Implementation
|
176
202
|
#
|
@@ -387,10 +413,6 @@ module Bunny
|
|
387
413
|
|
388
414
|
protected
|
389
415
|
|
390
|
-
def socket_open?
|
391
|
-
!@socket.nil? && !@socket.closed?
|
392
|
-
end
|
393
|
-
|
394
416
|
def init_connection
|
395
417
|
self.send_preamble
|
396
418
|
|
data/lib/bunny/transport.rb
CHANGED
@@ -39,6 +39,10 @@ module Bunny
|
|
39
39
|
end
|
40
40
|
|
41
41
|
|
42
|
+
def hostname
|
43
|
+
@host
|
44
|
+
end
|
45
|
+
|
42
46
|
def uses_tls?
|
43
47
|
@ssl
|
44
48
|
end
|
@@ -66,7 +70,7 @@ module Bunny
|
|
66
70
|
@socket.write(*args)
|
67
71
|
end
|
68
72
|
rescue Errno::EPIPE, Errno::EAGAIN, Bunny::ClientTimeout, IOError => e
|
69
|
-
close
|
73
|
+
close
|
70
74
|
raise Bunny::ConnectionError, e.message
|
71
75
|
end
|
72
76
|
end
|
data/lib/bunny/version.rb
CHANGED
@@ -21,8 +21,8 @@ describe Bunny::Queue, "#subscribe" do
|
|
21
21
|
t = Thread.new do
|
22
22
|
ch = connection.create_channel
|
23
23
|
q = ch.queue(queue_name, :auto_delete => true, :durable => false)
|
24
|
-
q.subscribe(:exclusive => false, :ack => false) do |
|
25
|
-
delivered_keys <<
|
24
|
+
q.subscribe(:exclusive => false, :ack => false) do |delivery_info, properties, payload|
|
25
|
+
delivered_keys << delivery_info.routing_key
|
26
26
|
delivered_data << payload
|
27
27
|
end
|
28
28
|
end
|
@@ -12,7 +12,7 @@ describe "A client-named", Bunny::Queue do
|
|
12
12
|
q = ch.queue("bunny.tests.queues.client-named#{rand}", :exclusive => true)
|
13
13
|
q.should_not be_server_named
|
14
14
|
|
15
|
-
q.bind("amq.fanout").should
|
15
|
+
q.bind("amq.fanout").should == q
|
16
16
|
|
17
17
|
ch.close
|
18
18
|
end
|
@@ -23,7 +23,7 @@ describe "A client-named", Bunny::Queue do
|
|
23
23
|
q.should_not be_server_named
|
24
24
|
|
25
25
|
q.bind("amq.fanout")
|
26
|
-
q.unbind("amq.fanout").should
|
26
|
+
q.unbind("amq.fanout").should == q
|
27
27
|
|
28
28
|
ch.close
|
29
29
|
end
|
@@ -33,7 +33,7 @@ describe "A client-named", Bunny::Queue do
|
|
33
33
|
q = ch.queue("bunny.tests.queues.client-named#{rand}", :exclusive => true)
|
34
34
|
|
35
35
|
x = ch.fanout("bunny.tests.exchanges.fanout#{rand}")
|
36
|
-
q.bind(x).should
|
36
|
+
q.bind(x).should == q
|
37
37
|
|
38
38
|
x.delete
|
39
39
|
ch.close
|
@@ -47,7 +47,7 @@ describe "A client-named", Bunny::Queue do
|
|
47
47
|
x = ch.fanout("bunny.tests.fanout", :auto_delete => true, :durable => false)
|
48
48
|
|
49
49
|
q.bind(x)
|
50
|
-
q.unbind(x).should
|
50
|
+
q.unbind(x).should == q
|
51
51
|
|
52
52
|
ch.close
|
53
53
|
end
|
@@ -67,7 +67,7 @@ describe "A server-named", Bunny::Queue do
|
|
67
67
|
q = ch.queue("", :exclusive => true)
|
68
68
|
q.should be_server_named
|
69
69
|
|
70
|
-
q.bind("amq.fanout").should
|
70
|
+
q.bind("amq.fanout").should == q
|
71
71
|
|
72
72
|
ch.close
|
73
73
|
end
|
@@ -78,7 +78,7 @@ describe "A server-named", Bunny::Queue do
|
|
78
78
|
q.should be_server_named
|
79
79
|
|
80
80
|
q.bind("amq.fanout")
|
81
|
-
q.unbind("amq.fanout").should
|
81
|
+
q.unbind("amq.fanout").should == q
|
82
82
|
|
83
83
|
ch.close
|
84
84
|
end
|
@@ -88,7 +88,7 @@ describe "A server-named", Bunny::Queue do
|
|
88
88
|
q = ch.queue("", :exclusive => true)
|
89
89
|
|
90
90
|
x = ch.fanout("bunny.tests.exchanges.fanout#{rand}")
|
91
|
-
q.bind(x).should
|
91
|
+
q.bind(x).should == q
|
92
92
|
|
93
93
|
x.delete
|
94
94
|
ch.close
|
@@ -101,7 +101,7 @@ describe "A server-named", Bunny::Queue do
|
|
101
101
|
name = "bunny.tests.exchanges.fanout#{rand}"
|
102
102
|
x = ch.fanout(name)
|
103
103
|
q.bind(x)
|
104
|
-
q.unbind(name).should
|
104
|
+
q.unbind(name).should == q
|
105
105
|
|
106
106
|
x.delete
|
107
107
|
ch.close
|
@@ -42,8 +42,8 @@ describe Bunny::Channel, "#basic_consume" do
|
|
42
42
|
t = Thread.new do
|
43
43
|
ch = connection.create_channel
|
44
44
|
q = ch.queue(queue_name, :auto_delete => true, :durable => false)
|
45
|
-
ch.basic_consume(q, "", true, false) do |
|
46
|
-
delivered_keys <<
|
45
|
+
ch.basic_consume(q, "", true, false) do |delivery_info, properties, payload|
|
46
|
+
delivered_keys << delivery_info.routing_key
|
47
47
|
delivered_data << payload
|
48
48
|
end
|
49
49
|
end
|
@@ -74,8 +74,8 @@ describe Bunny::Channel, "#basic_consume" do
|
|
74
74
|
t = Thread.new do
|
75
75
|
ch = connection.create_channel
|
76
76
|
q = ch.queue(queue_name, :auto_delete => true, :durable => false)
|
77
|
-
ch.basic_consume(q, "", false, false) do |
|
78
|
-
delivered_keys <<
|
77
|
+
ch.basic_consume(q, "", false, false) do |delivery_info, properties, payload|
|
78
|
+
delivered_keys << delivery_info.routing_key
|
79
79
|
delivered_data << payload
|
80
80
|
|
81
81
|
ch.close
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: bunny
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease: 6
|
5
|
-
version: 0.9.0.
|
5
|
+
version: 0.9.0.pre2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Chris Duncan
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2012-11-
|
17
|
+
date: 2012-11-30 00:00:00 Z
|
18
18
|
dependencies:
|
19
19
|
- !ruby/object:Gem::Dependency
|
20
20
|
name: amq-protocol
|
@@ -52,6 +52,9 @@ files:
|
|
52
52
|
- bin/ci/before_build.sh
|
53
53
|
- bunny.gemspec
|
54
54
|
- examples/connection/heartbeat.rb
|
55
|
+
- examples/guides/getting_started/blabbr.rb
|
56
|
+
- examples/guides/getting_started/hello_world.rb
|
57
|
+
- examples/guides/getting_started/weathr.rb
|
55
58
|
- lib/bunny.rb
|
56
59
|
- lib/bunny/channel.rb
|
57
60
|
- lib/bunny/channel_id_allocator.rb
|
@@ -60,13 +63,15 @@ files:
|
|
60
63
|
- lib/bunny/consumer.rb
|
61
64
|
- lib/bunny/consumer_tag_generator.rb
|
62
65
|
- lib/bunny/consumer_work_pool.rb
|
66
|
+
- lib/bunny/delivery_info.rb
|
63
67
|
- lib/bunny/exceptions.rb
|
64
68
|
- lib/bunny/exchange.rb
|
65
69
|
- lib/bunny/framing.rb
|
66
70
|
- lib/bunny/heartbeat_sender.rb
|
67
71
|
- lib/bunny/main_loop.rb
|
68
|
-
- lib/bunny/
|
72
|
+
- lib/bunny/message_properties.rb
|
69
73
|
- lib/bunny/queue.rb
|
74
|
+
- lib/bunny/return_info.rb
|
70
75
|
- lib/bunny/session.rb
|
71
76
|
- lib/bunny/socket.rb
|
72
77
|
- lib/bunny/system_timer.rb
|