[bunny-amqp-devel] unsubscribe

17 views
Skip to first unread message

Phillip Neumann

unread,
Apr 18, 2010, 1:28:57 AM4/18/10
to bunny-am...@rubyforge.org
Hello all,

q = b.queue(responde)
q.subscribe(:timeout=>3) do |msg|
puts "Got #{msg[:payload]}, Going to
unsubscribe"
q.unsubscribe
puts "Ready"
end

Should the above code work?
I expected the it would get 1 message and then quits the subscriptions
of the queue, so the flow of the program can continue.

I get this then the program receives a message:
Got Ok, Going to unsubscribe
Ready
.../bunny/lib/bunny/queue08.rb:321:in `unsubscribe': No consumer tag
received (Bunny::UnsubscribeError)

When it does not get any mesage, i.e. it passes more than 3 seconds,
it quits clean.
Should it raise a timeout error?


Thanks!.
_______________________________________________
bunny-amqp-devel mailing list
bunny-am...@rubyforge.org
http://rubyforge.org/mailman/listinfo/bunny-amqp-devel

--
You received this message because you are subscribed to the Google Groups "bunny-amqp" group.
To post to this group, send email to bunny...@googlegroups.com.
To unsubscribe from this group, send email to bunny-amqp+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/bunny-amqp?hl=en.

Chris Duncan

unread,
Apr 18, 2010, 5:55:51 AM4/18/10
to Phillip Neumann, bunny-am...@rubyforge.org
Hi Phillip,

On 18 Apr 2010, at 06:28, Phillip Neumann wrote:

> Hello all,
>
> q = b.queue(responde)
> q.subscribe(:timeout=>3) do |msg|
> puts "Got #{msg[:payload]}, Going to
> unsubscribe"
> q.unsubscribe
> puts "Ready"
> end
>
> Should the above code work?
> I expected the it would get 1 message and then quits the
> subscriptions of the queue, so the flow of the program can continue.
>
> I get this then the program receives a message:
> Got Ok, Going to unsubscribe
> Ready
> .../bunny/lib/bunny/queue08.rb:321:in `unsubscribe': No consumer
> tag received (Bunny::UnsubscribeError)
>
> When it does not get any mesage, i.e. it passes more than 3
> seconds, it quits clean.
> Should it raise a timeout error?
>
>
> Thanks!.

You are getting an error because the code is actually unsubscribing
twice. The unsubscribe in your code block gets executed first,
however you are still in the subscribe loop. So when the timoeout
kicks in, yet another unsubscribe is called and and it fails because
you are already unsubscribed. If you put a break in your code block
then your code should work. Try something like this -

q = b.queue(responde)
q.subscribe(:timeout=>3) do |msg|
puts "Got #{msg[:payload]}, Going to unsubscribe"
q.unsubscribe
puts "Ready"
break
end

HTH.

Regards,

Chris

Chris Duncan

unread,
Apr 18, 2010, 6:17:37 AM4/18/10
to Chris Duncan, bunny-am...@rubyforge.org
Hi Phillip,
I forgot to answer your question about timeout error. A timeout error
is raised, but it is rescued so that a clean unsubscribe can be done.

Cheers,
Reply all
Reply to author
Forward
0 new messages