Random thoughts of a warped mind…

January 18, 2012

Loading specific version of Ruby AMQP gem

Filed under: Linux,Ruby — Srinivas @ 16:27

I recently installed Chef and Chef-server on a server of mine which already had the AMQP and EventMachine gems installed on it. Chef also used ruby code to access rabbitmq and ended up installing from Chefs apt repo, the packages libeventmachine-ruby and libamqp-ruby.

Once this was done, pre-existing code of mine which uses AMQP gem stopped working with the error:

/pathto/myprog.rb:79: uninitialized constant AMQP::Channel (NameError)
from /usr/lib/ruby/1.8/eventmachine.rb:257:in `call’
from /usr/lib/ruby/1.8/eventmachine.rb:257:in `run_machine’
from /usr/lib/ruby/1.8/eventmachine.rb:257:in `run’
from /pathto/myprog.rb:71

Tested and realized that the newly installed eventmachine package was’nt to blame (was version 0.12.10-1) while my previously installed Gem was 0.12.10.

Checked up and found that the Opscode package amqp module however was version 0.6.7 while the pre-existing gem on my machine was version 0.8.4.

$# uname -a
Linux cyclops.mydomain.com 2.6.38-11-virtual #50-Ubuntu SMP Mon Sep 12 21:51:23 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux
$# ruby -v
ruby 1.8.7 (2010-08-16 patchlevel 302) [x86_64-linux]

$# cat /etc/apt/sources.list.d/opscode.list
deb http://apt.opscode.com/ natty-0.10 main

$# dpkg -s libamqp-ruby
Package: libamqp-rubyStatus: install ok installed
Priority: optionalSection: rubyInstalled-Size: 164
Maintainer: Debian Ruby Extras Maintainers <[email protected]>
Architecture: all
Version: 0.6.7-0opscode1
Depends: ruby1.8 | ruby-interpreter, libeventmachine-ruby (>= 0.12.4)
Description: AMQP client implementation in Ruby/EventMachine. An implementation of the AMQP protocol in Ruby/EventMachine for writing clients to the RabbitMQ message broker.
Homepage: http://github.com/ruby-amqp/amqp
Ruby-Versions: ruby1.8 ruby1.9.1

$# gem list | grep amqp
amqp (0.8.4)

I dont want to wipe out the deb packages from my server since I need  Chef to work. And I dont want to modify my existing ruby code to have to  work with the older 0.6.7 amqp gem. So heres what I did in my ruby code  to fix this issue:

gem ‘amqp’,'>= 0.8.4′

require ‘amqp’

I know its not optimum but this works for me but there are’nt too many programs I had to change (just some internal libraries rest of my code uses) – But maybe whenever Opscode fixes their stuff, their libamqp-ruby will be set to build from the 0.8.x version rather than the _pretty_obsolete_ 0.6.7 version.

Powered by WordPress