amq-client 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +8 -0
- data/.gitmodules +9 -0
- data/.rspec +2 -0
- data/.travis.yml +7 -0
- data/.yardopts +1 -0
- data/CONTRIBUTORS +3 -0
- data/Gemfile +27 -0
- data/LICENSE +20 -0
- data/README.textile +61 -0
- data/amq-client.gemspec +34 -0
- data/bin/jenkins.sh +23 -0
- data/bin/set_test_suite_realms_up.sh +24 -0
- data/examples/coolio_adapter/basic_consume.rb +49 -0
- data/examples/coolio_adapter/basic_consume_with_acknowledgements.rb +43 -0
- data/examples/coolio_adapter/basic_consume_with_rejections.rb +43 -0
- data/examples/coolio_adapter/basic_publish.rb +35 -0
- data/examples/coolio_adapter/channel_close.rb +24 -0
- data/examples/coolio_adapter/example_helper.rb +39 -0
- data/examples/coolio_adapter/exchange_declare.rb +28 -0
- data/examples/coolio_adapter/kitchen_sink1.rb +48 -0
- data/examples/coolio_adapter/queue_bind.rb +32 -0
- data/examples/coolio_adapter/queue_purge.rb +32 -0
- data/examples/coolio_adapter/queue_unbind.rb +37 -0
- data/examples/eventmachine_adapter/authentication/plain_password_with_custom_role_credentials.rb +36 -0
- data/examples/eventmachine_adapter/authentication/plain_password_with_default_role_credentials.rb +27 -0
- data/examples/eventmachine_adapter/authentication/plain_password_with_incorrect_credentials.rb +18 -0
- data/examples/eventmachine_adapter/basic_cancel.rb +49 -0
- data/examples/eventmachine_adapter/basic_consume.rb +51 -0
- data/examples/eventmachine_adapter/basic_consume_with_acknowledgements.rb +45 -0
- data/examples/eventmachine_adapter/basic_consume_with_rejections.rb +45 -0
- data/examples/eventmachine_adapter/basic_get.rb +57 -0
- data/examples/eventmachine_adapter/basic_get_with_empty_queue.rb +53 -0
- data/examples/eventmachine_adapter/basic_publish.rb +38 -0
- data/examples/eventmachine_adapter/basic_qos.rb +29 -0
- data/examples/eventmachine_adapter/basic_recover.rb +29 -0
- data/examples/eventmachine_adapter/basic_return.rb +34 -0
- data/examples/eventmachine_adapter/channel_close.rb +24 -0
- data/examples/eventmachine_adapter/channel_flow.rb +36 -0
- data/examples/eventmachine_adapter/channel_level_exception_handling.rb +44 -0
- data/examples/eventmachine_adapter/example_helper.rb +39 -0
- data/examples/eventmachine_adapter/exchange_declare.rb +54 -0
- data/examples/eventmachine_adapter/extensions/rabbitmq/handling_confirm_select_ok.rb +31 -0
- data/examples/eventmachine_adapter/extensions/rabbitmq/publisher_confirmations_with_transient_messages.rb +56 -0
- data/examples/eventmachine_adapter/extensions/rabbitmq/publisher_confirmations_with_unroutable_message.rb +46 -0
- data/examples/eventmachine_adapter/kitchen_sink1.rb +50 -0
- data/examples/eventmachine_adapter/queue_bind.rb +32 -0
- data/examples/eventmachine_adapter/queue_declare.rb +34 -0
- data/examples/eventmachine_adapter/queue_purge.rb +32 -0
- data/examples/eventmachine_adapter/queue_unbind.rb +37 -0
- data/examples/eventmachine_adapter/tx_commit.rb +29 -0
- data/examples/eventmachine_adapter/tx_rollback.rb +29 -0
- data/examples/eventmachine_adapter/tx_select.rb +27 -0
- data/examples/socket_adapter/basics.rb +19 -0
- data/examples/socket_adapter/connection.rb +53 -0
- data/examples/socket_adapter/multiple_connections.rb +17 -0
- data/irb.rb +66 -0
- data/lib/amq/client.rb +15 -0
- data/lib/amq/client/adapter.rb +356 -0
- data/lib/amq/client/adapters/coolio.rb +221 -0
- data/lib/amq/client/adapters/event_machine.rb +228 -0
- data/lib/amq/client/adapters/socket.rb +89 -0
- data/lib/amq/client/channel.rb +338 -0
- data/lib/amq/client/connection.rb +246 -0
- data/lib/amq/client/entity.rb +117 -0
- data/lib/amq/client/exceptions.rb +86 -0
- data/lib/amq/client/exchange.rb +163 -0
- data/lib/amq/client/extensions/rabbitmq.rb +5 -0
- data/lib/amq/client/extensions/rabbitmq/basic.rb +36 -0
- data/lib/amq/client/extensions/rabbitmq/confirm.rb +254 -0
- data/lib/amq/client/framing/io/frame.rb +32 -0
- data/lib/amq/client/framing/string/frame.rb +62 -0
- data/lib/amq/client/logging.rb +56 -0
- data/lib/amq/client/mixins/anonymous_entity.rb +21 -0
- data/lib/amq/client/mixins/status.rb +62 -0
- data/lib/amq/client/protocol/get_response.rb +55 -0
- data/lib/amq/client/queue.rb +450 -0
- data/lib/amq/client/settings.rb +83 -0
- data/lib/amq/client/version.rb +5 -0
- data/spec/benchmarks/adapters.rb +77 -0
- data/spec/client/framing/io_frame_spec.rb +57 -0
- data/spec/client/framing/string_frame_spec.rb +57 -0
- data/spec/client/protocol/get_response_spec.rb +79 -0
- data/spec/integration/coolio/basic_ack_spec.rb +41 -0
- data/spec/integration/coolio/basic_get_spec.rb +73 -0
- data/spec/integration/coolio/basic_return_spec.rb +33 -0
- data/spec/integration/coolio/channel_close_spec.rb +26 -0
- data/spec/integration/coolio/channel_flow_spec.rb +46 -0
- data/spec/integration/coolio/spec_helper.rb +31 -0
- data/spec/integration/coolio/tx_commit_spec.rb +40 -0
- data/spec/integration/coolio/tx_rollback_spec.rb +44 -0
- data/spec/integration/eventmachine/basic_ack_spec.rb +40 -0
- data/spec/integration/eventmachine/basic_get_spec.rb +73 -0
- data/spec/integration/eventmachine/basic_return_spec.rb +35 -0
- data/spec/integration/eventmachine/channel_close_spec.rb +26 -0
- data/spec/integration/eventmachine/channel_flow_spec.rb +32 -0
- data/spec/integration/eventmachine/spec_helper.rb +22 -0
- data/spec/integration/eventmachine/tx_commit_spec.rb +47 -0
- data/spec/integration/eventmachine/tx_rollback_spec.rb +35 -0
- data/spec/regression/bad_frame_slicing_in_adapters_spec.rb +59 -0
- data/spec/spec_helper.rb +24 -0
- data/spec/unit/client/adapter_spec.rb +49 -0
- data/spec/unit/client/entity_spec.rb +49 -0
- data/spec/unit/client/logging_spec.rb +60 -0
- data/spec/unit/client/mixins/status_spec.rb +72 -0
- data/spec/unit/client/settings_spec.rb +27 -0
- data/spec/unit/client_spec.rb +11 -0
- data/tasks.rb +11 -0
- metadata +202 -0
@@ -0,0 +1,39 @@
|
|
1
|
+
require "bundler"
|
2
|
+
|
3
|
+
Bundler.setup
|
4
|
+
Bundler.require(:default)
|
5
|
+
|
6
|
+
$LOAD_PATH.unshift(File.expand_path("../../../lib", __FILE__))
|
7
|
+
|
8
|
+
require "amq/client/adapters/coolio"
|
9
|
+
require "amq/client/queue"
|
10
|
+
require "amq/client/exchange"
|
11
|
+
|
12
|
+
|
13
|
+
if RUBY_VERSION.to_s =~ /^1.9/
|
14
|
+
Encoding.default_internal = Encoding::UTF_8
|
15
|
+
Encoding.default_external = Encoding::UTF_8
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
def amq_client_example(description = "", &block)
|
20
|
+
AMQ::Client::Coolio.connect(:port => 5672, :vhost => "/amq_client_testbed") do |client|
|
21
|
+
begin
|
22
|
+
puts
|
23
|
+
puts
|
24
|
+
puts "=============> #{description}"
|
25
|
+
|
26
|
+
block.call(client)
|
27
|
+
rescue Interrupt
|
28
|
+
warn "Manually interrupted, terminating ..."
|
29
|
+
rescue Exception => exception
|
30
|
+
STDERR.puts "\n\e[1;31m[#{exception.class}] #{exception.message}\e[0m"
|
31
|
+
exception.backtrace.each do |line|
|
32
|
+
line = "\e[0;36m#{line}\e[0m" if line.match(Regexp::quote(File.basename(__FILE__)))
|
33
|
+
STDERR.puts " - " + line
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
cool.io.run
|
39
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
__dir = File.dirname(File.expand_path(__FILE__))
|
5
|
+
require File.join(__dir, "example_helper")
|
6
|
+
|
7
|
+
amq_client_example "Declare a new fanout exchange" do |client|
|
8
|
+
puts "AMQP connection is open: #{client.connection.server_properties.inspect}"
|
9
|
+
|
10
|
+
channel = AMQ::Client::Channel.new(client, 1)
|
11
|
+
channel.open do
|
12
|
+
puts "Channel #{channel.id} is now open!"
|
13
|
+
end
|
14
|
+
|
15
|
+
exchange = AMQ::Client::Exchange.new(client, channel, "amqclient.adapters.em.exchange1", :fanout)
|
16
|
+
exchange.declare
|
17
|
+
|
18
|
+
show_stopper = Proc.new {
|
19
|
+
client.disconnect do
|
20
|
+
puts
|
21
|
+
puts "AMQP connection is now properly closed"
|
22
|
+
Coolio::Loop.default.stop
|
23
|
+
end
|
24
|
+
}
|
25
|
+
|
26
|
+
Signal.trap "INT", show_stopper
|
27
|
+
Signal.trap "TERM", show_stopper
|
28
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
__dir = File.dirname(File.expand_path(__FILE__))
|
5
|
+
require File.join(__dir, "example_helper")
|
6
|
+
|
7
|
+
amq_client_example "An example that combines several AMQ operations" do |client|
|
8
|
+
puts "AMQP connection is open: #{client.connection.server_properties.inspect}"
|
9
|
+
|
10
|
+
channel = AMQ::Client::Channel.new(client, 1)
|
11
|
+
channel.open do
|
12
|
+
puts "Channel #{channel.id} is now open!"
|
13
|
+
end
|
14
|
+
|
15
|
+
queue = AMQ::Client::Queue.new(client, channel, "amqclient.queue2")
|
16
|
+
queue.declare(false, false, false, true) do
|
17
|
+
puts "Queue #{queue.name.inspect} is now declared!"
|
18
|
+
end
|
19
|
+
|
20
|
+
exchange = AMQ::Client::Exchange.new(client, channel, "amqclient.adapters.em.exchange1", :fanout)
|
21
|
+
exchange.declare { puts "Exchange #{exchange.name.inspect} is now declared!" }
|
22
|
+
|
23
|
+
queue.consume do |msg|
|
24
|
+
puts msg
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
show_stopper = Proc.new {
|
29
|
+
puts
|
30
|
+
puts "Deleting queue #{queue.name}"
|
31
|
+
queue.delete do |message_count|
|
32
|
+
puts
|
33
|
+
puts "Deleted #{queue.name}. It had #{message_count} messages in it."
|
34
|
+
puts
|
35
|
+
puts "Deleting exchange #{exchange.name}"
|
36
|
+
exchange.delete do
|
37
|
+
client.disconnect do
|
38
|
+
puts
|
39
|
+
puts "AMQP connection is now properly closed"
|
40
|
+
Coolio::Loop.default.stop
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
}
|
45
|
+
|
46
|
+
Signal.trap "INT", show_stopper
|
47
|
+
Signal.trap "TERM", show_stopper
|
48
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
__dir = File.dirname(File.expand_path(__FILE__))
|
5
|
+
require File.join(__dir, "example_helper")
|
6
|
+
|
7
|
+
amq_client_example "Bind a new queue to amq.fanout" do |client|
|
8
|
+
channel = AMQ::Client::Channel.new(client, 1)
|
9
|
+
channel.open do
|
10
|
+
puts "Channel #{channel.id} is now open!"
|
11
|
+
end
|
12
|
+
|
13
|
+
queue = AMQ::Client::Queue.new(client, channel, "amqclient.queue2")
|
14
|
+
queue.declare do
|
15
|
+
puts "Queue #{queue.name.inspect} is now declared!"
|
16
|
+
end
|
17
|
+
|
18
|
+
queue.bind("amq.fanout") do
|
19
|
+
puts "Queue #{queue.name} is now bound to amq.fanout"
|
20
|
+
puts
|
21
|
+
puts "Deleting queue #{queue.name}"
|
22
|
+
queue.delete do |message_count|
|
23
|
+
puts "Deleted."
|
24
|
+
puts
|
25
|
+
client.disconnect do
|
26
|
+
puts
|
27
|
+
puts "AMQP connection is now properly closed"
|
28
|
+
Coolio::Loop.default.stop
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
__dir = File.dirname(File.expand_path(__FILE__))
|
5
|
+
require File.join(__dir, "example_helper")
|
6
|
+
|
7
|
+
amq_client_example "Purge a queue and announce how many messages it had" do |client|
|
8
|
+
channel = AMQ::Client::Channel.new(client, 1)
|
9
|
+
channel.open do
|
10
|
+
puts "Channel #{channel.id} is now open!"
|
11
|
+
end
|
12
|
+
|
13
|
+
queue = AMQ::Client::Queue.new(client, channel, "amqclient.queue2")
|
14
|
+
queue.declare(false, false, false, true) do
|
15
|
+
puts "Queue #{queue.name.inspect} is now declared!"
|
16
|
+
end
|
17
|
+
|
18
|
+
queue.purge do |message_count|
|
19
|
+
puts "Queue #{queue.name} is now purged. It had #{message_count} messages."
|
20
|
+
puts
|
21
|
+
puts "Deleting queue #{queue.name}"
|
22
|
+
queue.delete do |message_count|
|
23
|
+
puts "Deleted."
|
24
|
+
puts
|
25
|
+
client.disconnect do
|
26
|
+
puts
|
27
|
+
puts "AMQP connection is now properly closed"
|
28
|
+
Coolio::Loop.default.stop
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
__dir = File.dirname(File.expand_path(__FILE__))
|
5
|
+
require File.join(__dir, "example_helper")
|
6
|
+
|
7
|
+
amq_client_example "Bind and then unbind a queue to amq.fanout" do |client|
|
8
|
+
channel = AMQ::Client::Channel.new(client, 1)
|
9
|
+
channel.open do
|
10
|
+
puts "Channel #{channel.id} is now open!"
|
11
|
+
end
|
12
|
+
|
13
|
+
queue = AMQ::Client::Queue.new(client, channel, "amqclient.queue2")
|
14
|
+
queue.declare do
|
15
|
+
puts "Queue #{queue.name.inspect} is now declared!"
|
16
|
+
end
|
17
|
+
|
18
|
+
queue.bind("amq.fanout") do
|
19
|
+
puts "Queue #{queue.name} is now bound to amq.fanout"
|
20
|
+
|
21
|
+
queue.unbind("amq.fanout") do
|
22
|
+
puts "Queue #{queue.name} is now unbound from amq.fanout"
|
23
|
+
|
24
|
+
puts
|
25
|
+
puts "Deleting queue #{queue.name}"
|
26
|
+
queue.delete do |message_count|
|
27
|
+
puts "Deleted."
|
28
|
+
puts
|
29
|
+
client.disconnect do
|
30
|
+
puts
|
31
|
+
puts "AMQP connection is now properly closed"
|
32
|
+
Coolio::Loop.default.stop
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/examples/eventmachine_adapter/authentication/plain_password_with_custom_role_credentials.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
__dir = File.join(File.dirname(File.expand_path(__FILE__)), "..")
|
5
|
+
require File.join(__dir, "example_helper")
|
6
|
+
|
7
|
+
EM.run do
|
8
|
+
AMQ::Client::EventMachineClient.connect(:port => 5672,
|
9
|
+
:vhost => "/amq_client_testbed",
|
10
|
+
:user => "amq_client_gem",
|
11
|
+
:password => "amq_client_gem_password") do |client|
|
12
|
+
puts "Connected, authenticated"
|
13
|
+
|
14
|
+
|
15
|
+
show_stopper = Proc.new {
|
16
|
+
client.disconnect do
|
17
|
+
puts
|
18
|
+
puts "AMQP connection is now properly closed"
|
19
|
+
EM.stop
|
20
|
+
end
|
21
|
+
}
|
22
|
+
|
23
|
+
show_stopper = Proc.new {
|
24
|
+
client.disconnect do
|
25
|
+
puts
|
26
|
+
puts "AMQP connection is now properly closed"
|
27
|
+
EM.stop
|
28
|
+
end
|
29
|
+
}
|
30
|
+
|
31
|
+
Signal.trap "INT", show_stopper
|
32
|
+
Signal.trap "TERM", show_stopper
|
33
|
+
|
34
|
+
EM.add_timer(1, show_stopper)
|
35
|
+
end
|
36
|
+
end
|
data/examples/eventmachine_adapter/authentication/plain_password_with_default_role_credentials.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
__dir = File.join(File.dirname(File.expand_path(__FILE__)), "..")
|
5
|
+
require File.join(__dir, "example_helper")
|
6
|
+
|
7
|
+
EM.run do
|
8
|
+
AMQ::Client::EventMachineClient.connect(:port => 5672, :vhost => "/amq_client_testbed", :user => "guest", :password => "guest") do |client|
|
9
|
+
puts "Connected, authenticated"
|
10
|
+
|
11
|
+
puts client.authenticating?
|
12
|
+
|
13
|
+
|
14
|
+
show_stopper = Proc.new {
|
15
|
+
client.disconnect do
|
16
|
+
puts
|
17
|
+
puts "AMQP connection is now properly closed"
|
18
|
+
EM.stop
|
19
|
+
end
|
20
|
+
}
|
21
|
+
|
22
|
+
Signal.trap "INT", show_stopper
|
23
|
+
Signal.trap "TERM", show_stopper
|
24
|
+
|
25
|
+
EM.add_timer(1, show_stopper)
|
26
|
+
end
|
27
|
+
end
|
data/examples/eventmachine_adapter/authentication/plain_password_with_incorrect_credentials.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
__dir = File.join(File.dirname(File.expand_path(__FILE__)), "..")
|
5
|
+
require File.join(__dir, "example_helper")
|
6
|
+
|
7
|
+
EM.run do
|
8
|
+
AMQ::Client::EventMachineClient.connect(:port => 5672,
|
9
|
+
:vhost => "/amq_client_testbed",
|
10
|
+
:user => "amq_client_gem",
|
11
|
+
:password => "a password that is incorrect #{Time.now.to_i}", :on_possible_authentication_failure => Proc.new { |settings|
|
12
|
+
puts "Authentication failed, as expected, settings are: #{settings.inspect}"
|
13
|
+
|
14
|
+
EM.stop
|
15
|
+
}) do |client|
|
16
|
+
raise "Should not really be executed"
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
__dir = File.dirname(File.expand_path(__FILE__))
|
5
|
+
require File.join(__dir, "example_helper")
|
6
|
+
|
7
|
+
amq_client_example "Set a queue up for message delivery" do |client|
|
8
|
+
channel = AMQ::Client::Channel.new(client, 1)
|
9
|
+
channel.open do
|
10
|
+
queue = AMQ::Client::Queue.new(client, channel)
|
11
|
+
queue.declare(false, false, false, true)
|
12
|
+
|
13
|
+
queue.bind("amq.fanout") do
|
14
|
+
puts "Queue #{queue.name} is now bound to amq.fanout"
|
15
|
+
end
|
16
|
+
|
17
|
+
queue.consume(true) do |consumer_tag|
|
18
|
+
queue.on_delivery do |method, header, payload|
|
19
|
+
puts "Received #{payload}"
|
20
|
+
end
|
21
|
+
|
22
|
+
exchange = AMQ::Client::Exchange.new(client, channel, "amq.fanout", :fanout)
|
23
|
+
100.times do |i|
|
24
|
+
exchange.publish("Message ##{i}")
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
queue.cancel do
|
29
|
+
100.times do |i|
|
30
|
+
exchange.publish("Message ##{i} that MUST NOT have been routed to #{queue.name}")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
show_stopper = Proc.new {
|
38
|
+
client.disconnect do
|
39
|
+
puts
|
40
|
+
puts "AMQP connection is now properly closed"
|
41
|
+
EM.stop
|
42
|
+
end
|
43
|
+
}
|
44
|
+
|
45
|
+
Signal.trap "INT", show_stopper
|
46
|
+
Signal.trap "TERM", show_stopper
|
47
|
+
|
48
|
+
EM.add_timer(1, show_stopper)
|
49
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
__dir = File.dirname(File.expand_path(__FILE__))
|
5
|
+
require File.join(__dir, "example_helper")
|
6
|
+
|
7
|
+
amq_client_example "Set a queue up for message delivery" do |client|
|
8
|
+
channel = AMQ::Client::Channel.new(client, 1)
|
9
|
+
channel.open do
|
10
|
+
puts "Channel #{channel.id} is now open!"
|
11
|
+
end
|
12
|
+
|
13
|
+
queue = AMQ::Client::Queue.new(client, channel)
|
14
|
+
queue.declare(false, false, false, true) do
|
15
|
+
puts "Server-named, auto-deletable Queue #{queue.name.inspect} is ready"
|
16
|
+
end
|
17
|
+
|
18
|
+
queue.bind("amq.fanout") do
|
19
|
+
puts "Queue #{queue.name} is now bound to amq.fanout"
|
20
|
+
end
|
21
|
+
|
22
|
+
queue.consume(true) do |method|
|
23
|
+
puts "Subscribed for messages routed to #{queue.name}, consumer tag is #{method.consumer_tag}, using no-ack mode"
|
24
|
+
puts
|
25
|
+
|
26
|
+
queue.on_delivery do |method, header, payload|
|
27
|
+
puts "Got a delivery:"
|
28
|
+
puts " Delivery tag: #{method.delivery_tag}"
|
29
|
+
puts " Header: #{header.inspect}"
|
30
|
+
puts " Payload: #{payload.inspect}"
|
31
|
+
end
|
32
|
+
|
33
|
+
exchange = AMQ::Client::Exchange.new(client, channel, "amq.fanout", :fanout)
|
34
|
+
100.times do |i|
|
35
|
+
exchange.publish("Message ##{i}")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
show_stopper = Proc.new {
|
40
|
+
client.disconnect do
|
41
|
+
puts
|
42
|
+
puts "AMQP connection is now properly closed"
|
43
|
+
EM.stop
|
44
|
+
end
|
45
|
+
}
|
46
|
+
|
47
|
+
Signal.trap "INT", show_stopper
|
48
|
+
Signal.trap "TERM", show_stopper
|
49
|
+
|
50
|
+
EM.add_timer(1, show_stopper)
|
51
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
__dir = File.dirname(File.expand_path(__FILE__))
|
5
|
+
require File.join(__dir, "example_helper")
|
6
|
+
|
7
|
+
amq_client_example "Acknowledge a message using basic.ack" do |client|
|
8
|
+
channel = AMQ::Client::Channel.new(client, 1)
|
9
|
+
channel.open do
|
10
|
+
puts "Channel #{channel.id} is now open!"
|
11
|
+
end
|
12
|
+
|
13
|
+
queue = AMQ::Client::Queue.new(client, channel)
|
14
|
+
queue.declare
|
15
|
+
|
16
|
+
queue.bind("amq.fanout") do
|
17
|
+
puts "Queue #{queue.name} is now bound to amq.fanout"
|
18
|
+
end
|
19
|
+
|
20
|
+
queue.consume do |consumer_tag|
|
21
|
+
queue.on_delivery do |method, header, payload|
|
22
|
+
puts "Got a delivery: #{payload} (delivery tag: #{method.delivery_tag}), ack-ing..."
|
23
|
+
|
24
|
+
queue.acknowledge(method.delivery_tag)
|
25
|
+
end
|
26
|
+
|
27
|
+
exchange = AMQ::Client::Exchange.new(client, channel, "amq.fanout", :fanout)
|
28
|
+
10.times do |i|
|
29
|
+
exchange.publish("Message ##{i}")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
show_stopper = Proc.new {
|
34
|
+
client.disconnect do
|
35
|
+
puts
|
36
|
+
puts "AMQP connection is now properly closed"
|
37
|
+
EM.stop
|
38
|
+
end
|
39
|
+
}
|
40
|
+
|
41
|
+
Signal.trap "INT", show_stopper
|
42
|
+
Signal.trap "TERM", show_stopper
|
43
|
+
|
44
|
+
EM.add_timer(1, show_stopper)
|
45
|
+
end
|