amqp 0.8.0.rc13 → 0.8.0.rc14
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +2 -1
- data/.travis.yml +8 -2
- data/.yardopts +1 -0
- data/CHANGELOG +9 -0
- data/Gemfile +17 -11
- data/README.md +26 -16
- data/amqp.gemspec +2 -2
- data/bin/ci/before_build.sh +21 -0
- data/docs/08Migration.textile +199 -5
- data/docs/AMQP091ModelExplained.textile +322 -0
- data/docs/Bindings.textile +24 -4
- data/docs/Clustering.textile +1 -1
- data/docs/ConnectingToTheBroker.textile +98 -82
- data/docs/ConnectionEncryptionWithTLS.textile +65 -5
- data/docs/DocumentationGuidesIndex.textile +93 -13
- data/docs/Durability.textile +1 -1
- data/docs/ErrorHandling.textile +458 -94
- data/docs/Exchanges.textile +901 -87
- data/docs/GettingStarted.textile +278 -143
- data/docs/PatternsAndUseCases.textile +420 -0
- data/docs/Queues.textile +730 -178
- data/docs/RabbitMQVersions.textile +18 -3
- data/docs/RunningTests.textile +1 -1
- data/docs/TestingWithEventedSpec.textile +121 -0
- data/docs/Troubleshooting.textile +15 -1
- data/docs/VendorSpecificExtensions.textile +1 -1
- data/docs/diagrams/001_hello_world_example_routing.png +0 -0
- data/docs/diagrams/002_blabbr_example_routing.png +0 -0
- data/docs/diagrams/003_weathr_example_routing.png +0 -0
- data/docs/diagrams/004_fanout_exchange.png +0 -0
- data/docs/diagrams/005_direct_exchange.png +0 -0
- data/docs/diagrams/redhat/direct_exchange.png +0 -0
- data/docs/diagrams/redhat/fanout_exchange.png +0 -0
- data/docs/diagrams/redhat/topic_exchange.png +0 -0
- data/examples/error_handling/automatic_recovery_of_channel_and_queues.rb +50 -0
- data/examples/error_handling/automatically_recovering_hello_world_consumer.rb +51 -0
- data/examples/error_handling/automatically_recovering_hello_world_consumer_that_uses_a_server_named_queue.rb +51 -0
- data/examples/error_handling/basic_connection_failover.rb +22 -0
- data/examples/error_handling/channel_level_exception.rb +9 -2
- data/examples/error_handling/connection_level_exception.rb +8 -1
- data/examples/error_handling/connection_level_exception_with_objects.rb +49 -0
- data/examples/error_handling/connection_loss_handler.rb +1 -5
- data/examples/error_handling/hello_world_producer.rb +43 -0
- data/examples/error_handling/insufficient_permissions.rb +54 -0
- data/examples/error_handling/manual_connection_and_channel_recovery.rb +71 -0
- data/examples/error_handling/queue_exclusivity_violation.rb +41 -0
- data/examples/error_handling/queue_name_violation.rb +31 -0
- data/examples/exchanges/autodeletion_of_exchanges.rb +1 -4
- data/examples/guides/queues/01a_declaring_a_server_named_queue_using_queue_constructor.rb +7 -8
- data/examples/guides/queues/01b_declaring_a_queue_using_queue_constructor.rb +7 -8
- data/examples/guides/queues/02a_declaring_a_durable_shared_queue.rb +5 -8
- data/examples/guides/queues/02b_declaring_a_durable_shared_queue.rb +5 -8
- data/examples/guides/queues/03a_declaring_a_temporary_exclusive_queue.rb +7 -8
- data/examples/guides/queues/04_bind_a_queue_using_exchange_instance.rb +9 -10
- data/examples/guides/queues/05_bind_a_queue_using_exchange_name.rb +8 -10
- data/examples/guides/queues/06_subscribe_to_receive_messages.rb +10 -12
- data/examples/guides/queues/07_fetch_a_message_from_the_queue.rb +14 -14
- data/examples/guides/queues/08_unsubscribing_a_consumer.rb +13 -16
- data/examples/guides/queues/09_unbinding_from_exchange.rb +16 -22
- data/examples/guides/queues/10_purge_a_queue.rb +13 -18
- data/examples/guides/queues/11_deleting_a_queue.rb +14 -19
- data/examples/guides/queues/12_objects_that_consume_messages.rb +69 -0
- data/examples/guides/queues/13_objects_that_consume_messages_take_two.rb +89 -0
- data/examples/hello_world.rb +1 -3
- data/examples/hello_world_with_an_empty_string.rb +5 -6
- data/examples/inspecting_server_information.rb +45 -0
- data/examples/issues/issue_93.rb +23 -0
- data/examples/issues/issue_94.rb +23 -0
- data/examples/patterns/command/consumer.rb +45 -0
- data/examples/patterns/command/producer.rb +26 -0
- data/examples/patterns/request_reply/client.rb +29 -0
- data/examples/patterns/request_reply/server.rb +26 -0
- data/examples/publishing/publishing_a_one_off_message.rb +6 -4
- data/examples/publishing/returned_messages.rb +2 -10
- data/examples/queues/accessing_message_metadata.rb +15 -13
- data/examples/queues/queue_status.rb +12 -15
- data/examples/routing/fanout_routing.rb +33 -0
- data/examples/routing/headers_routing.rb +17 -15
- data/examples/routing/round_robin_with_direct_exchange.rb +39 -0
- data/examples/routing/round_robin_with_the_default_exchange.rb +38 -0
- data/examples/routing/unroutable_mandatory_message_is_returned.rb +33 -0
- data/examples/routing/weather_updates.rb +15 -20
- data/examples/tls/using_tls.rb +41 -0
- data/lib/amqp/bit_set.rb +80 -0
- data/lib/amqp/broker.rb +72 -0
- data/lib/amqp/channel.rb +93 -13
- data/lib/amqp/client.rb +11 -22
- data/lib/amqp/compatibility/ruby187_patchlevel_check.rb +2 -0
- data/lib/amqp/connection.rb +2 -3
- data/lib/amqp/consumer.rb +208 -0
- data/lib/amqp/deprecated/fork.rb +2 -0
- data/lib/amqp/deprecated/mq.rb +2 -0
- data/lib/amqp/exchange.rb +6 -4
- data/lib/amqp/extensions/rabbitmq.rb +3 -1
- data/lib/amqp/header.rb +76 -14
- data/lib/amqp/int_allocator.rb +96 -0
- data/lib/amqp/logger.rb +2 -0
- data/lib/amqp/queue.rb +242 -86
- data/lib/amqp/rpc.rb +2 -0
- data/lib/amqp/session.rb +169 -9
- data/lib/amqp/utilities/event_loop_helper.rb +2 -0
- data/lib/amqp/utilities/server_type.rb +2 -0
- data/lib/amqp/version.rb +2 -2
- data/lib/mq.rb +4 -2
- data/lib/mq/logger.rb +3 -1
- data/lib/mq/rpc.rb +3 -1
- data/spec/integration/authentication_spec.rb +17 -10
- data/spec/integration/automatic_binding_for_default_direct_exchange_spec.rb +1 -1
- data/spec/integration/automatic_recovery_predicate_spec.rb +68 -0
- data/spec/integration/basic_get_spec.rb +2 -1
- data/spec/integration/{extensions/basic_return_spec.rb → basic_return_spec.rb} +2 -1
- data/spec/integration/channel_level_exception_handling_spec.rb +53 -0
- data/spec/integration/connection_level_exception_handling_spec.rb +49 -0
- data/spec/integration/declare_and_immediately_bind_a_server_named_queue_spec.rb +38 -17
- data/spec/integration/declare_one_hundred_server_named_queues_spec.rb +44 -0
- data/spec/integration/direct_exchange_routing_spec.rb +125 -0
- data/spec/integration/exchange_declaration_spec.rb +75 -46
- data/spec/integration/extensions/rabbitmq/publisher_confirmations_spec.rb +180 -0
- data/spec/integration/{workload_distribution_spec.rb → fanout_exchange_routing_spec.rb} +10 -9
- data/spec/integration/headers_exchange_routing_spec.rb +269 -0
- data/spec/integration/hello_world_spec.rb +77 -0
- data/spec/integration/immediate_messages_spec.rb +59 -0
- data/spec/integration/mandatory_messages_spec.rb +52 -0
- data/spec/integration/message_metadata_access_spec.rb +106 -0
- data/spec/integration/multiple_consumers_per_queue_spec.rb +319 -0
- data/spec/integration/ordering_of_published_messages_spec.rb +96 -0
- data/spec/integration/queue_declaration_spec.rb +8 -8
- data/spec/integration/queue_status_spec.rb +66 -0
- data/spec/integration/recovery/per_channel_automatic_recovery_on_graceful_broker_shutdown_spec.rb +76 -0
- data/spec/integration/recovery/per_channel_automatic_recovery_spec.rb +72 -0
- data/spec/integration/redelivery_of_unacknowledged_messages_spec.rb +96 -0
- data/spec/integration/regressions/concurrent_publishing_on_the_same_channel_spec.rb +91 -0
- data/spec/integration/regressions/empty_message_body_spec.rb +56 -0
- data/spec/integration/regressions/issue66_spec.rb +2 -1
- data/spec/integration/reply_queue_communication_spec.rb +2 -1
- data/spec/integration/store_and_forward_spec.rb +4 -3
- data/spec/integration/topic_subscription_spec.rb +2 -1
- data/spec/integration/tx_commit_spec.rb +124 -0
- data/spec/integration/tx_rollback_spec.rb +167 -0
- data/spec/spec_helper.rb +44 -71
- data/spec/unit/amqp/bit_set_spec.rb +127 -0
- data/spec/unit/amqp/channel_id_allocation_spec.rb +40 -0
- data/spec/unit/amqp/connection_spec.rb +4 -2
- data/spec/unit/amqp/int_allocator_spec.rb +116 -0
- metadata +92 -26
- data/CONTRIBUTORS +0 -29
- data/docs/Routing.textile +0 -30
- data/examples/real-world/task-queue/README.textile +0 -3
- data/examples/real-world/task-queue/consumer.rb +0 -27
- data/examples/real-world/task-queue/producer.rb +0 -22
- data/spec/unit/amqp/basic_spec.rb +0 -39
- data/tasks.rb +0 -4
@@ -0,0 +1,49 @@
|
|
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
|
+
class ConnectionManager
|
13
|
+
|
14
|
+
#
|
15
|
+
# API
|
16
|
+
#
|
17
|
+
|
18
|
+
def connect(*args, &block)
|
19
|
+
@connection = AMQP.connect(*args, &block)
|
20
|
+
|
21
|
+
# combines Object#method and Method#to_proc to use object
|
22
|
+
# method as a callback
|
23
|
+
@connection.on_error(&method(:on_error))
|
24
|
+
end # connect(*args, &block)
|
25
|
+
|
26
|
+
|
27
|
+
def on_error(connection, connection_close)
|
28
|
+
puts "Handling a connection-level exception."
|
29
|
+
puts
|
30
|
+
puts "AMQP class id : #{connection_close.class_id}"
|
31
|
+
puts "AMQP method id: #{connection_close.method_id}"
|
32
|
+
puts "Status code : #{connection_close.reply_code}"
|
33
|
+
puts "Error message : #{connection_close.reply_text}"
|
34
|
+
end # on_error(connection, connection_close)
|
35
|
+
end
|
36
|
+
|
37
|
+
EventMachine.run do
|
38
|
+
manager = ConnectionManager.new
|
39
|
+
manager.connect(:host => '127.0.0.1', :port => 5672) do |connection|
|
40
|
+
puts "Connected to AMQP broker. Running #{AMQP::VERSION} version of the gem..."
|
41
|
+
|
42
|
+
# send_frame is NOT part of the public API, but it is public for entities like AMQ::Client::Channel
|
43
|
+
# and we use it here to trigger a connection-level exception. MK.
|
44
|
+
connection.send_frame(AMQ::Protocol::Connection::TuneOk.encode(1000, 1024 * 128 * 1024, 10))
|
45
|
+
end
|
46
|
+
|
47
|
+
# shut down after 2 seconds
|
48
|
+
EventMachine.add_timer(2) { EventMachine.stop }
|
49
|
+
end
|
@@ -25,15 +25,11 @@ AMQP.start(:port => 5672,
|
|
25
25
|
|
26
26
|
show_stopper = Proc.new do
|
27
27
|
$stdout.puts "Stopping..."
|
28
|
-
|
29
|
-
connection.close {
|
30
|
-
EM.stop { exit }
|
31
|
-
}
|
28
|
+
connection.close { EventMachine.stop }
|
32
29
|
end
|
33
30
|
|
34
31
|
puts "Connected, authenticated. To really exercise this example, shut AMQP broker down for a few seconds. If you don't it will exit gracefully in 30 seconds."
|
35
32
|
|
36
|
-
Signal.trap "TERM", show_stopper
|
37
33
|
Signal.trap "INT", show_stopper
|
38
34
|
EM.add_timer(30, show_stopper)
|
39
35
|
end
|
@@ -0,0 +1,43 @@
|
|
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
|
+
puts "=> Auxiliary script that tests automatically recovering message consumer(s)"
|
13
|
+
puts
|
14
|
+
AMQP.start(:host => "localhost") do |connection, open_ok|
|
15
|
+
connection.on_error do |ch, connection_close|
|
16
|
+
raise connection_close.reply_text
|
17
|
+
end
|
18
|
+
|
19
|
+
ch1 = AMQP::Channel.new(connection, 2)
|
20
|
+
ch1.on_error do |ch, channel_close|
|
21
|
+
raise channel_close.reply_text
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
exchange = ch1.fanout("amq.fanout", :durable => true)
|
26
|
+
EventMachine.add_periodic_timer(0.5) do
|
27
|
+
puts "Publishing..."
|
28
|
+
# messages must be routable & there must be at least one consumer.
|
29
|
+
exchange.publish("Hello", :immediate => true, :mandatory => true)
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
show_stopper = Proc.new {
|
34
|
+
connection.disconnect { puts "Disconnected. Exiting…"; EventMachine.stop }
|
35
|
+
}
|
36
|
+
|
37
|
+
Signal.trap "TERM", show_stopper
|
38
|
+
Signal.trap "INT", show_stopper
|
39
|
+
EM.add_timer(15, show_stopper)
|
40
|
+
|
41
|
+
puts "This example a helper that publishes messages to amq.fanout. Use together with examples/error_handling/automatically_recovering_hello_world_consumer.rb."
|
42
|
+
puts "This example terminates in 15 seconds and needs MANUAL RESTART when connection fails"
|
43
|
+
end
|
@@ -0,0 +1,54 @@
|
|
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
|
+
puts "=> Queue redeclaration with different attributes results in a channel exception that is handled"
|
13
|
+
puts
|
14
|
+
AMQP.start(:vhost => "amqp_gem_testbed", :username => "amqp_gem_reader", :password => "reader_password") do |connection, open_ok|
|
15
|
+
AMQP::Channel.new do |channel, open_ok|
|
16
|
+
puts "Channel ##{channel.id} is now open!"
|
17
|
+
|
18
|
+
channel.on_error do |ch, channel_close|
|
19
|
+
puts <<-ERR
|
20
|
+
Handling a channel-level exception.
|
21
|
+
|
22
|
+
AMQP class id : #{channel_close.class_id},
|
23
|
+
AMQP method id: #{channel_close.method_id},
|
24
|
+
Status code : #{channel_close.reply_code}
|
25
|
+
Error message : #{channel_close.reply_text}
|
26
|
+
ERR
|
27
|
+
end
|
28
|
+
|
29
|
+
EventMachine.add_timer(0.4) do
|
30
|
+
# these two definitions result in a race condition. For sake of this example,
|
31
|
+
# however, it does not matter. Whatever definition succeeds first, 2nd one will
|
32
|
+
# cause a channel-level exception (because attributes are not identical)
|
33
|
+
AMQP::Queue.new(channel, "amqpgem.examples.channel_exception", :auto_delete => true, :durable => false) do |queue|
|
34
|
+
puts "#{queue.name} is ready to go"
|
35
|
+
end
|
36
|
+
|
37
|
+
AMQP::Queue.new(channel, "amqpgem.examples.channel_exception", :auto_delete => true, :durable => true) do |queue|
|
38
|
+
puts "#{queue.name} is ready to go"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
show_stopper = Proc.new do
|
45
|
+
$stdout.puts "Stopping..."
|
46
|
+
|
47
|
+
connection.close {
|
48
|
+
EM.stop { exit }
|
49
|
+
}
|
50
|
+
end
|
51
|
+
|
52
|
+
Signal.trap "INT", show_stopper
|
53
|
+
EM.add_timer(2, show_stopper)
|
54
|
+
end
|
@@ -0,0 +1,71 @@
|
|
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
|
+
class ConnectionInterruptionHandler
|
13
|
+
|
14
|
+
#
|
15
|
+
# API
|
16
|
+
#
|
17
|
+
|
18
|
+
def handle(connection)
|
19
|
+
puts "[network failure] Connection #{connection} detected connection interruption"
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
puts "=> Example of AMQP connection & channel recovery API in action"
|
26
|
+
puts
|
27
|
+
AMQP.start(:host => "localhost") do |connection, open_ok|
|
28
|
+
unless connection.auto_recovering?
|
29
|
+
puts "Connection IS NOT auto-recovering..."
|
30
|
+
end
|
31
|
+
|
32
|
+
ch1 = AMQP::Channel.new(connection)
|
33
|
+
ch1.on_error do |ch, channel_close|
|
34
|
+
raise channel_close.reply_text
|
35
|
+
end
|
36
|
+
|
37
|
+
unless ch1.auto_recovering?
|
38
|
+
puts "Channel #{ch1.id} IS NOT auto-recovering"
|
39
|
+
end
|
40
|
+
ch1.on_connection_interruption do |c|
|
41
|
+
puts "[network failure] Channel #{c.id} reacted to connection interruption"
|
42
|
+
end
|
43
|
+
ch1.on_recovery do |c|
|
44
|
+
puts "[recovery] Channel #{c.id} has recovered"
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
connection.on_tcp_connection_loss do |conn, settings|
|
49
|
+
puts "[network failure] Trying to reconnect..."
|
50
|
+
conn.reconnect(false, 2)
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
handler = ConnectionInterruptionHandler.new
|
55
|
+
connection.on_connection_interruption(&handler.method(:handle))
|
56
|
+
|
57
|
+
connection.on_recovery do |conn, settings|
|
58
|
+
puts "[recovery] Connection has recovered"
|
59
|
+
end
|
60
|
+
|
61
|
+
show_stopper = Proc.new {
|
62
|
+
connection.disconnect { puts "Disconnected. Exiting…"; EventMachine.stop }
|
63
|
+
}
|
64
|
+
|
65
|
+
Signal.trap "TERM", show_stopper
|
66
|
+
Signal.trap "INT", show_stopper
|
67
|
+
EM.add_timer(30, show_stopper)
|
68
|
+
|
69
|
+
|
70
|
+
puts "Connected, authenticated. To really exercise this example, shut AMQP broker down for a few seconds. If you don't it will exit gracefully in 30 seconds."
|
71
|
+
end
|
@@ -0,0 +1,41 @@
|
|
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
|
+
puts "=> Queue exclusivity violation results "
|
13
|
+
puts
|
14
|
+
EventMachine.run do
|
15
|
+
connection1 = AMQP.connect("amqp://guest:guest@dev.rabbitmq.com")
|
16
|
+
channel1 = AMQP::Channel.new(connection1)
|
17
|
+
|
18
|
+
connection2 = AMQP.connect("amqp://guest:guest@dev.rabbitmq.com")
|
19
|
+
channel2 = AMQP::Channel.new(connection2)
|
20
|
+
|
21
|
+
channel1.on_error do |ch, close|
|
22
|
+
puts "Handling a channel-level exception on channel1: #{close.reply_text}, #{close.reply_code}"
|
23
|
+
end
|
24
|
+
channel2.on_error do |ch, close|
|
25
|
+
puts "Handling a channel-level exception on channel2: #{close.reply_text}, #{close.reply_code}"
|
26
|
+
end
|
27
|
+
|
28
|
+
name = "amqpgem.examples.queue"
|
29
|
+
channel1.queue(name, :auto_delete => true, :exclusive => true)
|
30
|
+
# declare a queue with the same name on a different connection
|
31
|
+
channel2.queue(name, :auto_delete => true, :exclusive => true)
|
32
|
+
|
33
|
+
|
34
|
+
EventMachine.add_timer(3.5) do
|
35
|
+
connection1.close {
|
36
|
+
connection2.close {
|
37
|
+
EventMachine.stop { exit }
|
38
|
+
}
|
39
|
+
}
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,31 @@
|
|
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
|
+
puts "=> Queue declaration uses name prefix amq.* reserved by the AMQP spec"
|
13
|
+
puts
|
14
|
+
AMQP.start("amqp://guest:guest@dev.rabbitmq.com:5672") do |connection, open_ok|
|
15
|
+
AMQP::Channel.new do |channel, open_ok|
|
16
|
+
puts "Channel ##{channel.id} is now open!"
|
17
|
+
|
18
|
+
channel.on_error do |ch, close|
|
19
|
+
puts "Handling a channel-level exception: #{close.reply_text}, code: #{close.reply_code}"
|
20
|
+
end
|
21
|
+
|
22
|
+
channel.queue("amq.queue")
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
EventMachine.add_timer(0.5) do
|
27
|
+
connection.close {
|
28
|
+
EventMachine.stop { exit }
|
29
|
+
}
|
30
|
+
end
|
31
|
+
end
|
@@ -26,10 +26,7 @@ AMQP.start(:host => 'localhost', :port => 5673) do |connection|
|
|
26
26
|
|
27
27
|
show_stopper = Proc.new do
|
28
28
|
$stdout.puts "Stopping..."
|
29
|
-
|
30
|
-
connection.close {
|
31
|
-
EM.stop { exit }
|
32
|
-
}
|
29
|
+
connection.close { EventMachine.stop }
|
33
30
|
end
|
34
31
|
|
35
32
|
Signal.trap "INT", show_stopper
|
@@ -4,15 +4,14 @@
|
|
4
4
|
require "rubygems"
|
5
5
|
require "amqp"
|
6
6
|
|
7
|
-
# Declaring a server-
|
7
|
+
# Declaring a queue with server-generated name using AMQP::Queue constructor
|
8
8
|
AMQP.start("amqp://guest:guest@dev.rabbitmq.com") do |connection, open_ok|
|
9
|
-
AMQP::Channel.new
|
10
|
-
|
11
|
-
|
9
|
+
channel = AMQP::Channel.new(connection)
|
10
|
+
AMQP::Queue.new(channel, "", :auto_delete => true) do |queue|
|
11
|
+
puts "#{queue.name} is ready to go."
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
end
|
13
|
+
connection.close {
|
14
|
+
EventMachine.stop { exit }
|
15
|
+
}
|
17
16
|
end
|
18
17
|
end
|
@@ -6,13 +6,12 @@ require "amqp"
|
|
6
6
|
|
7
7
|
# Declaring a queue with explicitly given name using AMQP::Queue constructor
|
8
8
|
AMQP.start("amqp://guest:guest@dev.rabbitmq.com") do |connection, open_ok|
|
9
|
-
AMQP::Channel.new
|
10
|
-
|
11
|
-
puts "#{queue.name} is ready to go."
|
9
|
+
channel = AMQP::Channel.new(connection)
|
10
|
+
queue = AMQP::Queue.new(channel, "images.resize", :auto_delete => true)
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
12
|
+
puts "#{queue.name} is ready to go."
|
13
|
+
|
14
|
+
connection.close {
|
15
|
+
EventMachine.stop { exit }
|
16
|
+
}
|
18
17
|
end
|
@@ -6,13 +6,10 @@ require "amqp"
|
|
6
6
|
|
7
7
|
# Declaring a durable shared queue
|
8
8
|
AMQP.start("amqp://guest:guest@dev.rabbitmq.com") do |connection, open_ok|
|
9
|
-
AMQP::Channel.new
|
10
|
-
|
11
|
-
puts "#{queue.name} is ready to go."
|
9
|
+
channel = AMQP::Channel.new(connection)
|
10
|
+
queue = AMQP::Queue.new(channel, "images.resize", :durable => true)
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
end
|
17
|
-
end
|
12
|
+
connection.close {
|
13
|
+
EventMachine.stop { exit }
|
14
|
+
}
|
18
15
|
end
|
@@ -6,13 +6,10 @@ require "amqp"
|
|
6
6
|
|
7
7
|
# Declaring a durable shared queue using AMQP::Channel#queue method
|
8
8
|
AMQP.start("amqp://guest:guest@dev.rabbitmq.com") do |connection, open_ok|
|
9
|
-
AMQP::Channel.new
|
10
|
-
|
11
|
-
puts "#{queue.name} is ready to go."
|
9
|
+
channel = AMQP::Channel.new(connection)
|
10
|
+
queue = channel.queue("images.resize", :durable => true)
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
end
|
17
|
-
end
|
12
|
+
connection.close {
|
13
|
+
EventMachine.stop { exit }
|
14
|
+
}
|
18
15
|
end
|
@@ -6,14 +6,13 @@ require "amqp"
|
|
6
6
|
|
7
7
|
# Declaring a temporary exclusive queue
|
8
8
|
AMQP.start("amqp://guest:guest@dev.rabbitmq.com") do |connection, open_ok|
|
9
|
-
AMQP::Channel.new
|
10
|
-
AMQP::Queue.new(channel, "", :auto_delete => true, :exclusive => true) do |queue, declare_ok|
|
11
|
-
puts "#{queue.name} is ready to go."
|
9
|
+
channel = AMQP::Channel.new(connection)
|
12
10
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
11
|
+
AMQP::Queue.new(channel, "", :auto_delete => true, :exclusive => true) do |queue, declare_ok|
|
12
|
+
puts "#{queue.name} is ready to go."
|
13
|
+
|
14
|
+
connection.close {
|
15
|
+
EventMachine.stop { exit }
|
16
|
+
}
|
17
17
|
end
|
18
18
|
end
|
19
|
-
|
@@ -6,17 +6,16 @@ require "amqp"
|
|
6
6
|
|
7
7
|
# Binding a queue to an exchange
|
8
8
|
AMQP.start("amqp://guest:guest@dev.rabbitmq.com") do |connection, open_ok|
|
9
|
-
AMQP::Channel.new
|
10
|
-
|
9
|
+
channel = AMQP::Channel.new(connection)
|
10
|
+
exchange = channel.fanout("amq.fanout")
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
end
|
16
|
-
|
17
|
-
connection.close {
|
18
|
-
EventMachine.stop { exit }
|
19
|
-
}
|
12
|
+
channel.queue("", :auto_delete => true, :exclusive => true) do |queue, declare_ok|
|
13
|
+
queue.bind(exchange) do |bind_ok|
|
14
|
+
puts "Just bound #{queue.name} to #{exchange.name}"
|
20
15
|
end
|
16
|
+
|
17
|
+
connection.close {
|
18
|
+
EventMachine.stop { exit }
|
19
|
+
}
|
21
20
|
end
|
22
21
|
end
|