amqp 0.7.5 → 0.8.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. data/.gitignore +3 -4
  2. data/.travis.yml +3 -5
  3. data/.yardopts +6 -0
  4. data/CHANGELOG +26 -7
  5. data/Gemfile +15 -7
  6. data/README.textile +216 -0
  7. data/Rakefile +0 -6
  8. data/amqp.gemspec +14 -4
  9. data/bin/jenkins.sh +27 -0
  10. data/bin/set_test_suite_realms_up.sh +16 -2
  11. data/docs/VendorSpecificExtensions.textile +32 -0
  12. data/examples/extensions/rabbitmq/publisher_confirmations_with_transient_messages.rb +53 -0
  13. data/examples/hello_world.rb +29 -0
  14. data/examples/real-world/task-queue/README.textile +3 -0
  15. data/examples/real-world/task-queue/consumer.rb +27 -0
  16. data/examples/real-world/task-queue/producer.rb +22 -0
  17. data/examples/various/ack.rb +70 -0
  18. data/examples/various/automatic_binding_for_default_direct_exchange.rb +53 -0
  19. data/examples/various/basic_get.rb +65 -0
  20. data/examples/various/callbacks.rb +45 -0
  21. data/examples/various/clock.rb +74 -0
  22. data/examples/various/declare_a_queue_without_assignment.rb +46 -0
  23. data/examples/various/declare_an_exchange_without_assignment.rb +46 -0
  24. data/examples/various/hashtable.rb +60 -0
  25. data/examples/{logger.rb → various/logger.rb} +9 -7
  26. data/examples/{multiclock.rb → various/multiclock.rb} +15 -17
  27. data/examples/various/open_channel_without_assignment.rb +34 -0
  28. data/examples/various/pingpong.rb +53 -0
  29. data/examples/various/primes-simple.rb +29 -0
  30. data/examples/various/primes.rb +76 -0
  31. data/examples/various/pubsub.rb +43 -0
  32. data/examples/various/queue_status.rb +58 -0
  33. data/examples/various/stocks.rb +59 -0
  34. data/examples/various/weather_updates.rb +63 -0
  35. data/lib/amqp.rb +11 -2
  36. data/lib/amqp/basic_client.rb +23 -54
  37. data/lib/amqp/channel.rb +577 -805
  38. data/lib/amqp/client.rb +37 -275
  39. data/lib/amqp/connection.rb +165 -93
  40. data/lib/amqp/deprecated/fork.rb +15 -0
  41. data/lib/amqp/deprecated/logger.rb +99 -0
  42. data/lib/amqp/deprecated/mq.rb +20 -0
  43. data/lib/amqp/deprecated/rpc.rb +168 -0
  44. data/lib/amqp/exchange.rb +409 -281
  45. data/lib/amqp/extensions/rabbitmq.rb +1 -0
  46. data/lib/amqp/header.rb +41 -17
  47. data/lib/amqp/logger.rb +10 -84
  48. data/lib/amqp/queue.rb +457 -320
  49. data/lib/amqp/rpc.rb +11 -107
  50. data/lib/amqp/version.rb +1 -1
  51. data/lib/mq.rb +2 -1
  52. data/lib/mq/logger.rb +2 -0
  53. data/lib/mq/rpc.rb +2 -0
  54. data/spec/integration/authentication_spec.rb +36 -40
  55. data/spec/integration/automatic_binding_for_default_direct_exchange_spec.rb +3 -5
  56. data/spec/integration/basic_get_spec.rb +91 -0
  57. data/spec/integration/channel_close_spec.rb +5 -5
  58. data/spec/integration/exchange_declaration_spec.rb +6 -53
  59. data/spec/integration/extensions/basic_return_spec.rb +47 -0
  60. data/spec/integration/queue_declaration_spec.rb +14 -17
  61. data/spec/integration/queue_exclusivity_spec.rb +49 -48
  62. data/spec/integration/reply_queue_communication_spec.rb +6 -4
  63. data/spec/integration/store_and_forward_spec.rb +9 -36
  64. data/spec/integration/topic_subscription_spec.rb +1 -1
  65. data/spec/integration/workload_distribution_spec.rb +1 -0
  66. data/spec/spec_helper.rb +69 -43
  67. data/spec/unit/amqp/connection_spec.rb +27 -23
  68. data/tasks.rb +11 -0
  69. metadata +124 -95
  70. data/README.md +0 -156
  71. data/TODO +0 -30
  72. data/amqp.pre.gemspec +0 -6
  73. data/examples/ack.rb +0 -47
  74. data/examples/automatic_binding_for_default_direct_exchange.rb +0 -65
  75. data/examples/callbacks.rb +0 -40
  76. data/examples/clock.rb +0 -65
  77. data/examples/default_channel.rb +0 -19
  78. data/examples/hashtable.rb +0 -61
  79. data/examples/immediately_bind_a_server_named_queue.rb +0 -38
  80. data/examples/internal.rb +0 -51
  81. data/examples/issues/issue_75.rb +0 -21
  82. data/examples/issues/issue_94.rb +0 -23
  83. data/examples/pingpong.rb +0 -54
  84. data/examples/pop.rb +0 -45
  85. data/examples/primes-simple.rb +0 -21
  86. data/examples/primes.rb +0 -101
  87. data/examples/simple.rb +0 -81
  88. data/examples/stocks.rb +0 -67
  89. data/gemfiles/eventmachine-pre +0 -24
  90. data/lib/amqp/buffer.rb +0 -272
  91. data/lib/amqp/collection.rb +0 -60
  92. data/lib/amqp/frame.rb +0 -68
  93. data/lib/amqp/protocol.rb +0 -163
  94. data/lib/amqp/server.rb +0 -101
  95. data/lib/amqp/spec.rb +0 -832
  96. data/protocol/amqp-0.8.json +0 -617
  97. data/protocol/amqp-0.8.xml +0 -3908
  98. data/protocol/codegen.rb +0 -175
  99. data/protocol/doc.txt +0 -281
  100. data/research/api.rb +0 -52
  101. data/research/primes-forked.rb +0 -65
  102. data/research/primes-processes.rb +0 -137
  103. data/research/primes-threaded.rb +0 -51
  104. data/spec/integration/queue_status_spec.rb +0 -44
  105. data/spec/unit/amqp/buffer_spec.rb +0 -178
  106. data/spec/unit/amqp/client_spec.rb +0 -102
  107. data/spec/unit/amqp/collection_spec.rb +0 -144
  108. data/spec/unit/amqp/frame_spec.rb +0 -60
  109. data/spec/unit/amqp/protocol_spec.rb +0 -51
data/TODO DELETED
@@ -1,30 +0,0 @@
1
- - breaks with header values that are nil
2
- - breaks with header values that are ruby objects (convert to strings?)
3
-
4
- - add peek and pop to queues
5
- - use rabbitmq generated consumer tag from basic.consume-ok reply
6
-
7
- - allow temporary queues with amq.queue(nil) syntax (use uuids)
8
- - use as temp queue in rpc
9
- - use uuids for message ids in rpc
10
-
11
- - add ack/completed responses for messages
12
- - deleting queues/bindings/exchanges
13
- + queue.unbind
14
- - queue.remove or queue.close or queue.delete
15
- - exchange.remove
16
- - rpc.remove
17
-
18
- - handle errors and exceptions
19
- binding to a non-existent (or not yet created in clock.rb) exchange
20
- #<AMQP::Protocol::Channel::Close:0x11d35d4
21
- @class_id=50,
22
- @debug=1,
23
- @method_id=20,
24
- @reply_code=404,
25
- @reply_text="NOT_FOUND - no exchange 'clock' in vhost '/'">>]
26
-
27
- - handle connection.redirect during connect (for rabbitmq in distributed mode) [or just set insist to true]
28
-
29
- - add amq.queue('name').size{ |num| "#{num} messages in the queue" } (send declare passive, look at declare-ok response)
30
- - clean up AMQP::Channel.default on disconnect
@@ -1,6 +0,0 @@
1
- #!/usr/bin/env gem build
2
- # encoding: utf-8
3
-
4
- eval(File.read("amqp.gemspec")).tap do |specification|
5
- specification.version = "#{specification.version}.pre"
6
- end
@@ -1,47 +0,0 @@
1
- # encoding: utf-8
2
-
3
- $:.unshift(File.expand_path("../../lib", __FILE__))
4
- require 'amqp'
5
-
6
- # For ack to work appropriately you must shutdown AMQP gracefully,
7
- # otherwise all items in your queue will be returned
8
- Signal.trap('INT') { AMQP.stop { EM.stop } }
9
- Signal.trap('TERM') { AMQP.stop { EM.stop } }
10
-
11
- AMQP.start(:host => 'localhost') do
12
- AMQP::Channel.queue('awesome').publish('Totally rad 1')
13
- AMQP::Channel.queue('awesome').publish('Totally rad 2')
14
- AMQP::Channel.queue('awesome').publish('Totally rad 3')
15
-
16
- i = 0
17
-
18
- # Stopping after the second item was acked will keep the 3rd item in the queue
19
- AMQP::Channel.queue('awesome').subscribe(:ack => true) do |h, m|
20
- if (i += 1) == 3
21
- puts 'Shutting down...'
22
- AMQP.stop { EM.stop }
23
- end
24
-
25
- if AMQP.closing?
26
- puts "#{m} (ignored, redelivered later)"
27
- else
28
- puts m
29
- h.ack
30
- end
31
- end
32
- end
33
-
34
- __END__
35
-
36
- Totally rad 1
37
- Totally rad 2
38
- Shutting down...
39
- Totally rad 3 (ignored, redelivered later)
40
-
41
- When restarted:
42
-
43
- Totally rad 3
44
- Totally rad 1
45
- Shutting down...
46
- Totally rad 2 (ignored, redelivered later)
47
- Totally rad 3 (ignored, redelivered later)
@@ -1,65 +0,0 @@
1
- # encoding: utf-8
2
-
3
- $:.unshift(File.expand_path("../../lib", __FILE__))
4
-
5
- require 'amqp'
6
-
7
- if RUBY_VERSION == "1.8.7"
8
- module ArrayExtensions
9
- def sample
10
- self.choice
11
- end # sample
12
- end
13
-
14
- class Array
15
- include ArrayExtensions
16
- end
17
- end
18
-
19
-
20
-
21
- EM.run do
22
- connection = AMQP.connect
23
- ch = AMQP::Channel.new(connection)
24
-
25
- show_stopper = Proc.new do
26
- $stdout.puts "Stopping..."
27
- # now change this to just EM.stop and it
28
- # unbinds instantly
29
- connection.close {
30
- EM.stop { exit }
31
- }
32
- end
33
-
34
- Signal.trap "INT", &show_stopper
35
-
36
- $stdout.puts "Bound! Running #{AMQP::VERSION} version of the gem."
37
-
38
- queue1 = ch.queue("queue1")
39
- queue2 = ch.queue("queue2")
40
- queue3 = ch.queue("queue3")
41
-
42
- queues = [queue1, queue2, queue3]
43
-
44
- # Rely on default direct exchange binding, see section 2.1.2.4 Automatic Mode in AMQP 0.9.1 spec.
45
- exchange = ch.default_exchange
46
-
47
- queue1.subscribe do |payload|
48
- puts "Got #{payload} for #{queue1.name}"
49
- end
50
-
51
- queue2.subscribe do |payload|
52
- puts "New message to queue #{queue2.name}"
53
- end
54
-
55
- queue3.subscribe do |payload|
56
- puts "There is a message for #{queue3.name}"
57
- end
58
-
59
- EM.add_periodic_timer(1) do
60
- q = queues.sample
61
-
62
- $stdout.puts "Publishing to default exchange with routing key = #{q.name}..."
63
- exchange.publish "Some payload", :routing_key => q.name
64
- end
65
- end
@@ -1,40 +0,0 @@
1
- # encoding: utf-8
2
-
3
- $:.unshift File.expand_path("../../../lib", __FILE__)
4
- require "amqp"
5
-
6
- AMQP.start(:host => "localhost") do |connection|
7
-
8
- # Send Connection.Close on Ctrl+C
9
- trap(:INT) do
10
- unless connection.closing?
11
- connection.close { exit! }
12
- end
13
- end
14
-
15
- @counter = 0
16
- amq = AMQP::Channel.new
17
-
18
- 3.times do
19
- amq.queue("") do |queue|
20
- puts "Queue #{queue.name} declared."
21
- puts "All queues: #{amq.queues.map(&:name).inspect}", ""
22
-
23
- @counter += 1
24
- end
25
- end
26
-
27
- EM.add_periodic_timer(0.1) do
28
- EM.stop if @counter == 3
29
- end
30
- end
31
-
32
- __END__
33
- Queue amq.gen-qeaCcyVCG50S6QC4U/zNoA== declared.
34
- All queues: [nil, nil, "amq.gen-qeaCcyVCG50S6QC4U/zNoA=="]
35
-
36
- Queue amq.gen-AinMI7PBa2n1fFRIaGEAog== declared.
37
- All queues: [nil, "amq.gen-AinMI7PBa2n1fFRIaGEAog==", "amq.gen-qeaCcyVCG50S6QC4U/zNoA=="]
38
-
39
- Queue amq.gen-ROdJW1LZJVJulUIh8KZqkw== declared.
40
- All queues: ["amq.gen-ROdJW1LZJVJulUIh8KZqkw==", "amq.gen-AinMI7PBa2n1fFRIaGEAog==", "amq.gen-qeaCcyVCG50S6QC4U/zNoA=="]
@@ -1,65 +0,0 @@
1
- # encoding: utf-8
2
-
3
- $:.unshift(File.expand_path("../../lib", __FILE__))
4
- require 'amqp'
5
-
6
- AMQP.start(:host => 'localhost') do |connection|
7
-
8
- # Send Connection.Close on Ctrl+C
9
- trap(:INT) do
10
- unless connection.closing?
11
- connection.close { exit! }
12
- end
13
- end
14
-
15
- def log(*args)
16
- p args
17
- end
18
-
19
- # AMQP.logging = true
20
-
21
- clock = AMQP::Channel.new.fanout('clock')
22
- EM.add_periodic_timer(1) {
23
- puts
24
-
25
- log :publishing, time = Time.now
26
- clock.publish(Marshal.dump(time))
27
- }
28
-
29
- amq = AMQP::Channel.new
30
- amq.queue('every second').bind(amq.fanout('clock')).subscribe { |time|
31
- log 'every second', :received, Marshal.load(time)
32
- }
33
-
34
- amq = AMQP::Channel.new
35
- amq.queue('every 5 seconds').bind(amq.fanout('clock')).subscribe { |time|
36
- time = Marshal.load(time)
37
- log 'every 5 seconds', :received, time if time.strftime('%S').to_i % 5 == 0
38
- }
39
-
40
- end
41
-
42
- __END__
43
-
44
- [:publishing, Thu Jul 17 20:14:00 -0700 2008]
45
- ["every 5 seconds", :received, Thu Jul 17 20:14:00 -0700 2008]
46
- ["every second", :received, Thu Jul 17 20:14:00 -0700 2008]
47
-
48
- [:publishing, Thu Jul 17 20:14:01 -0700 2008]
49
- ["every second", :received, Thu Jul 17 20:14:01 -0700 2008]
50
-
51
- [:publishing, Thu Jul 17 20:14:02 -0700 2008]
52
- ["every second", :received, Thu Jul 17 20:14:02 -0700 2008]
53
-
54
- [:publishing, Thu Jul 17 20:14:03 -0700 2008]
55
- ["every second", :received, Thu Jul 17 20:14:03 -0700 2008]
56
-
57
- [:publishing, Thu Jul 17 20:14:04 -0700 2008]
58
- ["every second", :received, Thu Jul 17 20:14:04 -0700 2008]
59
-
60
- [:publishing, Thu Jul 17 20:14:05 -0700 2008]
61
- ["every 5 seconds", :received, Thu Jul 17 20:14:05 -0700 2008]
62
- ["every second", :received, Thu Jul 17 20:14:05 -0700 2008]
63
-
64
- [:publishing, Thu Jul 17 20:14:06 -0700 2008]
65
- ["every second", :received, Thu Jul 17 20:14:06 -0700 2008]
@@ -1,19 +0,0 @@
1
- # encoding: utf-8
2
-
3
- $:.unshift(File.expand_path("../../lib", __FILE__))
4
- require 'amqp'
5
-
6
- AMQP.start(:host => 'localhost') do |connection|
7
-
8
- # Send Connection.Close on Ctrl+C
9
- trap(:INT) do
10
- AMQP.stop do
11
- puts "Closing and AMQP.channel is #{AMQP.channel.open? ? 'open' : 'closed'}"
12
- exit
13
- end
14
- end
15
-
16
- puts "AMQP.connection is #{AMQP.connection}"
17
- puts "AMQP.channel is #{AMQP.channel}"
18
-
19
- end
@@ -1,61 +0,0 @@
1
- # encoding: utf-8
2
-
3
- $:.unshift(File.expand_path("../../lib", __FILE__))
4
- require 'amqp'
5
-
6
- AMQP.start(:host => 'localhost') do |connection|
7
-
8
- # Send Connection.Close on Ctrl+C
9
- trap(:INT) do
10
- unless connection.closing?
11
- connection.close { exit! }
12
- end
13
- end
14
-
15
- def log(*args)
16
- p args
17
- end
18
-
19
- # AMQP.logging = true
20
-
21
- class HashTable < Hash
22
- def get(key)
23
- log 'HashTable', :get, key
24
- self[key]
25
- end
26
-
27
- def set(key, value)
28
- log 'HashTable', :set, key => value
29
- self[key] = value
30
- end
31
-
32
- def keys
33
- log 'HashTable', :keys
34
- super
35
- end
36
- end
37
-
38
- server = AMQP::Channel.new.rpc('hash table node', HashTable.new)
39
-
40
- client = AMQP::Channel.new.rpc('hash table node')
41
- client.set(:now, time = Time.now)
42
- client.get(:now) do |res|
43
- log 'client', :now => res, :eql? => res == time
44
- end
45
-
46
- client.set(:one, 1)
47
- client.keys do |res|
48
- log 'client', :keys => res
49
- AMQP.stop { EM.stop }
50
- end
51
-
52
- end
53
-
54
- __END__
55
-
56
- ["HashTable", :set, {:now => Thu Jul 17 21:04:53 -0700 2008}]
57
- ["HashTable", :get, :now]
58
- ["HashTable", :set, {:one => 1}]
59
- ["HashTable", :keys]
60
- ["client", {:eql? => true, :now => Thu Jul 17 21:04:53 -0700 2008}]
61
- ["client", {:keys => [:one, :now]}]
@@ -1,38 +0,0 @@
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 "=> AMQP gem #{AMQP::VERSION}"
13
- puts
14
- AMQP.start do |connection|
15
- channel = AMQP::Channel.new
16
- puts "Channel ##{channel.channel} is now open!"
17
-
18
- xchange = channel.fanout("amq.fanout")
19
- q = AMQP::Queue.new(channel, "", :auto_delete => true).bind(xchange).subscribe do |header, payload|
20
- puts "Got a payload: #{payload}"
21
- end
22
-
23
- EventMachine.add_periodic_timer(0.5) {
24
- xchange.publish("à bientôt!", :key => q.name)
25
- }
26
-
27
-
28
- show_stopper = Proc.new do
29
- $stdout.puts "Stopping..."
30
-
31
- connection.close {
32
- EM.stop { exit }
33
- }
34
- end
35
-
36
- Signal.trap "INT", show_stopper
37
- EM.add_timer(3, show_stopper)
38
- end
@@ -1,51 +0,0 @@
1
- # encoding: utf-8
2
-
3
- $:.unshift(File.expand_path("../../lib", __FILE__))
4
- require 'amqp'
5
- require 'pp'
6
-
7
- EM.run do
8
-
9
- # connect to the amqp server
10
- connection = AMQP.connect(:host => 'localhost', :logging => false)
11
-
12
- # open a channel on the AMQP connection
13
- channel = AMQP::Channel.new(connection)
14
-
15
- # declare a queue on the channel
16
- queue = AMQP::Channel::Queue.new(channel, 'queue name')
17
-
18
- # create a fanout exchange
19
- exchange = AMQP::Channel::Exchange.new(channel, :fanout, 'all queues')
20
-
21
- # bind the queue to the exchange
22
- queue.bind(exchange)
23
-
24
- # publish a message to the exchange
25
- exchange.publish('hello world')
26
-
27
- # subscribe to messages in the queue
28
- queue.subscribe do |headers, msg|
29
- pp [:got, headers, msg]
30
- connection.close { EM.stop_event_loop }
31
- end
32
-
33
- end
34
-
35
- __END__
36
-
37
- [:got,
38
- #<AMQP::Protocol::Header:0x1186270
39
- @klass=AMQP::Protocol::Basic,
40
- @properties=
41
- {:priority => 0,
42
- :exchange => "all queues",
43
- :consumer_tag => "queue name",
44
- :delivery_tag => 1,
45
- :delivery_mode => 1,
46
- :redelivered => false,
47
- :content_type => "application/octet-stream",
48
- :routing_key => ""},
49
- @size=11,
50
- @weight=0>,
51
- "hello world"]
@@ -1,21 +0,0 @@
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
- AMQP.start(:host => "localhost") do |connection|
12
- channel = AMQP::Channel.new(connection)
13
- channel.fanout("logs.nad", :auto_delete => false)
14
- channel.fanout("logs.ad", :auto_delete => true)
15
-
16
- EM.add_timer(1) do
17
- connection.close do
18
- EM.stop { exit }
19
- end
20
- end
21
- end