sparqcode_bunny 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. data/.gitignore +10 -0
  2. data/.rspec +3 -0
  3. data/.travis.yml +15 -0
  4. data/.yardopts +9 -0
  5. data/CHANGELOG +27 -0
  6. data/Gemfile +39 -0
  7. data/LICENSE +21 -0
  8. data/README.textile +82 -0
  9. data/Rakefile +14 -0
  10. data/bunny.gemspec +43 -0
  11. data/examples/simple_08.rb +32 -0
  12. data/examples/simple_09.rb +32 -0
  13. data/examples/simple_ack_08.rb +35 -0
  14. data/examples/simple_ack_09.rb +35 -0
  15. data/examples/simple_consumer_08.rb +55 -0
  16. data/examples/simple_consumer_09.rb +55 -0
  17. data/examples/simple_fanout_08.rb +41 -0
  18. data/examples/simple_fanout_09.rb +41 -0
  19. data/examples/simple_headers_08.rb +42 -0
  20. data/examples/simple_headers_09.rb +42 -0
  21. data/examples/simple_publisher_08.rb +29 -0
  22. data/examples/simple_publisher_09.rb +29 -0
  23. data/examples/simple_topic_08.rb +61 -0
  24. data/examples/simple_topic_09.rb +61 -0
  25. data/ext/amqp-0.8.json +616 -0
  26. data/ext/amqp-0.9.1.json +388 -0
  27. data/ext/config.yml +4 -0
  28. data/ext/qparser.rb +469 -0
  29. data/lib/bunny/channel08.rb +39 -0
  30. data/lib/bunny/channel09.rb +39 -0
  31. data/lib/bunny/client08.rb +472 -0
  32. data/lib/bunny/client09.rb +374 -0
  33. data/lib/bunny/consumer.rb +35 -0
  34. data/lib/bunny/exchange08.rb +171 -0
  35. data/lib/bunny/exchange09.rb +159 -0
  36. data/lib/bunny/queue08.rb +403 -0
  37. data/lib/bunny/queue09.rb +325 -0
  38. data/lib/bunny/subscription08.rb +87 -0
  39. data/lib/bunny/subscription09.rb +87 -0
  40. data/lib/bunny/system_timer.rb +14 -0
  41. data/lib/bunny/version.rb +5 -0
  42. data/lib/bunny.rb +109 -0
  43. data/lib/qrack/amq-client-url.rb +165 -0
  44. data/lib/qrack/channel.rb +20 -0
  45. data/lib/qrack/client.rb +235 -0
  46. data/lib/qrack/errors.rb +5 -0
  47. data/lib/qrack/protocol/protocol08.rb +134 -0
  48. data/lib/qrack/protocol/protocol09.rb +135 -0
  49. data/lib/qrack/protocol/spec08.rb +828 -0
  50. data/lib/qrack/protocol/spec09.rb +524 -0
  51. data/lib/qrack/qrack08.rb +20 -0
  52. data/lib/qrack/qrack09.rb +20 -0
  53. data/lib/qrack/queue.rb +40 -0
  54. data/lib/qrack/subscription.rb +112 -0
  55. data/lib/qrack/transport/buffer08.rb +278 -0
  56. data/lib/qrack/transport/buffer09.rb +280 -0
  57. data/lib/qrack/transport/frame08.rb +117 -0
  58. data/lib/qrack/transport/frame09.rb +97 -0
  59. data/spec/spec_08/bunny_spec.rb +77 -0
  60. data/spec/spec_08/connection_spec.rb +25 -0
  61. data/spec/spec_08/exchange_spec.rb +173 -0
  62. data/spec/spec_08/queue_spec.rb +235 -0
  63. data/spec/spec_09/amqp_url_spec.rb +19 -0
  64. data/spec/spec_09/bunny_spec.rb +76 -0
  65. data/spec/spec_09/connection_spec.rb +29 -0
  66. data/spec/spec_09/exchange_spec.rb +173 -0
  67. data/spec/spec_09/queue_spec.rb +248 -0
  68. metadata +151 -0
@@ -0,0 +1,42 @@
1
+ # encoding: utf-8
2
+
3
+ # simple_headers_09.rb
4
+
5
+ # Assumes that target message broker/server has a user called 'guest' with a password 'guest'
6
+ # and that it is running on 'localhost'.
7
+
8
+ # If this is not the case, please change the 'Bunny.new' call below to include
9
+ # the relevant arguments e.g. b = Bunny.new(:user => 'john', :pass => 'doe', :host => 'foobar')
10
+
11
+ $:.unshift File.dirname(__FILE__) + '/../lib'
12
+
13
+ require 'bunny'
14
+
15
+ b = Bunny.new(:spec => '09')
16
+
17
+ # start a communication session with the amqp server
18
+ b.start
19
+
20
+ # declare queues
21
+ q = b.queue('header_q1')
22
+
23
+ # create a headers exchange
24
+ header_exch = b.exchange('header_exch', :type => :headers)
25
+
26
+ # bind the queue to the exchange
27
+ q.bind(header_exch, :arguments => {'h1'=>'a','x-match'=>'all'})
28
+
29
+ # publish messages to the exchange
30
+ header_exch.publish('Headers test msg 1', :headers => {'h1'=>'a'})
31
+ header_exch.publish('Headers test msg 2', :headers => {'h1'=>'z'})
32
+
33
+
34
+ # get messages from the queue - should only be msg 1 that got through
35
+ msg = ""
36
+ until msg == :queue_empty do
37
+ msg = q.pop[:payload]
38
+ puts 'This is a message from the header_q1 queue: ' + msg + "\n" unless msg == :queue_empty
39
+ end
40
+
41
+ # close the client connection
42
+ b.stop
@@ -0,0 +1,29 @@
1
+ # encoding: utf-8
2
+
3
+ # simple_publisher_08.rb
4
+
5
+ # N.B. To be used in conjunction with simple_consumer_08.rb. See simple_consumer.rb for explanation.
6
+
7
+ # Assumes that target message broker/server has a user called 'guest' with a password 'guest'
8
+ # and that it is running on 'localhost'.
9
+
10
+ # If this is not the case, please change the 'Bunny.new' call below to include
11
+ # the relevant arguments e.g. b = Bunny.new(:user => 'john', :pass => 'doe', :host => 'foobar')
12
+
13
+ $:.unshift File.dirname(__FILE__) + '/../lib'
14
+
15
+ require 'bunny'
16
+
17
+ b = Bunny.new(:logging => true)
18
+
19
+ # start a communication session with the amqp server
20
+ b.start
21
+
22
+ # create/get exchange
23
+ exch = b.exchange('sorting_room')
24
+
25
+ # publish message to exchange
26
+ exch.publish('This is a message from the publisher', :key => 'fred')
27
+
28
+ # message should now be picked up by the consumer so we can stop
29
+ b.stop
@@ -0,0 +1,29 @@
1
+ # encoding: utf-8
2
+
3
+ # simple_publisher.rb
4
+
5
+ # N.B. To be used in conjunction with simple_consumer.rb. See simple_consumer.rb for explanation.
6
+
7
+ # Assumes that target message broker/server has a user called 'guest' with a password 'guest'
8
+ # and that it is running on 'localhost'.
9
+
10
+ # If this is not the case, please change the 'Bunny.new' call below to include
11
+ # the relevant arguments e.g. b = Bunny.new(:user => 'john', :pass => 'doe', :host => 'foobar')
12
+
13
+ $:.unshift File.dirname(__FILE__) + '/../lib'
14
+
15
+ require 'bunny'
16
+
17
+ b = Bunny.new(:logging => true, :spec => '09')
18
+
19
+ # start a communication session with the amqp server
20
+ b.start
21
+
22
+ # create/get exchange
23
+ exch = b.exchange('sorting_room')
24
+
25
+ # publish message to exchange
26
+ exch.publish('This is a message from the publisher', :key => 'fred')
27
+
28
+ # message should now be picked up by the consumer so we can stop
29
+ b.stop
@@ -0,0 +1,61 @@
1
+ # encoding: utf-8
2
+
3
+ # simple_topic_08.rb
4
+
5
+ # Assumes that target message broker/server has a user called 'guest' with a password 'guest'
6
+ # and that it is running on 'localhost'.
7
+
8
+ # If this is not the case, please change the 'Bunny.new' call below to include
9
+ # the relevant arguments e.g. b = Bunny.new(:user => 'john', :pass => 'doe', :host => 'foobar')
10
+
11
+ $:.unshift File.dirname(__FILE__) + '/../lib'
12
+
13
+ require 'bunny'
14
+
15
+ b = Bunny.new
16
+
17
+ # start a communication session with the amqp server
18
+ b.start
19
+
20
+ # declare queues
21
+ soccer = b.queue('topic_soccer')
22
+ cricket = b.queue('topic_cricket')
23
+ rugby = b.queue('topic_rugby')
24
+ allsport = b.queue('topic_allsport')
25
+
26
+ # create a topic exchange
27
+ sports_results = b.exchange('sports_results', :type => :topic)
28
+
29
+ # bind the queues to the exchange
30
+ soccer.bind(sports_results, :key => 'soccer.*')
31
+ cricket.bind(sports_results, :key => 'cricket.*')
32
+ rugby.bind(sports_results, :key => 'rugby.*')
33
+ allsport.bind(sports_results, :key => '*.result')
34
+
35
+ # publish messages to the exchange
36
+ sports_results.publish('Manchester United 1 : Hull City 4', :key => 'soccer.result')
37
+ sports_results.publish('England beat Australia by 5 wickets in first test', :key => 'cricket.result')
38
+ sports_results.publish('British Lions 15 : South Africa 12', :key => 'rugby.result')
39
+
40
+ # get message from the queues
41
+
42
+ # soccer queue got the soccer message
43
+ msg = soccer.pop[:payload]
44
+ puts 'This is a message from the soccer q: ' + msg + "\n\n"
45
+
46
+ # cricket queue got the cricket message
47
+ msg = cricket.pop[:payload]
48
+ puts 'This is a message from the cricket q: ' + msg + "\n\n"
49
+
50
+ # rugby queue got the rugby message
51
+ msg = rugby.pop[:payload]
52
+ puts 'This is a message from the rugby q: ' + msg + "\n\n"
53
+
54
+ # allsport queue got all of the messages
55
+ until msg == :queue_empty do
56
+ msg = allsport.pop[:payload]
57
+ puts 'This is a message from the allsport q: ' + msg + "\n\n" unless msg == :queue_empty
58
+ end
59
+
60
+ # close the client connection
61
+ b.stop
@@ -0,0 +1,61 @@
1
+ # encoding: utf-8
2
+
3
+ # simple_topic_09.rb
4
+
5
+ # Assumes that target message broker/server has a user called 'guest' with a password 'guest'
6
+ # and that it is running on 'localhost'.
7
+
8
+ # If this is not the case, please change the 'Bunny.new' call below to include
9
+ # the relevant arguments e.g. b = Bunny.new(:user => 'john', :pass => 'doe', :host => 'foobar')
10
+
11
+ $:.unshift File.dirname(__FILE__) + '/../lib'
12
+
13
+ require 'bunny'
14
+
15
+ b = Bunny.new(:spec => '09')
16
+
17
+ # start a communication session with the amqp server
18
+ b.start
19
+
20
+ # declare queues
21
+ soccer = b.queue('topic_soccer')
22
+ cricket = b.queue('topic_cricket')
23
+ rugby = b.queue('topic_rugby')
24
+ allsport = b.queue('topic_allsport')
25
+
26
+ # create a topic exchange
27
+ sports_results = b.exchange('sports_results', :type => :topic)
28
+
29
+ # bind the queues to the exchange
30
+ soccer.bind(sports_results, :key => 'soccer.*')
31
+ cricket.bind(sports_results, :key => 'cricket.*')
32
+ rugby.bind(sports_results, :key => 'rugby.*')
33
+ allsport.bind(sports_results, :key => '*.result')
34
+
35
+ # publish messages to the exchange
36
+ sports_results.publish('Manchester United 1 : Hull City 4', :key => 'soccer.result')
37
+ sports_results.publish('England beat Australia by 5 wickets in first test', :key => 'cricket.result')
38
+ sports_results.publish('British Lions 15 : South Africa 12', :key => 'rugby.result')
39
+
40
+ # get message from the queues
41
+
42
+ # soccer queue got the soccer message
43
+ msg = soccer.pop[:payload]
44
+ puts 'This is a message from the soccer q: ' + msg + "\n\n"
45
+
46
+ # cricket queue got the cricket message
47
+ msg = cricket.pop[:payload]
48
+ puts 'This is a message from the cricket q: ' + msg + "\n\n"
49
+
50
+ # rugby queue got the rugby message
51
+ msg = rugby.pop[:payload]
52
+ puts 'This is a message from the rugby q: ' + msg + "\n\n"
53
+
54
+ # allsport queue got all of the messages
55
+ until msg == :queue_empty do
56
+ msg = allsport.pop[:payload]
57
+ puts 'This is a message from the allsport q: ' + msg + "\n\n" unless msg == :queue_empty
58
+ end
59
+
60
+ # close the client connection
61
+ b.stop