amqp 0.8.0.rc7 → 0.8.0.rc8
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/CHANGELOG +1 -0
- data/examples/guides/getting_started/02_hello_world_dslified.rb +1 -1
- data/examples/publishing/simplistic_scatter_gather.rb +70 -0
- data/lib/amqp/exchange.rb +13 -9
- data/lib/amqp/utilities/event_loop_helper.rb +48 -0
- data/lib/amqp/utilities/server_type.rb +50 -0
- data/lib/amqp/version.rb +1 -1
- metadata +70 -81
data/CHANGELOG
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
= Version 0.8.0
|
2
2
|
|
3
|
+
* [WIP] AMQP::Utilities::EventLoopHelper detects app server (if any) being used and starts EventMachine reactor in an optimal way.
|
3
4
|
* [FEATURE] AMQP 0.9.1 support, including tx.* operations class.
|
4
5
|
* [API] Default authentication handler now raises AMQP::PossibleAuthenticationFailureError
|
5
6
|
* [API] AMQP::Channel#initialize now takes 3rd (optional) options hash.
|
@@ -0,0 +1,70 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
require "bundler"
|
5
|
+
Bundler.setup
|
6
|
+
|
7
|
+
$:.unshift(File.expand_path("../../../lib", __FILE__))
|
8
|
+
|
9
|
+
require 'amqp'
|
10
|
+
|
11
|
+
|
12
|
+
AMQP.start do |session|
|
13
|
+
ch = AMQP::Channel.new(session)
|
14
|
+
exchange = ch.fanout("amq.fanout")
|
15
|
+
reply_exchange = ch.default_exchange
|
16
|
+
|
17
|
+
ch.queue("", :exclusive => true) do |q1|
|
18
|
+
q1.bind(exchange).subscribe do |header, payload|
|
19
|
+
v = rand
|
20
|
+
|
21
|
+
puts "Replying to #{header.message_id} with #{v}"
|
22
|
+
reply_exchange.publish(v, :routing_key => header.reply_to, :message_id => header.message_id)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
ch.queue("", :exclusive => true) do |q2|
|
26
|
+
q2.bind(exchange).subscribe do |header, payload|
|
27
|
+
v = rand
|
28
|
+
|
29
|
+
puts "Replying to #{header.message_id} with #{v}"
|
30
|
+
reply_exchange.publish(v, :routing_key => header.reply_to, :message_id => header.message_id)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
ch.queue("", :exclusive => true) do |q3|
|
34
|
+
q3.bind(exchange).subscribe do |header, payload|
|
35
|
+
v = rand
|
36
|
+
|
37
|
+
puts "Replying to #{header.message_id} with #{v}"
|
38
|
+
reply_exchange.publish(v, :routing_key => header.reply_to, :message_id => header.message_id)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
requests = Hash.new
|
44
|
+
|
45
|
+
EventMachine.add_timer(0.5) do
|
46
|
+
ch.queue("", :exlusive => true) do |q|
|
47
|
+
q.subscribe do |header, payload|
|
48
|
+
requests[header.message_id].push(payload)
|
49
|
+
|
50
|
+
puts "Got a reply for #{header.message_id}"
|
51
|
+
|
52
|
+
if requests[header.message_id].size == 3
|
53
|
+
puts "Gathered all 3 responses: #{requests[header.message_id].join(', ')}"
|
54
|
+
requests[header.message_id].clear
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
message_id = "__message #{rand}__"
|
60
|
+
requests[message_id] = Array.new
|
61
|
+
|
62
|
+
exchange.publish("a request", :reply_to => q.name, :message_id => message_id)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
EventMachine.add_timer(2) do
|
68
|
+
session.close { EventMachine.stop }
|
69
|
+
end
|
70
|
+
end
|
data/lib/amqp/exchange.rb
CHANGED
@@ -331,17 +331,21 @@ module AMQP
|
|
331
331
|
unless name == "amq.#{type}" or name.empty? or opts[:no_declare]
|
332
332
|
@status = :opening
|
333
333
|
|
334
|
-
shim = Proc.new do |exchange, declare_ok|
|
335
|
-
case block.arity
|
336
|
-
when 1 then block.call(exchange)
|
337
|
-
else
|
338
|
-
block.call(exchange, declare_ok)
|
339
|
-
end
|
340
|
-
end
|
341
|
-
|
342
334
|
unless @opts[:no_declare]
|
343
335
|
@channel.once_open do
|
344
|
-
|
336
|
+
if block
|
337
|
+
shim = Proc.new do |exchange, declare_ok|
|
338
|
+
case block.arity
|
339
|
+
when 1 then block.call(exchange)
|
340
|
+
else
|
341
|
+
block.call(exchange, declare_ok)
|
342
|
+
end
|
343
|
+
end
|
344
|
+
|
345
|
+
self.declare(passive = @opts[:passive], durable = @opts[:durable], auto_delete = @opts[:auto_delete], nowait = @opts[:nowait], @opts[:arguments], &shim)
|
346
|
+
else
|
347
|
+
self.declare(passive = @opts[:passive], durable = @opts[:durable], auto_delete = @opts[:auto_delete], nowait = @opts[:nowait], @opts[:arguments])
|
348
|
+
end
|
345
349
|
end
|
346
350
|
end
|
347
351
|
else
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require "eventmachine"
|
2
|
+
require "amqp/utilities/server_type"
|
3
|
+
|
4
|
+
module AMQP
|
5
|
+
module Utilities
|
6
|
+
class EventLoopHelper
|
7
|
+
|
8
|
+
def self.eventmachine_thread
|
9
|
+
@eventmachine_thread
|
10
|
+
end # self.eventmachine_thread
|
11
|
+
|
12
|
+
def self.reactor_running?
|
13
|
+
EventMachine.reactor_running?
|
14
|
+
end # self.reactor_running?
|
15
|
+
|
16
|
+
def self.server_type
|
17
|
+
@server_type ||= ServerType.detect
|
18
|
+
end # self.server_type
|
19
|
+
|
20
|
+
def self.run(in_a_worker_process = false)
|
21
|
+
# TODO: make reentrant
|
22
|
+
|
23
|
+
@eventmachine_thread = case self.server_type
|
24
|
+
when :thin, :goliath, :evented_mongrel then
|
25
|
+
Thread.current
|
26
|
+
when :unicorn, :passenger then
|
27
|
+
EventMachine.stop if in_a_worker_process
|
28
|
+
|
29
|
+
t = Thread.new { EventMachine.run }
|
30
|
+
# give EventMachine reactor some time to start
|
31
|
+
sleep(0.25)
|
32
|
+
|
33
|
+
t
|
34
|
+
when :mongrel, :scgi, :webrick, nil then
|
35
|
+
t = Thread.new { EventMachine.run }
|
36
|
+
# give EventMachine reactor some time to start
|
37
|
+
sleep(0.25)
|
38
|
+
|
39
|
+
t
|
40
|
+
end
|
41
|
+
end # self.run
|
42
|
+
|
43
|
+
def self.stop
|
44
|
+
EventMachine.stop
|
45
|
+
end
|
46
|
+
end # EventLoopHelper
|
47
|
+
end # Utilities
|
48
|
+
end # AMQP
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# Original version is from Qusion project by Daniel DeLeo.
|
2
|
+
#
|
3
|
+
# Copyright (c) 2009 Daniel DeLeo
|
4
|
+
# Copyright (c) 2011 Michael Klishin
|
5
|
+
#
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
# of this software and associated documentation files (the "Software"), to deal
|
8
|
+
# in the Software without restriction, including without limitation the rights
|
9
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
# copies of the Software, and to permit persons to whom the Software is
|
11
|
+
# furnished to do so, subject to the following conditions:
|
12
|
+
#
|
13
|
+
# The above copyright notice and this permission notice shall be included in
|
14
|
+
# all copies or substantial portions of the Software.
|
15
|
+
#
|
16
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22
|
+
# THE SOFTWARE.
|
23
|
+
|
24
|
+
module AMQP
|
25
|
+
module Utilities
|
26
|
+
class ServerType
|
27
|
+
def self.detect
|
28
|
+
if defined?(::PhusionPassenger)
|
29
|
+
:passenger
|
30
|
+
elsif defined?(::Unicorn)
|
31
|
+
:unicorn
|
32
|
+
elsif defined?(::Thin)
|
33
|
+
:thin
|
34
|
+
elsif defined?(::Goliath)
|
35
|
+
:goliath
|
36
|
+
elsif defined?(::Mongrel) && defined?(::Mongrel::MongrelProtocol)
|
37
|
+
:evented_mongrel
|
38
|
+
elsif defined?(::Mongrel)
|
39
|
+
:mongrel
|
40
|
+
elsif defined?(::SCGI)
|
41
|
+
:scgi
|
42
|
+
elsif defined?(::WEBrick)
|
43
|
+
:webrick
|
44
|
+
else
|
45
|
+
nil
|
46
|
+
end # if
|
47
|
+
end # self.detect
|
48
|
+
end # ServerType
|
49
|
+
end # Utilities
|
50
|
+
end # AMQP
|
data/lib/amqp/version.rb
CHANGED
metadata
CHANGED
@@ -1,49 +1,65 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: amqp
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 977940489
|
5
|
+
prerelease: true
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 8
|
9
|
+
- 0
|
10
|
+
- rc8
|
11
|
+
version: 0.8.0.rc8
|
6
12
|
platform: ruby
|
7
|
-
authors:
|
13
|
+
authors:
|
8
14
|
- Aman Gupta
|
9
15
|
- Jakub Stastny aka botanicus
|
10
16
|
- Michael S. Klishin
|
11
17
|
autorequire:
|
12
18
|
bindir: bin
|
13
19
|
cert_chain:
|
14
|
-
date: 2011-05-
|
20
|
+
date: 2011-05-09 00:00:00 +04:00
|
15
21
|
default_executable:
|
16
|
-
dependencies:
|
17
|
-
- !ruby/object:Gem::Dependency
|
22
|
+
dependencies:
|
23
|
+
- !ruby/object:Gem::Dependency
|
18
24
|
name: eventmachine
|
19
|
-
|
25
|
+
prerelease: false
|
26
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
27
|
none: false
|
21
|
-
requirements:
|
22
|
-
- -
|
23
|
-
- !ruby/object:Gem::Version
|
24
|
-
|
28
|
+
requirements:
|
29
|
+
- - ">="
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
hash: 3
|
32
|
+
segments:
|
33
|
+
- 0
|
34
|
+
version: "0"
|
25
35
|
type: :runtime
|
26
|
-
|
27
|
-
|
28
|
-
- !ruby/object:Gem::Dependency
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
29
38
|
name: amq-client
|
30
|
-
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
31
41
|
none: false
|
32
|
-
requirements:
|
33
|
-
- -
|
34
|
-
- !ruby/object:Gem::Version
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 1369095468
|
46
|
+
segments:
|
47
|
+
- 0
|
48
|
+
- 7
|
49
|
+
- 0
|
50
|
+
- alpha20
|
35
51
|
version: 0.7.0.alpha20
|
36
52
|
type: :runtime
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
included
|
41
|
-
email:
|
53
|
+
version_requirements: *id002
|
54
|
+
description: Widely used, feature-rich asynchronous AMQP 0.9.1 client with batteries included
|
55
|
+
email:
|
42
56
|
- michael@novemberain.com
|
43
57
|
- stastny@101ideas.cz
|
44
58
|
executables: []
|
59
|
+
|
45
60
|
extensions: []
|
46
|
-
|
61
|
+
|
62
|
+
extra_rdoc_files:
|
47
63
|
- README.textile
|
48
64
|
- docs/08Migration.textile
|
49
65
|
- docs/Bindings.textile
|
@@ -59,7 +75,7 @@ extra_rdoc_files:
|
|
59
75
|
- docs/RabbitMQVersions.textile
|
60
76
|
- docs/Routing.textile
|
61
77
|
- docs/VendorSpecificExtensions.textile
|
62
|
-
files:
|
78
|
+
files:
|
63
79
|
- .gitignore
|
64
80
|
- .rspec
|
65
81
|
- .travis.yml
|
@@ -129,6 +145,7 @@ files:
|
|
129
145
|
- examples/legacy/primes.rb
|
130
146
|
- examples/legacy/stocks.rb
|
131
147
|
- examples/publishing/publishing_and_immediately_stopping_event_loop.rb
|
148
|
+
- examples/publishing/simplistic_scatter_gather.rb
|
132
149
|
- examples/queues/automatic_binding_for_default_direct_exchange.rb
|
133
150
|
- examples/queues/basic_get.rb
|
134
151
|
- examples/queues/declare_a_queue_without_assignment.rb
|
@@ -177,6 +194,8 @@ files:
|
|
177
194
|
- lib/amqp/queue.rb
|
178
195
|
- lib/amqp/rpc.rb
|
179
196
|
- lib/amqp/session.rb
|
197
|
+
- lib/amqp/utilities/event_loop_helper.rb
|
198
|
+
- lib/amqp/utilities/server_type.rb
|
180
199
|
- lib/amqp/version.rb
|
181
200
|
- lib/mq.rb
|
182
201
|
- lib/mq/logger.rb
|
@@ -204,68 +223,38 @@ files:
|
|
204
223
|
has_rdoc: true
|
205
224
|
homepage: http://github.com/ruby-amqp/amqp
|
206
225
|
licenses: []
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
[API] AMQP::Channel#initialize now takes 3rd (optional) options hash.\n[\e[32mVersion
|
211
|
-
0.8.0\e[0m] [API] Broker connection class is now AMQP::Session.\n[\e[32mVersion
|
212
|
-
0.8.0\e[0m] [API] AMQP::Error instance now may carry cause, an exception that caused
|
213
|
-
exception in question to be raised.\n[\e[32mVersion 0.8.0\e[0m] [API] When initial
|
214
|
-
TCP connection fails, default action is now to raise AMQP::TCPConnectionFailed.\n[\e[32mVersion
|
215
|
-
0.8.0\e[0m] [API] AMQP::BasicClient#reconnect now takes 2nd optional argument, period
|
216
|
-
of waiting in seconds.\n[\e[32mVersion 0.8.0\e[0m] [FEATURE] Handlers for initial
|
217
|
-
connection failure, connection loss; channel-level exceptions handlers on Channel
|
218
|
-
instances.\n[\e[32mVersion 0.8.0\e[0m] [API] AMQP::Exchange#initialize now accepts
|
219
|
-
:arguments option that takes a hash.\n[\e[32mVersion 0.8.0\e[0m] [API] AMQP::Queue#initialize
|
220
|
-
now accepts :arguments option that takes a hash.\n[\e[32mVersion 0.8.0\e[0m] [API]
|
221
|
-
AMQP#Logger is deprecated. It will be removed before 1.0 release.\n[\e[32mVersion
|
222
|
-
0.8.0\e[0m] [API] AMQP#fork is deprecated. It will be removed before 1.0 release.\n[\e[32mVersion
|
223
|
-
0.8.0\e[0m] [API] AMQP::RPC is deprecated. It will be removed before 1.0 release.\n[\e[32mVersion
|
224
|
-
0.8.0\e[0m] [FEATURE] Significant improvements to the documentation. From now on
|
225
|
-
lack of/poor documentation is considered a severe bug.\n[\e[32mVersion 0.8.0\e[0m]
|
226
|
-
[FEATURE] Support for RabbitMQ extensions to AMQP 0.9.1\n[\e[32mVersion 0.8.0\e[0m]
|
227
|
-
[API] AMQP::Exchange#publish now accepts (an optional) callback.\n[\e[32mVersion
|
228
|
-
0.8.0\e[0m] [API] AMQP::Channel.new now accepts (an optional) callback.\n[\e[32mVersion
|
229
|
-
0.8.0\e[0m] [API] AMQP::Header#ack now can acknowledge multiple deliveries\n[\e[32mVersion
|
230
|
-
0.8.0\e[0m] [API] AMQP::Exchange#delete now takes (an optional) block that is called
|
231
|
-
when exchange.delete-ok response arrives.\n[\e[32mVersion 0.8.0\e[0m] [API] AMQP::Header
|
232
|
-
now implements #to_hash\n[\e[32mVersion 0.8.0\e[0m] [API] AMQP::Queue#pop block
|
233
|
-
now can take 1, 2 or 3 arguments.\n[\e[32mVersion 0.8.0\e[0m] [API] AMQP::Queue#purge
|
234
|
-
\ now takes an optional block which is called when queue.purge-ok response arrives.\n[\e[32mVersion
|
235
|
-
0.8.0\e[0m] [API] AMQP::Queue#delete now takes an optional block which is called
|
236
|
-
when queue.delete-ok response arrives.\n[\e[32mVersion 0.8.0\e[0m] [API] AMQP::Queue#delete
|
237
|
-
now accepts :nowait option.\n[\e[32mVersion 0.8.0\e[0m] [API] AMQP::Queue#unbind
|
238
|
-
now takes an optional block which is called when queue.unbind-ok response arrives.\n[\e[32mVersion
|
239
|
-
0.8.0\e[0m] [API] AMQP::Queue#unbind now accepts :routing_key as alias to :key.
|
240
|
-
we believe it is a good idea to use AMQP terms.\n[\e[32mVersion 0.8.0\e[0m] [API]
|
241
|
-
AMQP::Channel#prefetch now takes (an optional) 2nd parameter that specifies that
|
242
|
-
QoS settings should be applied to underlying connection, as well as optional callback.\n[\e[32mVersion
|
243
|
-
0.8.0\e[0m] [API] AMQP::Channel#recover now takes (an optional) callback that is
|
244
|
-
called when basic.recover-ok is received.\n[\e[32mVersion 0.8.0\e[0m] [API] AMQP::Frame
|
245
|
-
is gone.\n[\e[32mVersion 0.8.0\e[0m] [API] AMQP::Buffer is gone. Serialization &
|
246
|
-
framing are now handled primarily by amq-protocol.\n[\e[32mVersion 0.8.0\e[0m] [API]
|
247
|
-
AMQP::Queue#publish is deprecated.\n[\e[32mVersion 0.8.0\e[0m] [API] Name argument
|
248
|
-
for AMQP::Queue.new and Channel#queue is optional.\n"
|
249
|
-
rdoc_options:
|
226
|
+
|
227
|
+
post_install_message:
|
228
|
+
rdoc_options:
|
250
229
|
- --include=examples --main README.textile
|
251
|
-
require_paths:
|
230
|
+
require_paths:
|
252
231
|
- lib
|
253
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
232
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
254
233
|
none: false
|
255
|
-
requirements:
|
256
|
-
- -
|
257
|
-
- !ruby/object:Gem::Version
|
258
|
-
|
259
|
-
|
234
|
+
requirements:
|
235
|
+
- - ">="
|
236
|
+
- !ruby/object:Gem::Version
|
237
|
+
hash: 3
|
238
|
+
segments:
|
239
|
+
- 0
|
240
|
+
version: "0"
|
241
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
260
242
|
none: false
|
261
|
-
requirements:
|
262
|
-
- -
|
263
|
-
- !ruby/object:Gem::Version
|
243
|
+
requirements:
|
244
|
+
- - ">"
|
245
|
+
- !ruby/object:Gem::Version
|
246
|
+
hash: 25
|
247
|
+
segments:
|
248
|
+
- 1
|
249
|
+
- 3
|
250
|
+
- 1
|
264
251
|
version: 1.3.1
|
265
252
|
requirements: []
|
253
|
+
|
266
254
|
rubyforge_project: amqp
|
267
|
-
rubygems_version: 1.
|
255
|
+
rubygems_version: 1.3.7
|
268
256
|
signing_key:
|
269
257
|
specification_version: 3
|
270
258
|
summary: AMQP client implementation in Ruby/EventMachine.
|
271
259
|
test_files: []
|
260
|
+
|