From pneumann at gmail.com Sun Apr 18 01:28:57 2010 From: pneumann at gmail.com (Phillip Neumann) Date: Sun, 18 Apr 2010 01:28:57 -0400 Subject: [bunny-amqp-devel] unsubscribe Message-ID: <48F7C919-B79D-4E5F-9F22-1377BEE00075@gmail.com> 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!. From celldee at gmail.com Sun Apr 18 05:55:51 2010 From: celldee at gmail.com (Chris Duncan) Date: Sun, 18 Apr 2010 10:55:51 +0100 Subject: [bunny-amqp-devel] unsubscribe In-Reply-To: <48F7C919-B79D-4E5F-9F22-1377BEE00075@gmail.com> References: <48F7C919-B79D-4E5F-9F22-1377BEE00075@gmail.com> Message-ID: <46F920FA-FD82-45C4-B45D-55CF6C108B13@gmail.com> 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 From celldee at gmail.com Sun Apr 18 06:17:37 2010 From: celldee at gmail.com (Chris Duncan) Date: Sun, 18 Apr 2010 11:17:37 +0100 Subject: [bunny-amqp-devel] unsubscribe In-Reply-To: <46F920FA-FD82-45C4-B45D-55CF6C108B13@gmail.com> References: <48F7C919-B79D-4E5F-9F22-1377BEE00075@gmail.com> <46F920FA-FD82-45C4-B45D-55CF6C108B13@gmail.com> Message-ID: <756F7ADD-41EB-429B-9528-8B9BA99EED23@gmail.com> Hi Phillip, On 18 Apr 2010, at 10:55, Chris Duncan wrote: > 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 > 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, Chris