celldee-bunny 0.2.0 → 0.3.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.
data/lib/bunny.rb CHANGED
@@ -5,76 +5,34 @@ $:.unshift File.expand_path(File.dirname(__FILE__))
5
5
  require file
6
6
  end
7
7
 
8
- # AMQP protocol and transport
9
- %w[spec protocol buffer frame].each do |file|
10
- require 'engineroom/' + file
11
- end
8
+ require 'bunny/client'
9
+ require 'bunny/exchange'
10
+ require 'bunny/queue'
12
11
 
13
- # Bunny API
14
- %w[client exchange header queue].each do |file|
15
- require 'bunny/' + file
16
- end
12
+ require 'bunny/protocol/spec'
13
+ require 'bunny/protocol/protocol'
17
14
 
18
- # Error and return message definitions
19
- require 'api_messages'
15
+ require 'bunny/transport/buffer'
16
+ require 'bunny/transport/frame'
20
17
 
21
- class Bunny
18
+ module Bunny
19
+
22
20
  include Protocol
23
21
  include Transport
24
- include API
25
22
 
26
- attr_reader :client
27
-
28
- def initialize(opts = {})
29
- @client = API::Client.new(opts)
30
- end
31
-
32
- def logging=(bool)
33
- client.logging = bool
34
- end
23
+ class ProtocolError < StandardError; end
24
+ class ServerDownError < StandardError; end
25
+ class BufferOverflowError < StandardError; end
26
+ class InvalidTypeError < StandardError; end
27
+ class ConnectionError < StandardError; end
28
+ class MessageError < StandardError; end
35
29
 
36
- def logging
37
- client.logging
38
- end
39
-
40
- def start
41
- client.start_session
42
- end
43
-
44
- def status
45
- client.status
46
- end
30
+ VERSION = '0.3.0'
47
31
 
48
- def exchange(name, opts = {})
49
- client.exchanges[name] ||= API::Exchange.new(client, name, opts)
50
- end
51
-
52
- def queue(name, opts = {})
53
- client.queues[name] ||= API::Queue.new(client, name, opts)
54
- end
55
-
56
- def stop
57
- client.close
58
- end
59
-
60
- def queues
61
- client.queues ||= {}
62
- end
32
+ # Returns the Bunny version number
63
33
 
64
- def exchanges
65
- client.exchanges ||= {}
66
- end
67
-
68
- def host
69
- client.host
70
- end
71
-
72
- def vhost
73
- client.vhost
74
- end
75
-
76
- def port
77
- client.port
34
+ def self.version
35
+ VERSION
78
36
  end
79
-
37
+
80
38
  end
data/spec/bunny_spec.rb CHANGED
@@ -11,12 +11,12 @@ require File.expand_path(File.join(File.dirname(__FILE__), %w[.. lib bunny]))
11
11
  describe Bunny do
12
12
 
13
13
  before(:each) do
14
- @b = Bunny.new
14
+ @b = Bunny::Client.new
15
15
  @b.start
16
16
  end
17
17
 
18
18
  it "should connect to an AMQP server" do
19
- @b.status.should == 'CONNECTED'
19
+ @b.status.should == :connected
20
20
  end
21
21
 
22
22
  it "should be able to create an exchange" do
@@ -11,12 +11,12 @@ require File.expand_path(File.join(File.dirname(__FILE__), %w[.. lib bunny]))
11
11
  describe Bunny::Exchange do
12
12
 
13
13
  before(:each) do
14
- @b = Bunny.new
14
+ @b = Bunny::Client.new
15
15
  @b.start
16
16
  end
17
17
 
18
18
  it "should raise an error if instantiated as non-existent type" do
19
- lambda { @b.exchange('bogus_ex', :type => :bogus) }.should raise_error(API::ProtocolError)
19
+ lambda { @b.exchange('bogus_ex', :type => :bogus) }.should raise_error(Bunny::ProtocolError)
20
20
  end
21
21
 
22
22
  it "should allow a default direct exchange to be instantiated by specifying :type" do
@@ -105,7 +105,7 @@ describe Bunny::Exchange do
105
105
  it "should be able to be deleted" do
106
106
  exch = @b.exchange('direct_exchange')
107
107
  res = exch.delete
108
- res.should == 'EXCHANGE DELETED'
108
+ res.should == :delete_ok
109
109
  @b.exchanges.has_key?('direct_exchange').should be false
110
110
  end
111
111
 
data/spec/queue_spec.rb CHANGED
@@ -11,7 +11,7 @@ require File.expand_path(File.join(File.dirname(__FILE__), %w[.. lib bunny]))
11
11
  describe Bunny::Queue do
12
12
 
13
13
  before(:each) do
14
- @b = Bunny.new
14
+ @b = Bunny::Client.new
15
15
  @b.start
16
16
  end
17
17
 
@@ -22,25 +22,25 @@ describe Bunny::Queue do
22
22
  it "should ignore the :nowait option when binding to an exchange" do
23
23
  exch = @b.exchange('direct_exch')
24
24
  q = @b.queue('test0')
25
- q.bind(exch, :nowait => true).should == 'BIND SUCCEEDED'
25
+ q.bind(exch, :nowait => true).should == :bind_ok
26
26
  end
27
27
 
28
28
  it "should be able to bind to an exchange" do
29
29
  exch = @b.exchange('direct_exch')
30
30
  q = @b.queue('test1')
31
- q.bind(exch).should == 'BIND SUCCEEDED'
31
+ q.bind(exch).should == :bind_ok
32
32
  end
33
33
 
34
34
  it "should ignore the :nowait option when unbinding from an exchange" do
35
35
  exch = @b.exchange('direct_exch')
36
36
  q = @b.queue('test0')
37
- q.unbind(exch, :nowait => true).should == 'UNBIND SUCCEEDED'
37
+ q.unbind(exch, :nowait => true).should == :unbind_ok
38
38
  end
39
39
 
40
40
  it "should be able to unbind from an exchange" do
41
41
  exch = @b.exchange('direct_exch')
42
42
  q = @b.queue('test1')
43
- q.unbind(exch).should == 'UNBIND SUCCEEDED'
43
+ q.unbind(exch).should == :unbind_ok
44
44
  end
45
45
 
46
46
  it "should be able to publish a message" do
@@ -49,12 +49,13 @@ describe Bunny::Queue do
49
49
  q.message_count.should == 1
50
50
  end
51
51
 
52
- it "should be able to pop a message complete with header" do
52
+ it "should be able to pop a message complete with header and delivery details" do
53
53
  q = @b.queue('test1')
54
54
  msg = q.pop(:header => true)
55
55
  msg.should be_an_instance_of Hash
56
- msg[:header].should be_an_instance_of Protocol::Header
56
+ msg[:header].should be_an_instance_of Bunny::Protocol::Header
57
57
  msg[:payload].should == 'This is a test message'
58
+ msg[:delivery_details].should be_an_instance_of Hash
58
59
  q.message_count.should == 0
59
60
  end
60
61
 
@@ -71,13 +72,13 @@ describe Bunny::Queue do
71
72
  q.publish('This is another test message')
72
73
  q.pop
73
74
  msg = q.pop
74
- msg.should == 'QUEUE EMPTY'
75
+ msg.should == :queue_empty
75
76
  end
76
77
 
77
78
  it "should be able to be deleted" do
78
79
  q = @b.queue('test1')
79
80
  res = q.delete
80
- res.should == 'QUEUE DELETED'
81
+ res.should == :delete_ok
81
82
  @b.queues.has_key?('test1').should be false
82
83
  end
83
84
 
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.2.0
4
+ version: 0.3.0
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-05-01 00:00:00 -07:00
12
+ date: 2009-05-10 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -19,38 +19,38 @@ executables: []
19
19
 
20
20
  extensions: []
21
21
 
22
- extra_rdoc_files: []
23
-
22
+ extra_rdoc_files:
23
+ - README
24
24
  files:
25
+ - LICENSE
26
+ - README
25
27
  - Rakefile
26
- - README.markdown
27
- - lib/api_messages.rb
28
- - lib/bunny.rb
29
- - lib/engineroom/buffer.rb
30
- - lib/engineroom/frame.rb
31
- - lib/engineroom/protocol.rb
32
- - lib/engineroom/spec.rb
33
- - lib/bunny/exchange.rb
34
- - lib/bunny/header.rb
35
- - lib/bunny/queue.rb
36
- - lib/bunny/client.rb
28
+ - bunny.gemspec
37
29
  - examples/simple.rb
38
- - examples/simple_fanout.rb
30
+ - examples/simple_ack.rb
39
31
  - examples/simple_consumer.rb
32
+ - examples/simple_fanout.rb
40
33
  - examples/simple_publisher.rb
41
- - examples/simple_ack.rb
42
34
  - examples/simple_topic.rb
35
+ - ext/amqp-0.8.json
36
+ - ext/codegen.rb
37
+ - lib/bunny.rb
38
+ - lib/bunny/client.rb
39
+ - lib/bunny/exchange.rb
40
+ - lib/bunny/protocol/protocol.rb
41
+ - lib/bunny/protocol/spec.rb
42
+ - lib/bunny/queue.rb
43
+ - lib/bunny/transport/buffer.rb
44
+ - lib/bunny/transport/frame.rb
43
45
  - spec/bunny_spec.rb
44
46
  - spec/exchange_spec.rb
45
47
  - spec/queue_spec.rb
46
- - protocol/amqp-0.8.json
47
- - protocol/codegen.rb
48
48
  has_rdoc: true
49
49
  homepage: http://github.com/celldee/bunny
50
50
  post_install_message:
51
51
  rdoc_options:
52
- - --inline-source
53
- - --charset=UTF-8
52
+ - --main
53
+ - README
54
54
  require_paths:
55
55
  - lib
56
56
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -71,6 +71,6 @@ rubyforge_project: bunny-amqp
71
71
  rubygems_version: 1.2.0
72
72
  signing_key:
73
73
  specification_version: 2
74
- summary: Another synchronous Ruby AMQP client
74
+ summary: A synchronous Ruby AMQP client that enables interaction with AMQP-compliant brokers/servers.
75
75
  test_files: []
76
76
 
data/README.markdown DELETED
@@ -1,126 +0,0 @@
1
- # Bunny: A synchronous Ruby AMQP client
2
-
3
- Google Group: [http://groups.google.com/group/bunny-amqp](http://groups.google.com/group/bunny-amqp)
4
-
5
- Mailing List: [http://rubyforge.org/mailman/listinfo/bunny-amqp-devel](http://rubyforge.org/mailman/listinfo/bunny-amqp-devel)
6
-
7
- Rubyforge: [http://rubyforge.org/projects/bunny-amqp](http://rubyforge.org/projects/bunny-amqp)
8
-
9
- Twitter: [http://twitter.com/bunny_amqp](https://twitter.com/bunny_amqp)
10
-
11
- ## Announcements
12
-
13
- Bunny v0.2.0 is now available. The highlights are -
14
-
15
- * Code has been re-organised enabling Bunny to play nicely with [amqp](http://github.com/tmm1/amqp) (thanks [Dan](http://github.com/danielsdeleo))
16
- * When instantiating a default exchange (one beginning with ‘amq.’) the type will be inferred from the name.
17
- * Fixed Queue#subscribe and included Queue#unsubscribe method. See examples/simple_consumer.rb for details
18
-
19
- ## About
20
-
21
- *Bunny* is an [AMQP](http://www.amqp.org) (Advanced Message Queuing Protocol) client, written in Ruby, that is intended to allow you to interact with AMQP-compliant message brokers/servers such as [RabbitMQ](http://www.rabbitmq.com) in a synchronous fashion.
22
-
23
- It is based on a great deal of fabulous code from [amqp](http://github.com/tmm1/amqp) by Aman Gupta and [Carrot](http://github.com/famoseagle/carrot) by Amos Elliston.
24
-
25
- You can use *Bunny* to -
26
-
27
- * Create and delete exchanges
28
- * Create and delete queues
29
- * Publish and consume messages
30
-
31
- *Bunny* is known to work with RabbitMQ version 1.5.4 and version 0-8 of the AMQP specification. If you want to try to use it with other AMQP message brokers/servers please let me know how you get on.
32
-
33
- ## Quick Start
34
-
35
- require 'bunny'
36
-
37
- b = Bunny.new(:logging => true)
38
-
39
- # start a communication session with the amqp server
40
- b.start
41
-
42
- # declare a queue
43
- q = b.queue('test1')
44
-
45
- # publish a message to the queue
46
- q.publish('Hello everybody!')
47
-
48
- # get message from the queue
49
- msg = q.pop
50
-
51
- puts 'This is the message: ' + msg + "\n\n"
52
-
53
- # close the connection
54
- b.close
55
-
56
- ## Bunny methods
57
-
58
- These are the Bunny methods that you will probably want to use -
59
-
60
- ### Create a Bunny instance
61
- Bunny#new({_options_})
62
-
63
- ### Start a communication session with the target server
64
- Bunny#start
65
-
66
- ### Stop a communication session with the target server
67
- Bunny#stop
68
-
69
- ### Create a Queue
70
- Bunny#queue(_**name**_, {_options_})
71
-
72
- ### Create an Exchange
73
- Bunny#exchange(_**name**_, {_options_})
74
-
75
- ### Return connection status ('CONNECTED' or 'NOT CONNECTED')
76
- Bunny#status
77
-
78
- ### Publish a message to an exchange
79
- Exchange#publish(_**data**_, {_options_})
80
-
81
- ### Delete an exchange from the target server
82
- Exchange#delete({_options_})
83
-
84
- ### Bind a queue to an exchange
85
- Queue#bind(_**exchange**_, {_options_})
86
-
87
- ### Unbind a queue from an exchange
88
- Queue#unbind(_**exchange**_, {_options_})
89
-
90
- ### Publish a message to a queue
91
- Queue#publish(_**data**_, {_options_})
92
-
93
- ### Pop a message off of a queue
94
- Queue#pop({_options_})
95
-
96
- ### Subscribe to a queue
97
- Queue#subscribe({_options_}, &blk)
98
-
99
- ### Unsubscribe from a queue
100
- Queue#unsubscribe({_options_})
101
-
102
- ### Return queue message count
103
- Queue#message_count
104
-
105
- ### Return queue consumer count
106
- Queue#consumer_count
107
-
108
- ### Return queue status (hash {:message count, :consumer_count})
109
- Queue#status
110
-
111
- ### Delete a queue from the target server
112
- Queue#delete({_options_})
113
-
114
- ### Acknowledge receipt of a message
115
- Queue#ack
116
-
117
- ## Acknowledgements
118
-
119
- This project has borrowed heavily from the following two projects and owes their respective creators and collaborators a whole lot of gratitude:
120
-
121
- 1. **amqp** by *tmm1* [http://github.com/tmm1/amqp/tree/master](http://github.com/tmm1/amqp/tree/master)
122
- 2. **carrot** by *famoseagle* [http://github.com/famoseagle/carrot/tree/master](http://github.com/famoseagle/carrot/tree/master)
123
-
124
- ## LICENSE
125
-
126
- Copyright (c) 2009 Chris Duncan; Published under The MIT License, see License
data/lib/api_messages.rb DELETED
@@ -1,18 +0,0 @@
1
- module API
2
- # return messages
3
- CONNECTED = 'CONNECTED'
4
- NOT_CONNECTED = 'NOT CONNECTED'
5
- QUEUE_EMPTY = 'QUEUE EMPTY'
6
- QUEUE_DELETED = 'QUEUE DELETED'
7
- EXCHANGE_DELETED = 'EXCHANGE DELETED'
8
- BIND_SUCCEEDED = 'BIND SUCCEEDED'
9
- UNBIND_SUCCEEDED = 'UNBIND SUCCEEDED'
10
-
11
- # specific error definitions
12
- class ProtocolError < StandardError; end
13
- class ServerDownError < StandardError; end
14
- class BufferOverflowError < StandardError; end
15
- class InvalidTypeError < StandardError; end
16
- class ConnectionError < StandardError; end
17
- class MessageError < StandardError; end
18
- end
data/lib/bunny/header.rb DELETED
@@ -1,30 +0,0 @@
1
- module API
2
- class Header
3
-
4
- attr_reader :client
5
-
6
- def initialize(client, header_obj)
7
- @client = client
8
- @header = header_obj
9
- end
10
-
11
- # Acknowledges the receipt of this message with the server.
12
- def ack
13
- client.send(Protocol::Basic::Ack.new(:delivery_tag => properties[:delivery_tag]))
14
- end
15
-
16
- # Reject this message (XXX currently unimplemented in rabbitmq)
17
- # * :requeue => true | false (default false)
18
- def reject(opts = {})
19
- client.send(Protocol::Basic::Reject.new(opts.merge(:delivery_tag => properties[:delivery_tag])))
20
- end
21
-
22
- def method_missing(meth, *args, &blk)
23
- @header.send(meth, *args, &blk)
24
- end
25
-
26
- def inspect
27
- @header.inspect
28
- end
29
- end
30
- end