Skip to content

Commit

Permalink
Call pop when the message is null (when Receiver#pop is used).
Browse files Browse the repository at this point in the history
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
Richard Heycock committed Apr 17, 2012
1 parent 66c467b commit 79345c0
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions lib/smith/messaging/receiver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 79345c0

Please sign in to comment.