arvicco-amqp 0.6.10 → 0.6.11

Sign up to get free protection for your applications and to get access to all the features.
data/HISTORY CHANGED
@@ -13,3 +13,7 @@
13
13
  == 0.6.10 / 2010-11-04
14
14
 
15
15
  * Bacon tests converted to Rspec
16
+
17
+ == 0.6.11 / 2010-11-04
18
+
19
+ * AMQP class behavior specified
data/README.md CHANGED
@@ -17,7 +17,8 @@ This fork of AMQP contains following improvements:
17
17
  * MQ::Exchange#publish raises error if no connection to broker.
18
18
  * MQ::Queue only wraps headers with new MQ::Headers if they are not nil. This allows pops to tell more easily when they've requested a message from an empty queue. See (https://github.com/tmm1/amqp/issues#issue/22)
19
19
  * Support for receiving Headers with zero-size data packets. Such contents with no body frames are totally legit if indicated header size is zero.
20
- # * Support for AMQP::Protocol::Basic::Return method. See (https://github.com/tmm1/amqp/issues#issue/1).
20
+
21
+ TODO: * Support for AMQP::Protocol::Basic::Return method. See (https://github.com/tmm1/amqp/issues#issue/1).
21
22
 
22
23
  Getting started
23
24
  ===============
@@ -86,7 +87,7 @@ AMQP gem resources
86
87
  Running specifications suite
87
88
  ============================
88
89
 
89
- To run the test suite make sure you have [bacon](http://gemcutter.org/gems/bacon) gem installed and run:
90
+ To run the test suite make sure you have [Rspec2](http://gemcutter.org/gems/rspec) gem installed and run:
90
91
 
91
92
  rake spec
92
93
 
data/TODO CHANGED
@@ -27,4 +27,6 @@
27
27
  - handle connection.redirect during connect (for rabbitmq in distributed mode) [or just set insist to true]
28
28
 
29
29
  - add amq.queue('name').size{ |num| "#{num} messages in the queue" } (send declare passive, look at declare-ok response)
30
- - clean up MQ.default on disconnect
30
+ - clean up MQ.default on disconnect
31
+
32
+ - add proper handling of Basic::Return (:immediate and :mandatory flags)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.10
1
+ 0.6.11
data/lib/amqp/client.rb CHANGED
@@ -132,13 +132,6 @@ module AMQP
132
132
  send_data data.to_s
133
133
  end
134
134
 
135
- #:stopdoc:
136
- # def send_data data
137
- # log 'send_data', data
138
- # super
139
- # end
140
- #:startdoc:
141
-
142
135
  def close &on_disconnect
143
136
  if on_disconnect
144
137
  @closing = true
data/lib/mq.rb CHANGED
@@ -15,7 +15,8 @@ class MQ
15
15
  end
16
16
 
17
17
  # Raised whenever an illegal operation is attempted.
18
- class Error < StandardError; end
18
+ class Error < StandardError;
19
+ end
19
20
  end
20
21
 
21
22
  # The top-level class for building AMQP clients. This class contains several
@@ -140,13 +141,14 @@ class MQ
140
141
 
141
142
  @connection = connection || AMQP.start
142
143
 
143
- conn.callback{ |c|
144
+ conn.callback { |c|
144
145
  @channel = c.add_channel(self)
145
146
  send Protocol::Channel::Open.new
146
147
  }
147
148
  end
149
+
148
150
  attr_reader :channel, :connection
149
-
151
+
150
152
  # May raise a MQ::Error exception when the frame payload contains a
151
153
  # Protocol::Channel::Close object.
152
154
  #
@@ -160,86 +162,89 @@ class MQ
160
162
  log :received, frame
161
163
 
162
164
  case frame
163
- when Frame::Header
164
- @header = frame.payload
165
- @body = ''
166
- check_content_completion
167
-
168
- when Frame::Body
169
- @body << frame.payload
170
- check_content_completion
171
-
172
- when Frame::Method
173
- case method = frame.payload
174
- when Protocol::Channel::OpenOk
175
- send Protocol::Access::Request.new(:realm => '/data',
176
- :read => true,
177
- :write => true,
178
- :active => true,
179
- :passive => true)
180
-
181
- when Protocol::Access::RequestOk
182
- @ticket = method.ticket
183
- callback{
184
- send Protocol::Channel::Close.new(:reply_code => 200,
185
- :reply_text => 'bye',
186
- :method_id => 0,
187
- :class_id => 0)
188
- } if @closing
189
- succeed
190
-
191
- when Protocol::Basic::CancelOk
192
- if @consumer = consumers[ method.consumer_tag ]
193
- @consumer.cancelled
194
- else
195
- MQ.error "Basic.CancelOk for invalid consumer tag: #{method.consumer_tag}"
196
- end
197
-
198
- when Protocol::Queue::DeclareOk
199
- queues[ method.queue ].receive_status method
200
-
201
- when Protocol::Basic::Deliver, Protocol::Basic::GetOk
202
- @method = method
203
- @header = nil
165
+ when Frame::Header
166
+ @header = frame.payload
204
167
  @body = ''
205
-
206
- if method.is_a? Protocol::Basic::GetOk
207
- @consumer = get_queue{|q| q.shift }
208
- MQ.error "No pending Basic.GetOk requests" unless @consumer
209
- else
210
- @consumer = consumers[ method.consumer_tag ]
211
- MQ.error "Basic.Deliver for invalid consumer tag: #{method.consumer_tag}" unless @consumer
212
- end
213
-
214
- when Protocol::Basic::GetEmpty
215
- if @consumer = get_queue{|q| q.shift }
216
- @consumer.receive nil, nil
217
- else
218
- MQ.error "Basic.GetEmpty for invalid consumer"
168
+ check_content_completion
169
+
170
+ when Frame::Body
171
+ @body << frame.payload
172
+ check_content_completion
173
+
174
+ when Frame::Method
175
+ case method = frame.payload
176
+ when Protocol::Channel::OpenOk
177
+ send Protocol::Access::Request.new(:realm => '/data',
178
+ :read => true,
179
+ :write => true,
180
+ :active => true,
181
+ :passive => true)
182
+
183
+ when Protocol::Access::RequestOk
184
+ @ticket = method.ticket
185
+ callback {
186
+ send Protocol::Channel::Close.new(:reply_code => 200,
187
+ :reply_text => 'bye',
188
+ :method_id => 0,
189
+ :class_id => 0)
190
+ } if @closing
191
+ succeed
192
+
193
+ when Protocol::Basic::CancelOk
194
+ if @consumer = consumers[method.consumer_tag]
195
+ @consumer.cancelled
196
+ else
197
+ MQ.error "Basic.CancelOk for invalid consumer tag: #{method.consumer_tag}"
198
+ end
199
+
200
+ when Protocol::Queue::DeclareOk
201
+ queues[method.queue].receive_status method
202
+
203
+ when Protocol::Basic::GetOk
204
+ @method = method
205
+ @header = nil
206
+ @body = ''
207
+
208
+ @consumer = get_queue { |q| q.shift }
209
+ MQ.error "No pending Basic.GetOk requests" unless @consumer
210
+
211
+ when Protocol::Basic::Deliver
212
+ @method = method
213
+ @header = nil
214
+ @body = ''
215
+
216
+ @consumer = consumers[method.consumer_tag]
217
+ MQ.error "Basic.Deliver for invalid consumer tag: #{method.consumer_tag}" unless @consumer
218
+
219
+ when Protocol::Basic::GetEmpty
220
+ if @consumer = get_queue { |q| q.shift }
221
+ @consumer.receive nil, nil
222
+ else
223
+ MQ.error "Basic.GetEmpty for invalid consumer"
224
+ end
225
+
226
+ when Protocol::Channel::Close
227
+ raise Error, "#{method.reply_text} in #{Protocol.classes[method.class_id].methods[method.method_id]} on #{@channel}"
228
+
229
+ when Protocol::Channel::CloseOk
230
+ @closing = false
231
+ conn.callback { |c|
232
+ c.channels.delete @channel
233
+ c.close if c.channels.empty?
234
+ }
235
+
236
+ when Protocol::Basic::ConsumeOk
237
+ if @consumer = consumers[method.consumer_tag]
238
+ @consumer.confirm_subscribe
239
+ else
240
+ MQ.error "Basic.ConsumeOk for invalid consumer tag: #{method.consumer_tag}"
241
+ end
219
242
  end
220
-
221
- when Protocol::Channel::Close
222
- raise Error, "#{method.reply_text} in #{Protocol.classes[method.class_id].methods[method.method_id]} on #{@channel}"
223
-
224
- when Protocol::Channel::CloseOk
225
- @closing = false
226
- conn.callback{ |c|
227
- c.channels.delete @channel
228
- c.close if c.channels.empty?
229
- }
230
-
231
- when Protocol::Basic::ConsumeOk
232
- if @consumer = consumers[ method.consumer_tag ]
233
- @consumer.confirm_subscribe
234
- else
235
- MQ.error "Basic.ConsumeOk for invalid consumer tag: #{method.consumer_tag}"
236
- end
237
- end
238
243
  end
239
244
  end
240
245
 
241
246
  def send *args
242
- conn.callback{ |c|
247
+ conn.callback { |c|
243
248
  (@_send_mutex ||= Mutex.new).synchronize do
244
249
  args.each do |data|
245
250
  data.ticket = @ticket if @ticket and data.respond_to? :ticket=
@@ -770,8 +775,8 @@ class MQ
770
775
 
771
776
  def get_queue
772
777
  if block_given?
773
- (@get_queue_mutex ||= Mutex.new).synchronize{
774
- yield( @get_queue ||= [] )
778
+ (@get_queue_mutex ||= Mutex.new).synchronize {
779
+ yield(@get_queue ||= [])
775
780
  }
776
781
  end
777
782
  end
@@ -799,11 +804,11 @@ class MQ
799
804
 
800
805
  exs = @exchanges
801
806
  @exchanges = {}
802
- exs.each{ |_,e| e.reset } if exs
807
+ exs.each { |_, e| e.reset } if exs
803
808
 
804
809
  qus = @queues
805
810
  @queues = {}
806
- qus.each{ |_,q| q.reset } if qus
811
+ qus.each { |_, q| q.reset } if qus
807
812
 
808
813
  prefetch(@prefetch_size) if @prefetch_size
809
814
  end
@@ -816,7 +821,7 @@ class MQ
816
821
 
817
822
  def check_content_completion
818
823
  if @body.length >= @header.size
819
- @header.properties.update(@method.arguments)
824
+ @header.properties.update(@method.arguments) if @method
820
825
  @consumer.receive @header, @body if @consumer
821
826
  @body = @header = @consumer = @method = nil
822
827
  end
data/lib/mq/queue.rb CHANGED
@@ -108,7 +108,7 @@ class MQ
108
108
  #
109
109
  def bind exchange, opts = {}
110
110
  exchange = exchange.respond_to?(:name) ? exchange.name : exchange
111
- @bindings[exchange] = opts
111
+ @bindings[exchange] = opts.clone
112
112
 
113
113
  @mq.callback{
114
114
  @mq.send Protocol::Queue::Bind.new({ :queue => name,
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arvicco-amqp
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 6
9
- - 10
10
- version: 0.6.10
9
+ - 11
10
+ version: 0.6.11
11
11
  platform: ruby
12
12
  authors:
13
13
  - Aman Gupta