celldee-bunny 0.0.5 → 0.0.6
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 +5 -8
- data/lib/amqp.rb +10 -0
- data/lib/amqp/buffer.rb +0 -2
- data/lib/amqp/client.rb +4 -7
- data/lib/amqp/frame.rb +0 -2
- data/lib/bunny.rb +0 -2
- data/lib/bunny/exchange.rb +3 -0
- data/lib/bunny/queue.rb +3 -0
- metadata +1 -1
data/README.markdown
CHANGED
|
@@ -31,20 +31,17 @@ There is a Google Group for discussing bunny - [bunny-amqp](http://groups.google
|
|
|
31
31
|
# declare a queue
|
|
32
32
|
q = b.queue('test1')
|
|
33
33
|
|
|
34
|
-
#
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
# bind the queue to the exchange
|
|
38
|
-
q.bind(exch)
|
|
39
|
-
|
|
40
|
-
# publish a message to the exchange
|
|
41
|
-
exch.publish('Hello everybody!')
|
|
34
|
+
# publish a message to the queue
|
|
35
|
+
q.publish('Hello everybody!')
|
|
42
36
|
|
|
43
37
|
# get message from the queue
|
|
44
38
|
msg = q.pop
|
|
45
39
|
|
|
46
40
|
puts 'This is the message: ' + msg + "\n\n"
|
|
47
41
|
|
|
42
|
+
# close the connection
|
|
43
|
+
b.close
|
|
44
|
+
|
|
48
45
|
## Acknowledgements
|
|
49
46
|
|
|
50
47
|
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.rb
CHANGED
|
@@ -2,4 +2,14 @@ module AMQP
|
|
|
2
2
|
%w[ spec buffer protocol frame client ].each do |file|
|
|
3
3
|
require "amqp/#{file}"
|
|
4
4
|
end
|
|
5
|
+
|
|
6
|
+
# constants
|
|
7
|
+
CONNECTED = 'CONNECTED'
|
|
8
|
+
NOT_CONNECTED = 'NOT CONNECTED'
|
|
9
|
+
|
|
10
|
+
# specific error definitions
|
|
11
|
+
class ProtocolError < StandardError; end
|
|
12
|
+
class ServerDown < StandardError; end
|
|
13
|
+
class Overflow < StandardError; end
|
|
14
|
+
class InvalidType < StandardError; end
|
|
5
15
|
end
|
data/lib/amqp/buffer.rb
CHANGED
data/lib/amqp/client.rb
CHANGED
|
@@ -6,9 +6,6 @@ module AMQP
|
|
|
6
6
|
attr_reader :status
|
|
7
7
|
attr_accessor :channel, :host, :logging, :exchanges, :queues, :port, :ticket
|
|
8
8
|
|
|
9
|
-
class ServerDown < StandardError; end
|
|
10
|
-
class ProtocolError < StandardError; end
|
|
11
|
-
|
|
12
9
|
def initialize(opts = {})
|
|
13
10
|
@host = opts[:host] || 'localhost'
|
|
14
11
|
@port = opts[:port] || AMQP::PORT
|
|
@@ -17,7 +14,7 @@ module AMQP
|
|
|
17
14
|
@vhost = opts[:vhost] || '/'
|
|
18
15
|
@logging = opts[:logging] || false
|
|
19
16
|
@insist = opts[:insist]
|
|
20
|
-
@status =
|
|
17
|
+
@status = NOT_CONNECTED
|
|
21
18
|
end
|
|
22
19
|
|
|
23
20
|
def exchanges
|
|
@@ -148,7 +145,7 @@ module AMQP
|
|
|
148
145
|
if Socket.constants.include? 'TCP_NODELAY'
|
|
149
146
|
@socket.setsockopt Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1
|
|
150
147
|
end
|
|
151
|
-
@status =
|
|
148
|
+
@status = CONNECTED
|
|
152
149
|
rescue SocketError, SystemCallError, IOError, Timeout::Error => e
|
|
153
150
|
raise ServerDown, e.message
|
|
154
151
|
end
|
|
@@ -160,14 +157,14 @@ module AMQP
|
|
|
160
157
|
# Close the socket. The server is not considered dead.
|
|
161
158
|
@socket.close if @socket and not @socket.closed?
|
|
162
159
|
@socket = nil
|
|
163
|
-
@status =
|
|
160
|
+
@status = NOT_CONNECTED
|
|
164
161
|
end
|
|
165
162
|
|
|
166
163
|
def log(*args)
|
|
167
164
|
return unless logging
|
|
168
165
|
require 'pp'
|
|
169
166
|
pp args
|
|
170
|
-
|
|
167
|
+
puts
|
|
171
168
|
end
|
|
172
169
|
|
|
173
170
|
end
|
data/lib/amqp/frame.rb
CHANGED
data/lib/bunny.rb
CHANGED
data/lib/bunny/exchange.rb
CHANGED
|
@@ -5,6 +5,9 @@ class Exchange
|
|
|
5
5
|
attr_reader :client, :type, :name, :opts, :key
|
|
6
6
|
|
|
7
7
|
def initialize(client, type, name, opts = {})
|
|
8
|
+
# check connection to server
|
|
9
|
+
raise 'Not connected to server' if client.status == NOT_CONNECTED
|
|
10
|
+
|
|
8
11
|
@client, @type, @name, @opts = client, type, name, opts
|
|
9
12
|
@key = opts[:key]
|
|
10
13
|
@client.exchanges[@name] ||= self
|
data/lib/bunny/queue.rb
CHANGED