Permalink
Browse files

Call pop when the message is null (when Receiver#pop is used).

I wasn't calling the block if there was no message pop'ed of the queue.
This pretty breaks pop so I now just call the block with nil.
  • Loading branch information...
1 parent 66c467b commit 79345c0f00c5c1c8e96c02a9894724ab20958b57 Richard Heycock committed Apr 17, 2012
Showing with 13 additions and 9 deletions.
  1. +13 −9 lib/smith/messaging/receiver.rb
@@ -47,10 +47,8 @@ def subscribe(&block)
def pop(&block)
opts = options.pop
@queue.pop(opts) do |metadata, payload|
- if payload
- thread(Reply.new(self, metadata, payload)) do |reply|
- block.call(reply)
- end
+ thread(Reply.new(self, metadata, (payload.nil?) ? nil : payload)) do |reply|
+ block.call(reply)
end
end
end
@@ -100,9 +98,15 @@ def initialize(receiver, metadata, undecoded_payload)
@metadata = metadata
@time = Time.now
- @payload = ACL::Payload.decode(undecoded_payload, metadata.type)
- logger.verbose { "Received content on: [queue]: #{denomalized_queue_name}." }
- logger.verbose { "Payload content: [queue]: #{denomalized_queue_name}, [metadata type]: #{metadata.type}, [message]: #{payload.inspect}" }
+ if undecoded_payload
+ @payload = ACL::Payload.decode(undecoded_payload, metadata.type)
+ logger.verbose { "Received content on: [queue]: #{denomalized_queue_name}." }
+ logger.verbose { "Payload content: [queue]: #{denomalized_queue_name}, [metadata type]: #{metadata.type}, [message]: #{payload.inspect}" }
+ else
+ logger.verbose { "Received nil content on: [queue]: #{denomalized_queue_name}." }
+ @payload = nil
+ @nil_message = true
+ end
end
# Reply to a message. If reply_to header is not set a error will be logged
@@ -128,12 +132,12 @@ def reply(&block)
# acknowledge the message.
def ack(multiple=false)
- @metadata.ack(multiple)
+ @metadata.ack(multiple) unless @nil_message
end
# reject the message. Optionally requeuing it.
def reject(opts={})
- @metadata.reject(opts)
+ @metadata.reject(opts) unless @nil_message
end
def reply_to

0 comments on commit 79345c0

Please sign in to comment.