on_return does not answer information

15 views
Skip to first unread message

Marie S

unread,
Nov 6, 2018, 2:40:32 PM11/6/18
to Ruby RabbitMQ libraries
Hello everyone,

I am trying to use the on_return function according to documentation (http://rubybunny.info/articles/exchanges.html), however it is not working. I am using ruby 2.4.1, rails 5.0.1, bunny 2.12 and my code is the following:

puts "hello1"

 

require 'bunny'

 

puts "hello2"

 

connection = Bunny.new(host: 0.0.0.0, user: 'myuser', pass: 'mypassword')

 

puts "hello3"

 

channel = connection.create_channel

queue = channel.queue('hello')

 

puts "hello4"

 

exch = channel.default_exchange

 

exch.on_return do |return_info, properties, content|

     puts "Got a returned message : #{content}"

     puts return_info.inspect

     puts properties.inspect

     message = content

end

 

exch.publish('Hello World!', routing_key: queue.name, mandatory: true)

 

 

puts " [x] Sent 'Hello World!'"

connection.close


And I get the following answer in console:
hello1
hello2
hello3
hello4
 [x] Sent 'Hello World!'

But nothing about the return_info, properties or content...

How is this?

Michael Klishin

unread,
Nov 6, 2018, 2:44:42 PM11/6/18
to Ruby RabbitMQ libraries
Your code publishes a message so that it is routable. Messages published as
mandatory by definition will be returned only when they cannot be routed to any queues.

In addition your code does not start the connect, although that might be a typo.

Here's an example that use a random routing key with the default exchange, which normally should not be
routed anywhere:


The handler is executed when I run it.

Marie S

unread,
Nov 7, 2018, 5:25:31 AM11/7/18
to Ruby RabbitMQ libraries
Thank you for your answer, indeed it is working when the message is not routed!
I would like to have a return also when the message is routed correctly, it is possible ? According to my tests, turning mandatory to false is not a solution...

Michael Klishin

unread,
Nov 7, 2018, 4:15:14 PM11/7/18
to ruby...@googlegroups.com
No, it is not. I cannot think of a reason to return a message that the publisher already has in case it was successfully routed?


On 7 Nov 2018, at 13:25, Marie S <msac...@gmail.com> wrote:

Thank you for your answer, indeed it is working when the message is not routed!
I would like to have a return also when the message is routed correctly, it is possible ? According to my tests, turning mandatory to false is not a solution...

--
Bunny: http://rubybunny.info
March Hare: http://rubymarchhare.info
 
IRC: #rabbitmq on irc.freenode.net
 
Post to the group: ruby...@googlegroups.com | unsubscribe: ruby-amqp+...@googlegroups.com
---
You received this message because you are subscribed to the Google Groups "Ruby RabbitMQ libraries" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ruby-amqp+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages