amq-client 0.5.0

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.
Files changed (108) hide show
  1. data/.gitignore +8 -0
  2. data/.gitmodules +9 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +7 -0
  5. data/.yardopts +1 -0
  6. data/CONTRIBUTORS +3 -0
  7. data/Gemfile +27 -0
  8. data/LICENSE +20 -0
  9. data/README.textile +61 -0
  10. data/amq-client.gemspec +34 -0
  11. data/bin/jenkins.sh +23 -0
  12. data/bin/set_test_suite_realms_up.sh +24 -0
  13. data/examples/coolio_adapter/basic_consume.rb +49 -0
  14. data/examples/coolio_adapter/basic_consume_with_acknowledgements.rb +43 -0
  15. data/examples/coolio_adapter/basic_consume_with_rejections.rb +43 -0
  16. data/examples/coolio_adapter/basic_publish.rb +35 -0
  17. data/examples/coolio_adapter/channel_close.rb +24 -0
  18. data/examples/coolio_adapter/example_helper.rb +39 -0
  19. data/examples/coolio_adapter/exchange_declare.rb +28 -0
  20. data/examples/coolio_adapter/kitchen_sink1.rb +48 -0
  21. data/examples/coolio_adapter/queue_bind.rb +32 -0
  22. data/examples/coolio_adapter/queue_purge.rb +32 -0
  23. data/examples/coolio_adapter/queue_unbind.rb +37 -0
  24. data/examples/eventmachine_adapter/authentication/plain_password_with_custom_role_credentials.rb +36 -0
  25. data/examples/eventmachine_adapter/authentication/plain_password_with_default_role_credentials.rb +27 -0
  26. data/examples/eventmachine_adapter/authentication/plain_password_with_incorrect_credentials.rb +18 -0
  27. data/examples/eventmachine_adapter/basic_cancel.rb +49 -0
  28. data/examples/eventmachine_adapter/basic_consume.rb +51 -0
  29. data/examples/eventmachine_adapter/basic_consume_with_acknowledgements.rb +45 -0
  30. data/examples/eventmachine_adapter/basic_consume_with_rejections.rb +45 -0
  31. data/examples/eventmachine_adapter/basic_get.rb +57 -0
  32. data/examples/eventmachine_adapter/basic_get_with_empty_queue.rb +53 -0
  33. data/examples/eventmachine_adapter/basic_publish.rb +38 -0
  34. data/examples/eventmachine_adapter/basic_qos.rb +29 -0
  35. data/examples/eventmachine_adapter/basic_recover.rb +29 -0
  36. data/examples/eventmachine_adapter/basic_return.rb +34 -0
  37. data/examples/eventmachine_adapter/channel_close.rb +24 -0
  38. data/examples/eventmachine_adapter/channel_flow.rb +36 -0
  39. data/examples/eventmachine_adapter/channel_level_exception_handling.rb +44 -0
  40. data/examples/eventmachine_adapter/example_helper.rb +39 -0
  41. data/examples/eventmachine_adapter/exchange_declare.rb +54 -0
  42. data/examples/eventmachine_adapter/extensions/rabbitmq/handling_confirm_select_ok.rb +31 -0
  43. data/examples/eventmachine_adapter/extensions/rabbitmq/publisher_confirmations_with_transient_messages.rb +56 -0
  44. data/examples/eventmachine_adapter/extensions/rabbitmq/publisher_confirmations_with_unroutable_message.rb +46 -0
  45. data/examples/eventmachine_adapter/kitchen_sink1.rb +50 -0
  46. data/examples/eventmachine_adapter/queue_bind.rb +32 -0
  47. data/examples/eventmachine_adapter/queue_declare.rb +34 -0
  48. data/examples/eventmachine_adapter/queue_purge.rb +32 -0
  49. data/examples/eventmachine_adapter/queue_unbind.rb +37 -0
  50. data/examples/eventmachine_adapter/tx_commit.rb +29 -0
  51. data/examples/eventmachine_adapter/tx_rollback.rb +29 -0
  52. data/examples/eventmachine_adapter/tx_select.rb +27 -0
  53. data/examples/socket_adapter/basics.rb +19 -0
  54. data/examples/socket_adapter/connection.rb +53 -0
  55. data/examples/socket_adapter/multiple_connections.rb +17 -0
  56. data/irb.rb +66 -0
  57. data/lib/amq/client.rb +15 -0
  58. data/lib/amq/client/adapter.rb +356 -0
  59. data/lib/amq/client/adapters/coolio.rb +221 -0
  60. data/lib/amq/client/adapters/event_machine.rb +228 -0
  61. data/lib/amq/client/adapters/socket.rb +89 -0
  62. data/lib/amq/client/channel.rb +338 -0
  63. data/lib/amq/client/connection.rb +246 -0
  64. data/lib/amq/client/entity.rb +117 -0
  65. data/lib/amq/client/exceptions.rb +86 -0
  66. data/lib/amq/client/exchange.rb +163 -0
  67. data/lib/amq/client/extensions/rabbitmq.rb +5 -0
  68. data/lib/amq/client/extensions/rabbitmq/basic.rb +36 -0
  69. data/lib/amq/client/extensions/rabbitmq/confirm.rb +254 -0
  70. data/lib/amq/client/framing/io/frame.rb +32 -0
  71. data/lib/amq/client/framing/string/frame.rb +62 -0
  72. data/lib/amq/client/logging.rb +56 -0
  73. data/lib/amq/client/mixins/anonymous_entity.rb +21 -0
  74. data/lib/amq/client/mixins/status.rb +62 -0
  75. data/lib/amq/client/protocol/get_response.rb +55 -0
  76. data/lib/amq/client/queue.rb +450 -0
  77. data/lib/amq/client/settings.rb +83 -0
  78. data/lib/amq/client/version.rb +5 -0
  79. data/spec/benchmarks/adapters.rb +77 -0
  80. data/spec/client/framing/io_frame_spec.rb +57 -0
  81. data/spec/client/framing/string_frame_spec.rb +57 -0
  82. data/spec/client/protocol/get_response_spec.rb +79 -0
  83. data/spec/integration/coolio/basic_ack_spec.rb +41 -0
  84. data/spec/integration/coolio/basic_get_spec.rb +73 -0
  85. data/spec/integration/coolio/basic_return_spec.rb +33 -0
  86. data/spec/integration/coolio/channel_close_spec.rb +26 -0
  87. data/spec/integration/coolio/channel_flow_spec.rb +46 -0
  88. data/spec/integration/coolio/spec_helper.rb +31 -0
  89. data/spec/integration/coolio/tx_commit_spec.rb +40 -0
  90. data/spec/integration/coolio/tx_rollback_spec.rb +44 -0
  91. data/spec/integration/eventmachine/basic_ack_spec.rb +40 -0
  92. data/spec/integration/eventmachine/basic_get_spec.rb +73 -0
  93. data/spec/integration/eventmachine/basic_return_spec.rb +35 -0
  94. data/spec/integration/eventmachine/channel_close_spec.rb +26 -0
  95. data/spec/integration/eventmachine/channel_flow_spec.rb +32 -0
  96. data/spec/integration/eventmachine/spec_helper.rb +22 -0
  97. data/spec/integration/eventmachine/tx_commit_spec.rb +47 -0
  98. data/spec/integration/eventmachine/tx_rollback_spec.rb +35 -0
  99. data/spec/regression/bad_frame_slicing_in_adapters_spec.rb +59 -0
  100. data/spec/spec_helper.rb +24 -0
  101. data/spec/unit/client/adapter_spec.rb +49 -0
  102. data/spec/unit/client/entity_spec.rb +49 -0
  103. data/spec/unit/client/logging_spec.rb +60 -0
  104. data/spec/unit/client/mixins/status_spec.rb +72 -0
  105. data/spec/unit/client/settings_spec.rb +27 -0
  106. data/spec/unit/client_spec.rb +11 -0
  107. data/tasks.rb +11 -0
  108. metadata +202 -0
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /*.gem
2
+ .bundle
3
+ vendor/bundle
4
+ .yardoc/*
5
+ doc/*
6
+ .rvmrc
7
+ # see http://bit.ly/h2WJPm for reasoning
8
+ Gemfile.lock
data/.gitmodules ADDED
@@ -0,0 +1,9 @@
1
+ [submodule "vendor/amq-protocol"]
2
+ path = vendor/amq-protocol
3
+ url = https://github.com/ruby-amqp/amq-protocol.git
4
+ [submodule "vendor/cool.io"]
5
+ path = vendor/cool.io
6
+ url = https://github.com/tarcieri/cool.io.git
7
+ [submodule "vendor/evented-spec"]
8
+ path = vendor/evented-spec
9
+ url = git://github.com/markiz/evented-spec.git
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --format nested
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ script: "bundle exec rspec spec"
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.2
5
+ - ree
6
+ - rbx
7
+ - jruby
data/.yardopts ADDED
@@ -0,0 +1 @@
1
+ --no-private --protected lib/amq/**/*.rb
data/CONTRIBUTORS ADDED
@@ -0,0 +1,3 @@
1
+ Michael S. Klishin: 102 (7770 LOC)
2
+ Jakub Šťastný aka Botanicus: 49 (2103 LOC)
3
+ Mark Abramov: 13 (947 LOC)
data/Gemfile ADDED
@@ -0,0 +1,27 @@
1
+ # encoding: utf-8
2
+
3
+ source :rubygems
4
+
5
+ gem "eventmachine", "0.12.10" #, "1.0.0.beta.3"
6
+ # cool.io uses iobuffer that won't compile on JRuby
7
+ # (and, probably, Windows)
8
+ gem "cool.io", :platform => :ruby
9
+ gem "amq-protocol", :git => "git://github.com/ruby-amqp/amq-protocol.git", :branch => "master"
10
+
11
+ group :development do
12
+ gem "yard"
13
+ # yard tags this buddy along
14
+ gem "RedCloth"
15
+
16
+ gem "nake", :platform => :ruby_19
17
+ gem "contributors", :platform => :ruby_19
18
+
19
+ # excludes Windows and JRuby
20
+ gem "perftools.rb", :platform => :mri
21
+ end
22
+
23
+ group :test do
24
+ gem "rspec", ">=2.0.0"
25
+ gem "autotest"
26
+ gem "evented-spec", :git => "git://github.com/ruby-amqp/evented-spec.git", :branch => "master"
27
+ end
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Jakub Šťastný aka Botanicus
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.textile ADDED
@@ -0,0 +1,61 @@
1
+ h2. About amq-client
2
+
3
+ amq-client is a fully-featured, low-level AMQP 0.9.1 client that runs on Ruby 1.8.7, 1.9.2, REE, Rubinius and JRuby.
4
+ It's sweet spot is in serving as foundation for higher-level, more opinionated AMQP libraries.
5
+ It can be used directly by applications code when performance and access to
6
+ advanced AMQP protocol features is more important that API convenience.
7
+
8
+ h2(#amqp_gems_family). How does amq-client relate to amqp gem, amq-protocol and libraries like bunny?
9
+
10
+ <pre>
11
+ |--------------| |-----------------------| |----------------------|
12
+ | AMQ-Protocol | | AMQ-Client | | AMQP gem, bunny, etc |
13
+ | - Encoding | ===> | - IO abstraction | ===> | - high-level API |
14
+ | - Decoding | | - Low-level AMQP API | | - opinionated |
15
+ | - Framing | |-----------------------| |----------------------|
16
+ |--------------|
17
+
18
+ </pre>
19
+
20
+ * At the lowest level, "AMQ-Protocol gem":http://github.com/ruby-amqp/amq-protocol takes care of encoding, decoding and framing.
21
+ * One level above is "AMQ-Client gem":http://github.com/ruby-amqp/amq-client that takes care of network I/O, provides uniform interface for
22
+ various I/O libraries like "EventMachine":http://rubyeventmachine.com/, "cool.io":http://coolio.github.com/ or good old TCP sockets and implements
23
+ AMQP protocol entities (queues, exchanges, channels and so on) with emphasis on access to every feature available over API convenience or
24
+ conciseness.
25
+ * Finally, end applications use
26
+
27
+ h2. Adapters
28
+
29
+ Version 1.0 will feature 3 adapters:
30
+
31
+ * EventMachine (asynchronous)
32
+ * cool.io (asynchronous)
33
+ * TCP sockets (synchronous)
34
+
35
+ h2. Installation
36
+
37
+ If you use Bundler and want to use the very latest version, add this to your Gemfile:
38
+
39
+ <pre>
40
+ gem 'amq-client', :git => 'https://github.com/ruby-amqp/amq-client.git'
41
+ </pre>
42
+
43
+
44
+ h2. Nightly Builds
45
+
46
+ You can always find nightly builds at "gems.101ideas.cz":http://gems.101ideas.cz.
47
+ You can install them thusly:
48
+
49
+ <pre>
50
+ wget http://gems.101ideas.cz/amq-client-nightly.gem
51
+ gem install amq-client-nightly.gem
52
+ </pre>
53
+
54
+ h2. See also
55
+
56
+ * "API documentation":http://rdoc.info/github/ruby-amqp/amq-client/master/frames
57
+ * "Examples":https://github.com/ruby-amqp/amq-client/tree/master/examples/
58
+ * "Jabber room for contributors":xmpp://amqp-dev@conf.netlab.cz
59
+ * "Ruby AMQP mailing list":http://groups.google.com/group/ruby-amqp
60
+ * "Issue tracker":http://github.com/ruby-amqp/amq-client/issues
61
+ * "Continous integration server":http://travis-ci.org/#!/ruby-amqp/amq-client
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env gem build
2
+ # encoding: utf-8
3
+
4
+ require "base64"
5
+ require File.expand_path("../lib/amq/client/version", __FILE__)
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = "amq-client"
9
+ s.version = AMQ::Client::VERSION.dup
10
+ s.authors = ["Jakub Stastny", "Michael S. Klishin", "Theo Hultberg", "Mark Abramov"]
11
+ s.email = [Base64.decode64("c3Rhc3RueUAxMDFpZGVhcy5jeg==\n"), "michael@novemberain.com"]
12
+ s.homepage = "http://github.com/ruby-amqp/amq-client"
13
+ s.summary = "amq-client is a fully-featured, low-level AMQP 0.9.1 client"
14
+ s.description = <<-DESC
15
+ amq-client supports multiple networking adapters (EventMachine, TCP sockets, cool.io) and
16
+ supposed to back more opinionated AMQP clients (such as amqp gem, bunny, et cetera) or be used directly
17
+ in cases when access to more advanced AMQP 0.9.1 features is more important that convenient APIs
18
+ DESC
19
+ s.cert_chain = nil
20
+ s.has_rdoc = true
21
+
22
+ # files
23
+ s.files = `git ls-files`.split("\n").reject { |file| file =~ /^vendor\// }
24
+ s.require_paths = ["lib"]
25
+ s.extra_rdoc_files = ["README.textile"] + Dir.glob("doc/*")
26
+
27
+ # Dependencies
28
+ s.add_dependency "eventmachine", "~> 0.12.10"
29
+ s.add_dependency "amq-protocol"
30
+
31
+
32
+ # RubyForge
33
+ s.rubyforge_project = "amq-client"
34
+ end
data/bin/jenkins.sh ADDED
@@ -0,0 +1,23 @@
1
+ #!/bin/bash
2
+
3
+ echo -e "\n\n==== Setup ===="
4
+ source /etc/profile
5
+ git fetch && git reset origin/master --hard
6
+
7
+ echo -e "\n\n==== Ruby 1.9.2 Head ===="
8
+ rvm use 1.9.2-head@ruby-amqp
9
+ gem install bundler --no-ri --no-rdoc
10
+ bundle install --path vendor/bundle/1.9.2 --without development; echo
11
+ bundle update amq-protocol evented-spec; echo
12
+ bundle exec rspec spec
13
+ return_status=$?
14
+
15
+ echo -e "\n\n==== Ruby 1.8.7 ===="
16
+ rvm use 1.8.7@ruby-amqp
17
+ gem install bundler --no-ri --no-rdoc
18
+ bundle install --path vendor/bundle/1.8.7 --without development; echo
19
+ bundle update; echo
20
+ bundle exec rspec spec
21
+ return_status=$(expr $return_status + $?)
22
+
23
+ test $return_status -eq 0
@@ -0,0 +1,24 @@
1
+ #!/bin/sh
2
+
3
+ # guest:guest has full access to /
4
+
5
+ rabbitmqctl add_vhost /
6
+ rabbitmqctl add_user guest guest
7
+ rabbitmqctl set_permissions -p / guest ".*" ".*" ".*"
8
+
9
+
10
+ # guest:guest has full access to /amq_client_testbed
11
+ # amq_client_gem:amq_client_gem has full access to /amq_client_testbed
12
+
13
+ rabbitmqctl delete_vhost "/amq_client_testbed"
14
+ rabbitmqctl add_vhost "/amq_client_testbed"
15
+ rabbitmqctl delete_user amq_client_gem
16
+ rabbitmqctl add_user amq_client_gem amq_client_gem_password
17
+ rabbitmqctl set_permissions -p /amq_client_testbed guest ".*" ".*" ".*"
18
+ rabbitmqctl set_permissions -p /amq_client_testbed amq_client_gem ".*" ".*" ".*"
19
+
20
+
21
+ # amqp_gem_reader:reader_password has read access to /amq_client_testbed
22
+
23
+ rabbitmqctl add_user amq_client_gem_reader reader_password
24
+ rabbitmqctl set_permissions -p /amq_client_testbed amq_client_gem_reader "^---$" "^---$" ".*"
@@ -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
+ 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 |consumer_tag|
23
+ puts "Subscribed for messages routed to #{queue.name}, consumer tag is #{consumer_tag}, using no-ack mode"
24
+ puts
25
+
26
+ queue.on_delivery do |header, payload, consumer_tag, delivery_tag, redelivered, exchange, routing_key|
27
+ puts "Got a delivery:"
28
+ puts " Delivery tag: #{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
+ Coolio::Loop.default.stop
44
+ end
45
+ }
46
+
47
+ Signal.trap "INT", show_stopper
48
+ Signal.trap "TERM", show_stopper
49
+ end
@@ -0,0 +1,43 @@
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
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 |header, payload, consumer_tag, delivery_tag, redelivered, exchange, routing_key|
22
+ puts "Got a delivery: #{payload} (delivery tag: #{delivery_tag}), ack-ing..."
23
+
24
+ queue.acknowledge(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
+ Coolio::Loop.default.stop
38
+ end
39
+ }
40
+
41
+ Signal.trap "INT", show_stopper
42
+ Signal.trap "TERM", show_stopper
43
+ end
@@ -0,0 +1,43 @@
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
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 |header, payload, consumer_tag, delivery_tag, redelivered, exchange, routing_key|
22
+ puts "Got a delivery: #{payload} (delivery tag: #{delivery_tag}), rejecting..."
23
+
24
+ queue.reject(delivery_tag, false)
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
+ Coolio::Loop.default.stop
38
+ end
39
+ }
40
+
41
+ Signal.trap "INT", show_stopper
42
+ Signal.trap "TERM", show_stopper
43
+ end
@@ -0,0 +1,35 @@
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 "Publish 100 messages using basic.publish" 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 do
17
+ 100.times do
18
+ # exchange.publish("à bientôt!")
19
+ exchange.publish("See you soon!")
20
+ end
21
+
22
+ $stdout.flush
23
+ end
24
+
25
+ show_stopper = Proc.new {
26
+ client.disconnect do
27
+ puts
28
+ puts "AMQP connection is now properly closed"
29
+ Coolio::Loop.default.stop
30
+ end
31
+ }
32
+
33
+ Signal.trap "INT", show_stopper
34
+ Signal.trap "TERM", show_stopper
35
+ end
@@ -0,0 +1,24 @@
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 "Open and then close AMQ channel" 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
+ puts "Lets close it."
14
+ channel.close do
15
+ puts "Closed channel ##{channel.id}"
16
+ puts
17
+ client.disconnect do
18
+ puts
19
+ puts "AMQP connection is now properly closed"
20
+ Coolio::Loop.default.stop
21
+ end
22
+ end
23
+ end
24
+ end