Saturday 2 February 2013

Rails - RabbitMQ - undefined method `topic' for #

So I'm writing a Rails app on the side and one of the things I wanted to use was a massaging system (so I can potentially write apps in different languages and have it share a common message queue). I am going through the tutorials, and they explained that the following should be done using the following:

require "rubygems"
require "bunny"

connection = Bunny.new
connection.start

channel  = connection.create_channel
# topic exchange name can be any string
exchange = channel.topic("weathr", :auto_delete => true)
...

However, when I run my app, I got this error:

undefined method `topic' for #
What gives? Upon looking at the source, it was found that apparently in 0.9.0 (which is still in beta), the api has changed quite a bit if you are using topics.
Therefore the fix is to upgrade to the pre version of 0.9.
In your Gemfile, add the following:

gem "bunny", ">= 0.9.0.pre6"