celldee-bunny 0.0.1 → 0.0.2

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.
data/README.markdown CHANGED
@@ -1,11 +1,17 @@
1
- # bunny README
1
+ # README
2
2
 
3
- This project was started to enable me to interact with RabbitMQ using Ruby. It has borrowed heavily from two projects:
3
+ ## Acknowledgements
4
+
5
+ This project has borrowed heavily from the following two projects and owes their respective creators and collaborators a whole lot of gratitude:
4
6
 
5
7
  1. **amqp** by *tmm1* (http://github.com/tmm1/amqp/tree/master)
6
8
  2. **carrot** by *famoseagle* (http://github.com/famoseagle/carrot/tree/master)
9
+
10
+ ## About
11
+
12
+ *bunny* is an AMQP client, written in Ruby, that is intended to allow you to interact with AMQP-compliant message brokers/servers such as RabbitMQ in a synchronous fashion.
7
13
 
8
- I will be creating tests, examples and generally tinkering, so please bear with me.
14
+ *bunny* is being tested with RabbitMQ version 1.5.4 and version 0-8 of the AMQP specification.
9
15
 
10
16
  ## Quick Start
11
17
 
@@ -22,16 +28,16 @@ I will be creating tests, examples and generally tinkering, so please bear with
22
28
  end
23
29
 
24
30
  # declare a queue
25
- q = Queue.new(b.client, 'test1')
31
+ q = b.queue('test1')
26
32
 
27
33
  # create a direct exchange
28
- exchange = Exchange.new(b.client, :direct, 'test_ex')
34
+ exch = b.exchange(:direct, 'test_ex')
29
35
 
30
36
  # bind the queue to the exchange
31
- q.bind(exchange)
37
+ q.bind(exch)
32
38
 
33
39
  # publish a message to the exchange
34
- exchange.publish('Hello everybody!')
40
+ exch.publish('Hello everybody!')
35
41
 
36
42
  # get message from the queue
37
43
  msg = q.pop
data/examples/simple.rb CHANGED
@@ -13,16 +13,16 @@ rescue Exception => e
13
13
  end
14
14
 
15
15
  # declare a queue
16
- q = Queue.new(b.client, 'test1')
16
+ q = b.queue('test1')
17
17
 
18
18
  # create a direct exchange
19
- exchange = Exchange.new(b.client, :direct, 'test_ex')
19
+ exch = b.exchange(:direct, 'test_ex')
20
20
 
21
21
  # bind the queue to the exchange
22
- q.bind(exchange)
22
+ q.bind(exch)
23
23
 
24
24
  # publish a message to the exchange
25
- exchange.publish('Hello everybody!')
25
+ exch.publish('Hello everybody!')
26
26
 
27
27
  # get message from the queue
28
28
  msg = q.pop
data/lib/amqp/client.rb CHANGED
@@ -4,7 +4,7 @@ module AMQP
4
4
  RETRY_DELAY = 10.0
5
5
 
6
6
  attr_reader :status
7
- attr_accessor :channel, :host, :logging, :port, :ticket
7
+ attr_accessor :channel, :host, :logging, :exchanges, :queues, :port, :ticket
8
8
 
9
9
  class ServerDown < StandardError; end
10
10
  class ProtocolError < StandardError; end
@@ -20,6 +20,14 @@ module AMQP
20
20
  @status = 'NOT CONNECTED'
21
21
  end
22
22
 
23
+ def exchanges
24
+ @exchanges ||= {}
25
+ end
26
+
27
+ def queues
28
+ @queues ||= {}
29
+ end
30
+
23
31
  def send_frame(*args)
24
32
  args.each do |data|
25
33
  data.ticket = ticket if ticket and data.respond_to?(:ticket=)
data/lib/bunny.rb CHANGED
@@ -25,9 +25,13 @@ class Bunny
25
25
  def status
26
26
  client.status
27
27
  end
28
+
29
+ def exchange(type, name, opts = {})
30
+ client.exchanges[name] ||= Exchange.new(client, type, name, opts)
31
+ end
28
32
 
29
33
  def queue(name, opts = {})
30
- queues[name] ||= Queue.new(client, name, opts)
34
+ client.queues[name] ||= Queue.new(client, name, opts)
31
35
  end
32
36
 
33
37
  def stop
@@ -35,23 +39,11 @@ class Bunny
35
39
  end
36
40
 
37
41
  def queues
38
- @queues ||= {}
39
- end
40
-
41
- def direct(name = 'amq.direct', opts = {})
42
- exchanges[name] ||= Exchange.new(client, :direct, name, opts)
43
- end
44
-
45
- def topic(name = 'amq.topic', opts = {})
46
- exchanges[name] ||= Exchange.new(client, :topic, name, opts)
47
- end
48
-
49
- def headers(name = 'amq.match', opts = {})
50
- exchanges[name] ||= Exchange.new(client, :headers, name, opts)
42
+ client.queues ||= {}
51
43
  end
52
44
 
53
45
  def exchanges
54
- @exchanges ||= {}
46
+ client.exchanges ||= {}
55
47
  end
56
48
 
57
49
  end
@@ -7,7 +7,8 @@ class Exchange
7
7
  def initialize(client, type, name, opts = {})
8
8
  @client, @type, @name, @opts = client, type, name, opts
9
9
  @key = opts[:key]
10
-
10
+ @client.exchanges[@name] ||= self
11
+
11
12
  unless name == "amq.#{type}" or name == ''
12
13
  client.send_frame(
13
14
  Protocol::Exchange::Declare.new(
@@ -38,6 +39,8 @@ class Exchange
38
39
  end
39
40
 
40
41
  def delete(opts = {})
42
+ client.exchanges.delete(name)
43
+
41
44
  client.send_frame(
42
45
  Protocol::Exchange::Delete.new({ :exchange => name, :nowait => true }.merge(opts))
43
46
  )
data/lib/bunny/queue.rb CHANGED
@@ -77,6 +77,8 @@
77
77
  end
78
78
 
79
79
  def delete(opts = {})
80
+ client.queues.delete(name)
81
+
80
82
  client.send_frame(
81
83
  Protocol::Queue::Delete.new({ :queue => name, :nowait => true }.merge(opts))
82
84
  )
data/spec/bunny_spec.rb CHANGED
@@ -9,22 +9,20 @@ describe Bunny do
9
9
  @b.start
10
10
  end
11
11
 
12
+ after(:each) do
13
+ @b.stop
14
+ end
15
+
12
16
  it "should connect to an AMQP server" do
13
17
  @b.status.should == 'CONNECTED'
14
18
  end
15
19
 
16
20
  it "should be able to create an exchange" do
17
- exch = Exchange.new(@b.client, :direct, 'test_exchange')
21
+ exch = @b.exchange(:direct, 'test_exchange')
18
22
  exch.should be_an_instance_of Exchange
19
23
  exch.name.should == 'test_exchange'
20
24
  @b.exchanges.has_key?('test_exchange').should be true
21
25
  end
22
-
23
- it "should be able to delete an exchange" do
24
- exch = Exchange.new(@b.client, :direct, 'test_exchange')
25
- exch.delete
26
- @b.exchanges.has_key?('test_exchange').should be false
27
- end
28
26
 
29
27
  it "should be able to create a queue" do
30
28
  q = @b.queue('test1')
@@ -33,23 +31,4 @@ describe Bunny do
33
31
  @b.queues.has_key?('test1').should be true
34
32
  end
35
33
 
36
- it "should be able to publish a message to a queue" do
37
- q = @b.queue('test1')
38
- q.publish('This is a test message')
39
- q.message_count.should == 1
40
- end
41
-
42
- it "should be able to get a message from a queue" do
43
- q = @b.queue('test1')
44
- msg = q.pop
45
- msg.should == 'This is a test message'
46
- q.message_count.should == 0
47
- end
48
-
49
- it "should be able to delete a queue" do
50
- q = @b.queue('test1')
51
- q.delete
52
- @b.queues.has_key?('test1').should be true
53
- end
54
-
55
34
  end
@@ -0,0 +1,51 @@
1
+ # exchange_spec.rb
2
+
3
+ require File.expand_path(File.join(File.dirname(__FILE__), %w[.. lib bunny]))
4
+
5
+ describe Exchange do
6
+
7
+ before(:each) do
8
+ @b = Bunny.new
9
+ @b.start
10
+ end
11
+
12
+ after(:each) do
13
+ @b.stop
14
+ end
15
+
16
+ it "should be able to be created as a direct exchange" do
17
+ exch = @b.exchange(:direct, 'direct_exchange')
18
+ exch.should be_an_instance_of Exchange
19
+ exch.name.should == 'direct_exchange'
20
+ exch.type.should == :direct
21
+ @b.exchanges.has_key?('direct_exchange').should be true
22
+ end
23
+
24
+ it "should be able to be created as a topic exchange" do
25
+ exch = @b.exchange(:topic, 'topic_exchange')
26
+ exch.should be_an_instance_of Exchange
27
+ exch.name.should == 'topic_exchange'
28
+ exch.type.should == :topic
29
+ @b.exchanges.has_key?('topic_exchange').should be true
30
+ end
31
+
32
+ it "should be able to be created as a fanout exchange" do
33
+ exch = @b.exchange(:fanout, 'fanout_exchange')
34
+ exch.should be_an_instance_of Exchange
35
+ exch.name.should == 'fanout_exchange'
36
+ exch.type.should == :fanout
37
+ @b.exchanges.has_key?('fanout_exchange').should be true
38
+ end
39
+
40
+ it "should be able to publish a message" do
41
+ exch = @b.exchange(:direct, 'direct_exchange')
42
+ exch.publish('This is a published message')
43
+ end
44
+
45
+ it "should be able to be deleted" do
46
+ exch = @b.exchange(:direct, 'direct_exchange')
47
+ exch.delete
48
+ @b.exchanges.has_key?('direct_exchange').should be false
49
+ end
50
+
51
+ end
@@ -0,0 +1,35 @@
1
+ # queue_spec.rb
2
+
3
+ require File.expand_path(File.join(File.dirname(__FILE__), %w[.. lib bunny]))
4
+
5
+ describe Bunny do
6
+
7
+ before(:each) do
8
+ @b = Bunny.new
9
+ @b.start
10
+ end
11
+
12
+ after(:each) do
13
+ @b.stop
14
+ end
15
+
16
+ it "should be able to publish a message" do
17
+ q = @b.queue('test1')
18
+ q.publish('This is a test message')
19
+ q.message_count.should == 1
20
+ end
21
+
22
+ it "should be able to pop a message" do
23
+ q = @b.queue('test1')
24
+ msg = q.pop
25
+ msg.should == 'This is a test message'
26
+ q.message_count.should == 0
27
+ end
28
+
29
+ it "should be able to be deleted" do
30
+ q = @b.queue('test1')
31
+ q.delete
32
+ @b.queues.has_key?('test1').should be false
33
+ end
34
+
35
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: celldee-bunny
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Duncan
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-04-20 00:00:00 -07:00
12
+ date: 2009-04-21 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -38,6 +38,8 @@ files:
38
38
  - lib/bunny.rb
39
39
  - examples/simple.rb
40
40
  - spec/bunny_spec.rb
41
+ - spec/exchange_spec.rb
42
+ - spec/queue_spec.rb
41
43
  - protocol/amqp-0.8.json
42
44
  - protocol/amqp-0.8.xml
43
45
  - protocol/codegen.rb
@@ -67,6 +69,6 @@ rubyforge_project:
67
69
  rubygems_version: 1.2.0
68
70
  signing_key:
69
71
  specification_version: 2
70
- summary: TODO
72
+ summary: Another synchronous Ruby AMQP client
71
73
  test_files: []
72
74