celldee-bunny 0.0.9 → 0.1.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/amqp/buffer.rb CHANGED
@@ -132,7 +132,7 @@ module AMQP
132
132
 
133
133
  @bits.shift
134
134
  else
135
- raise InvalidType, "Cannot read data of type #{type}"
135
+ raise InvalidTypeError, "Cannot read data of type #{type}"
136
136
  end
137
137
  end
138
138
 
@@ -229,7 +229,7 @@ module AMQP
229
229
  write(type, value) unless type == :bit
230
230
  end
231
231
  else
232
- raise InvalidType, "Cannot write data of type #{type}"
232
+ raise InvalidTypeError, "Cannot write data of type #{type}"
233
233
  end
234
234
 
235
235
  self
@@ -239,7 +239,7 @@ module AMQP
239
239
  begin
240
240
  cur_data, cur_pos = @data.clone, @pos
241
241
  yield self
242
- rescue Overflow
242
+ rescue BufferOverflowError
243
243
  @data, @pos = cur_data, cur_pos
244
244
  nil
245
245
  end
@@ -253,7 +253,7 @@ module AMQP
253
253
  end
254
254
 
255
255
  if @pos + size > length
256
- raise Overflow
256
+ raise BufferOverflowError
257
257
  else
258
258
  data = @data[@pos,size]
259
259
  @data[@pos,size] = ''
data/lib/amqp/client.rb CHANGED
@@ -129,7 +129,7 @@ module AMQP
129
129
  begin
130
130
  socket.__send__(cmd, *args)
131
131
  rescue Errno::EPIPE, IOError => e
132
- raise ServerDown, e.message
132
+ raise ServerDownError, e.message
133
133
  end
134
134
  end
135
135
 
@@ -147,7 +147,7 @@ module AMQP
147
147
  end
148
148
  @status = CONNECTED
149
149
  rescue SocketError, SystemCallError, IOError, Timeout::Error => e
150
- raise ServerDown, e.message
150
+ raise ServerDownError, e.message
151
151
  end
152
152
 
153
153
  @socket
data/lib/amqp.rb CHANGED
@@ -9,8 +9,10 @@ module AMQP
9
9
  QUEUE_EMPTY = 'QUEUE EMPTY'
10
10
 
11
11
  # specific error definitions
12
- class ProtocolError < StandardError; end
13
- class ServerDown < StandardError; end
14
- class Overflow < StandardError; end
15
- class InvalidType < StandardError; end
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
16
18
  end
@@ -7,14 +7,17 @@ class Bunny
7
7
 
8
8
  def initialize(client, name, opts = {})
9
9
  # check connection to server
10
- raise 'Not connected to server' if client.status == NOT_CONNECTED
10
+ raise ConnectionError, 'Not connected to server' if client.status == NOT_CONNECTED
11
11
 
12
12
  @client, @name, @opts = client, name, opts
13
13
  @type = opts[:type] || :direct
14
- opts.delete(:type) unless opts[:type].nil?
15
14
  @key = opts[:key]
16
15
  @client.exchanges[@name] ||= self
17
-
16
+
17
+ # ignore the :nowait option if passed, otherwise program will hang waiting for a
18
+ # response that will not be sent by the server
19
+ opts.delete(:nowait)
20
+
18
21
  unless name == "amq.#{type}" or name == ''
19
22
  client.send_frame(
20
23
  Protocol::Exchange::Declare.new(
@@ -48,7 +51,11 @@ class Bunny
48
51
  client.send_frame(*out)
49
52
  end
50
53
 
51
- def delete(opts = {})
54
+ def delete(opts = {})
55
+ # ignore the :nowait option if passed, otherwise program will hang waiting for a
56
+ # response that will not be sent by the server
57
+ opts.delete(:nowait)
58
+
52
59
  client.send_frame(
53
60
  Protocol::Exchange::Delete.new({ :exchange => name, :nowait => false }.merge(opts))
54
61
  )
data/lib/bunny/queue.rb CHANGED
@@ -8,11 +8,16 @@ class Bunny
8
8
 
9
9
  def initialize(client, name, opts = {})
10
10
  # check connection to server
11
- raise 'Not connected to server' if client.status == NOT_CONNECTED
11
+ raise ConnectionError, 'Not connected to server' if client.status == NOT_CONNECTED
12
12
 
13
13
  @client = client
14
14
  @opts = opts
15
15
  @name = name
16
+
17
+ # ignore the :nowait option if passed, otherwise program will hang waiting for a
18
+ # response that will not be sent by the server
19
+ opts.delete(:nowait)
20
+
16
21
  client.send_frame(
17
22
  Protocol::Queue::Declare.new({ :queue => name, :nowait => false }.merge(opts))
18
23
  )
@@ -21,9 +26,7 @@ class Bunny
21
26
  end
22
27
 
23
28
  def pop(opts = {})
24
- self.delivery_tag = nil
25
-
26
- # do we want the header?
29
+ # do we want the message header?
27
30
  hdr = opts.delete(:header)
28
31
 
29
32
  client.send_frame(
@@ -40,25 +43,15 @@ class Bunny
40
43
  elsif !method.is_a?(Protocol::Basic::GetOk)
41
44
  raise ProtocolError, "Error getting message from queue #{name}"
42
45
  end
43
-
44
- self.delivery_tag = method.delivery_tag
45
-
46
- return QUEUE_EMPTY unless !self.delivery_tag.nil?
47
46
 
48
47
  header = client.next_payload
49
48
  msg = client.next_payload
50
- raise 'unexpected length' if msg.length < header.size
49
+ raise MessageError, 'unexpected length' if msg.length < header.size
51
50
 
52
51
  hdr ? {:header => header, :payload => msg} : msg
53
52
 
54
53
  end
55
54
 
56
- def ack
57
- client.send_frame(
58
- Protocol::Basic::Ack.new(:delivery_tag => delivery_tag)
59
- )
60
- end
61
-
62
55
  def publish(data, opts = {})
63
56
  exchange.publish(data, opts)
64
57
  end
@@ -81,6 +74,11 @@ class Bunny
81
74
 
82
75
  def bind(exchange, opts = {})
83
76
  exchange = exchange.respond_to?(:name) ? exchange.name : exchange
77
+
78
+ # ignore the :nowait option if passed, otherwise program will hang waiting for a
79
+ # response that will not be sent by the server
80
+ opts.delete(:nowait)
81
+
84
82
  bindings[exchange] = opts
85
83
  client.send_frame(
86
84
  Protocol::Queue::Bind.new({ :queue => name,
@@ -112,6 +110,10 @@ class Bunny
112
110
  end
113
111
 
114
112
  def delete(opts = {})
113
+ # ignore the :nowait option if passed, otherwise program will hang waiting for a
114
+ # response that will not be sent by the server
115
+ opts.delete(:nowait)
116
+
115
117
  client.send_frame(
116
118
  Protocol::Queue::Delete.new({ :queue => name, :nowait => false }.merge(opts))
117
119
  )
@@ -51,6 +51,10 @@ describe Bunny::Exchange do
51
51
  @b.exchanges.has_key?('fanout_exchange').should be true
52
52
  end
53
53
 
54
+ it "should ignore the :nowait option when instantiated" do
55
+ exch = @b.exchange('direct2_exchange', :nowait => true)
56
+ end
57
+
54
58
  it "should be able to publish a message" do
55
59
  exch = @b.exchange('direct_exchange')
56
60
  exch.publish('This is a published message')
@@ -62,4 +66,9 @@ describe Bunny::Exchange do
62
66
  @b.exchanges.has_key?('direct_exchange').should be false
63
67
  end
64
68
 
69
+ it "should ignore the :nowait option when deleted" do
70
+ exch = @b.exchange('direct2_exchange')
71
+ exch.delete(:nowait => true)
72
+ end
73
+
65
74
  end
data/spec/queue_spec.rb CHANGED
@@ -8,19 +8,35 @@
8
8
 
9
9
  require File.expand_path(File.join(File.dirname(__FILE__), %w[.. lib bunny]))
10
10
 
11
- describe Bunny do
11
+ describe Bunny::Queue do
12
12
 
13
13
  before(:each) do
14
14
  @b = Bunny.new
15
15
  @b.start
16
16
  end
17
17
 
18
+ it "should ignore the :nowait option when instantiated" do
19
+ q = @b.queue('test0', :nowait => true)
20
+ end
21
+
22
+ it "should ignore the :nowait option when binding to an exchange" do
23
+ exch = @b.exchange('direct_exch')
24
+ q = @b.queue('test0')
25
+ q.bind(exch, :nowait => true)
26
+ end
27
+
18
28
  it "should be able to bind to an exchange" do
19
29
  exch = @b.exchange('direct_exch')
20
30
  q = @b.queue('test1')
21
31
  q.bind(exch)
22
32
  end
23
33
 
34
+ it "should ignore the :nowait option when unbinding from an exchange" do
35
+ exch = @b.exchange('direct_exch')
36
+ q = @b.queue('test0')
37
+ q.unbind(exch, :nowait => true)
38
+ end
39
+
24
40
  it "should be able to unbind from an exchange" do
25
41
  exch = @b.exchange('direct_exch')
26
42
  q = @b.queue('test1')
@@ -64,4 +80,9 @@ describe Bunny do
64
80
  @b.queues.has_key?('test1').should be false
65
81
  end
66
82
 
83
+ it "should ignore the :nowait option when deleted" do
84
+ q = @b.queue('test0')
85
+ q.delete(:nowait => true)
86
+ end
87
+
67
88
  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.9
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Duncan