celldee-bunny 0.0.6 → 0.0.7
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 +74 -6
- data/lib/amqp/client.rb +2 -2
- data/lib/bunny.rb +14 -2
- data/lib/bunny/exchange.rb +7 -8
- data/lib/bunny/queue.rb +3 -3
- data/spec/bunny_spec.rb +1 -1
- data/spec/exchange_spec.rb +21 -5
- metadata +2 -2
data/README.markdown
CHANGED
|
@@ -1,18 +1,31 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Bunny: A synchronous Ruby AMQP client
|
|
2
|
+
|
|
3
|
+
Google Group: [bunny-amqp](http://groups.google.com/group/bunny-amqp)
|
|
4
|
+
|
|
5
|
+
## Announcements
|
|
6
|
+
|
|
7
|
+
**IMPORTANT**
|
|
8
|
+
|
|
9
|
+
The Exchange#initialize method has changed as of version 0.0.7
|
|
10
|
+
|
|
11
|
+
You now create an exchange like this -
|
|
12
|
+
|
|
13
|
+
b = Bunny.new
|
|
14
|
+
exch = b.exchange('*my_exchange*', :type => :fanout)
|
|
15
|
+
|
|
16
|
+
If you do not specify a :type option then a default of :direct is used.
|
|
2
17
|
|
|
3
18
|
## About
|
|
4
19
|
|
|
5
|
-
*
|
|
20
|
+
*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.
|
|
6
21
|
|
|
7
|
-
You can use *
|
|
22
|
+
You can use *Bunny* to -
|
|
8
23
|
|
|
9
24
|
* Create and delete exchanges
|
|
10
25
|
* Create and delete queues
|
|
11
26
|
* Publish and consume messages
|
|
12
27
|
|
|
13
|
-
*
|
|
14
|
-
|
|
15
|
-
There is a Google Group for discussing bunny - [bunny-amqp](http://groups.google.com/group/bunny-amqp)
|
|
28
|
+
*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.
|
|
16
29
|
|
|
17
30
|
## Quick Start
|
|
18
31
|
|
|
@@ -42,6 +55,61 @@ There is a Google Group for discussing bunny - [bunny-amqp](http://groups.google
|
|
|
42
55
|
# close the connection
|
|
43
56
|
b.close
|
|
44
57
|
|
|
58
|
+
## Bunny methods
|
|
59
|
+
|
|
60
|
+
These are the Bunny methods that you will probably want to use -
|
|
61
|
+
|
|
62
|
+
### Create a Bunny instance
|
|
63
|
+
Bunny#new({_options_})
|
|
64
|
+
|
|
65
|
+
### Start a communication session with the target server
|
|
66
|
+
Bunny#start
|
|
67
|
+
|
|
68
|
+
### Stop a communication session with the target server
|
|
69
|
+
Bunny#stop
|
|
70
|
+
|
|
71
|
+
### Create a Queue
|
|
72
|
+
Bunny#queue(_**name**_, {_options_})
|
|
73
|
+
|
|
74
|
+
### Creates an Exchange
|
|
75
|
+
Bunny#exchange(_**name**_, {_options_})
|
|
76
|
+
|
|
77
|
+
### Return connection status ('CONNECTED' or 'NOT CONNECTED')
|
|
78
|
+
Bunny#status
|
|
79
|
+
|
|
80
|
+
### Publish a message to an exchange
|
|
81
|
+
Exchange#publish(_**data**_, {_options_})
|
|
82
|
+
|
|
83
|
+
### Delete an exchange from the target server
|
|
84
|
+
Exchange#delete({_options_})
|
|
85
|
+
|
|
86
|
+
### Bind a queue to an exchange
|
|
87
|
+
Queue#bind(_**exchange**_, {_options_})
|
|
88
|
+
|
|
89
|
+
### Unbind a queue from an exchange
|
|
90
|
+
Queue#unbind(_**exchange**_, {_options_})
|
|
91
|
+
|
|
92
|
+
### Publish a message to a queue
|
|
93
|
+
Queue#publish(_**data**_, {_options_})
|
|
94
|
+
|
|
95
|
+
### Pop a message off of a queue
|
|
96
|
+
Queue#pop({_options_})
|
|
97
|
+
|
|
98
|
+
### Return queue message count
|
|
99
|
+
Queue#message_count
|
|
100
|
+
|
|
101
|
+
### Return queue consumer count
|
|
102
|
+
Queue#consumer_count
|
|
103
|
+
|
|
104
|
+
### Return queue status (array of message count and consumer_count)
|
|
105
|
+
Queue#status
|
|
106
|
+
|
|
107
|
+
### Send an acknowledge message to the server
|
|
108
|
+
Queue#ack
|
|
109
|
+
|
|
110
|
+
### Delete a queue from the target server
|
|
111
|
+
Queue#delete({_options_})
|
|
112
|
+
|
|
45
113
|
## Acknowledgements
|
|
46
114
|
|
|
47
115
|
This project has borrowed heavily from the following two projects and owes their respective creators and collaborators a whole lot of gratitude:
|
data/lib/amqp/client.rb
CHANGED
|
@@ -3,8 +3,8 @@ module AMQP
|
|
|
3
3
|
CONNECT_TIMEOUT = 1.0
|
|
4
4
|
RETRY_DELAY = 10.0
|
|
5
5
|
|
|
6
|
-
attr_reader :status
|
|
7
|
-
attr_accessor :channel, :
|
|
6
|
+
attr_reader :status, :host, :vhost, :port
|
|
7
|
+
attr_accessor :channel, :logging, :exchanges, :queues, :ticket
|
|
8
8
|
|
|
9
9
|
def initialize(opts = {})
|
|
10
10
|
@host = opts[:host] || 'localhost'
|
data/lib/bunny.rb
CHANGED
|
@@ -32,8 +32,8 @@ class Bunny
|
|
|
32
32
|
client.status
|
|
33
33
|
end
|
|
34
34
|
|
|
35
|
-
def exchange(
|
|
36
|
-
client.exchanges[name] ||= Exchange.new(client,
|
|
35
|
+
def exchange(name, opts = {})
|
|
36
|
+
client.exchanges[name] ||= Exchange.new(client, name, opts)
|
|
37
37
|
end
|
|
38
38
|
|
|
39
39
|
def queue(name, opts = {})
|
|
@@ -51,5 +51,17 @@ class Bunny
|
|
|
51
51
|
def exchanges
|
|
52
52
|
client.exchanges ||= {}
|
|
53
53
|
end
|
|
54
|
+
|
|
55
|
+
def host
|
|
56
|
+
client.host
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def vhost
|
|
60
|
+
client.vhost
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def port
|
|
64
|
+
client.port
|
|
65
|
+
end
|
|
54
66
|
|
|
55
67
|
end
|
data/lib/bunny/exchange.rb
CHANGED
|
@@ -4,11 +4,13 @@ class Exchange
|
|
|
4
4
|
|
|
5
5
|
attr_reader :client, :type, :name, :opts, :key
|
|
6
6
|
|
|
7
|
-
def initialize(client,
|
|
7
|
+
def initialize(client, name, opts = {})
|
|
8
8
|
# check connection to server
|
|
9
9
|
raise 'Not connected to server' if client.status == NOT_CONNECTED
|
|
10
10
|
|
|
11
|
-
@client, @
|
|
11
|
+
@client, @name, @opts = client, name, opts
|
|
12
|
+
@type = opts[:type] || :direct
|
|
13
|
+
opts.delete(:type) unless opts[:type].nil?
|
|
12
14
|
@key = opts[:key]
|
|
13
15
|
@client.exchanges[@name] ||= self
|
|
14
16
|
|
|
@@ -41,15 +43,12 @@ class Exchange
|
|
|
41
43
|
client.send_frame(*out)
|
|
42
44
|
end
|
|
43
45
|
|
|
44
|
-
def delete(opts = {})
|
|
45
|
-
client.exchanges.delete(name)
|
|
46
|
-
|
|
46
|
+
def delete(opts = {})
|
|
47
47
|
client.send_frame(
|
|
48
48
|
Protocol::Exchange::Delete.new({ :exchange => name, :nowait => true }.merge(opts))
|
|
49
49
|
)
|
|
50
|
-
end
|
|
51
50
|
|
|
52
|
-
|
|
53
|
-
initialize(client, type, name, opts)
|
|
51
|
+
client.exchanges.delete(name)
|
|
54
52
|
end
|
|
53
|
+
|
|
55
54
|
end
|
data/lib/bunny/queue.rb
CHANGED
|
@@ -93,16 +93,16 @@
|
|
|
93
93
|
end
|
|
94
94
|
|
|
95
95
|
def delete(opts = {})
|
|
96
|
-
client.queues.delete(name)
|
|
97
|
-
|
|
98
96
|
client.send_frame(
|
|
99
97
|
Protocol::Queue::Delete.new({ :queue => name, :nowait => true }.merge(opts))
|
|
100
98
|
)
|
|
99
|
+
|
|
100
|
+
client.queues.delete(name)
|
|
101
101
|
end
|
|
102
102
|
|
|
103
103
|
private
|
|
104
104
|
def exchange
|
|
105
|
-
@exchange ||= Exchange.new(client,
|
|
105
|
+
@exchange ||= Exchange.new(client, '', {:type => :direct, :key => name})
|
|
106
106
|
end
|
|
107
107
|
|
|
108
108
|
def bindings
|
data/spec/bunny_spec.rb
CHANGED
|
@@ -24,7 +24,7 @@ describe Bunny do
|
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
it "should be able to create an exchange" do
|
|
27
|
-
exch = @b.exchange(
|
|
27
|
+
exch = @b.exchange('test_exchange')
|
|
28
28
|
exch.should be_an_instance_of Exchange
|
|
29
29
|
exch.name.should == 'test_exchange'
|
|
30
30
|
@b.exchanges.has_key?('test_exchange').should be true
|
data/spec/exchange_spec.rb
CHANGED
|
@@ -19,8 +19,16 @@ describe Exchange do
|
|
|
19
19
|
@b.stop
|
|
20
20
|
end
|
|
21
21
|
|
|
22
|
+
it "should be able to create a default direct exchange" do
|
|
23
|
+
exch = @b.exchange('direct_defaultex')
|
|
24
|
+
exch.should be_an_instance_of Exchange
|
|
25
|
+
exch.name.should == 'direct_defaultex'
|
|
26
|
+
exch.type.should == :direct
|
|
27
|
+
@b.exchanges.has_key?('direct_defaultex').should be true
|
|
28
|
+
end
|
|
29
|
+
|
|
22
30
|
it "should be able to be instantiated as a direct exchange" do
|
|
23
|
-
exch = @b.exchange(
|
|
31
|
+
exch = @b.exchange('direct_exchange', :type => :direct)
|
|
24
32
|
exch.should be_an_instance_of Exchange
|
|
25
33
|
exch.name.should == 'direct_exchange'
|
|
26
34
|
exch.type.should == :direct
|
|
@@ -28,7 +36,7 @@ describe Exchange do
|
|
|
28
36
|
end
|
|
29
37
|
|
|
30
38
|
it "should be able to be instantiated as a topic exchange" do
|
|
31
|
-
exch = @b.exchange(
|
|
39
|
+
exch = @b.exchange('topic_exchange', :type => :topic)
|
|
32
40
|
exch.should be_an_instance_of Exchange
|
|
33
41
|
exch.name.should == 'topic_exchange'
|
|
34
42
|
exch.type.should == :topic
|
|
@@ -36,20 +44,28 @@ describe Exchange do
|
|
|
36
44
|
end
|
|
37
45
|
|
|
38
46
|
it "should be able to be instantiated as a fanout exchange" do
|
|
39
|
-
exch = @b.exchange(
|
|
47
|
+
exch = @b.exchange('fanout_exchange', :type => :fanout)
|
|
40
48
|
exch.should be_an_instance_of Exchange
|
|
41
49
|
exch.name.should == 'fanout_exchange'
|
|
42
50
|
exch.type.should == :fanout
|
|
43
51
|
@b.exchanges.has_key?('fanout_exchange').should be true
|
|
44
52
|
end
|
|
45
53
|
|
|
54
|
+
it "should be able to be instantiated as a headers exchange" do
|
|
55
|
+
exch = @b.exchange('head_exchange', :type => :headers)
|
|
56
|
+
exch.should be_an_instance_of Exchange
|
|
57
|
+
exch.name.should == 'head_exchange'
|
|
58
|
+
exch.type.should == :headers
|
|
59
|
+
@b.exchanges.has_key?('head_exchange').should be true
|
|
60
|
+
end
|
|
61
|
+
|
|
46
62
|
it "should be able to publish a message" do
|
|
47
|
-
exch = @b.exchange(
|
|
63
|
+
exch = @b.exchange('direct_exchange')
|
|
48
64
|
exch.publish('This is a published message')
|
|
49
65
|
end
|
|
50
66
|
|
|
51
67
|
it "should be able to be deleted" do
|
|
52
|
-
exch = @b.exchange(
|
|
68
|
+
exch = @b.exchange('direct_exchange')
|
|
53
69
|
exch.delete
|
|
54
70
|
@b.exchanges.has_key?('direct_exchange').should be false
|
|
55
71
|
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.
|
|
4
|
+
version: 0.0.7
|
|
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-
|
|
12
|
+
date: 2009-04-24 00:00:00 -07:00
|
|
13
13
|
default_executable:
|
|
14
14
|
dependencies: []
|
|
15
15
|
|