Friday, July 02, 2010

"cannot redeclare exchange" error on amqp and RabbitMQ 1.8 - fixed! (at last)

I've been having some trouble with an inherited MacBook Pro, on Leopard (OS X 10.5), trying to get RabbitMQ and the tmm1-amqp gem up and running. The annoying thing is that it was all working fine a few weeks ago, but I ended up having to completely remove MacPorts and do several sudo rm -rf wipeouts and pretty much rebuild the dev environment from scratch. Since then, I re-installed MacPorts and did:
sudo port install rabbitmq-server

After a bit of fiddling about, I got this error (using exactly the same code that worked a few weeks ago):

vendor/gems/tmm1-amqp-0.6.4/lib/mq.rb:225:in `process_frame': PRECONDITION_FAILED - cannot redeclare exchange 'jobs' in vhost 'trigganews.com' with different type, durable or autodelete value in AMQP::Protocol::Exchange::Declare on 1 (MQ::Error)


....several hours of frustrating googling later.....

It turns out that I'd innocently upgraded my version of RabbitMQ 1.8, whereas previously I'd had v1.7.2. This is significant because RMQ 1.8 uses AMQP 0.9, whereas v1.7.2 uses AMQP 0.8 - and this matters because I'm using the tmm1-amqp gem to connect to it, and tmm1-amqp v0.6.4 only supports AMQP 0.8...

(HINT - check the files under the protocol directory to see what version your gem supports)

So - time to downgrade RabbitMQ to 1.7.2 then. Should be straightforward, no? Well, no.

It also turns out that the version of Erlang in MacPorts is now R14A - and guess what? RabbitMQ 1.7.2 doesn't build in Erlang R14A


So I had to create a local MacPorts repo (using the very helpful instructions HERE) from the previous checkin of the Erlang R13B4 portfile and point ports at that.


Then, with a sudo port uninstall rabbitmq-server; sudo port install rabbitmq-server @1.7.2, followed by a blat of the mnesia database files:
sudo rm -rf /opt/local/var/lib/rabbitmq/mnesia/rabbit

- and it all works again. YAY!

(PS - I had to port uninstall and re-install rabbitmq-server twice for it to work properly. So that's always worth a try too - I swear MacOS gets more and more like Windows every day.....:)

Monday, June 21, 2010

EAFNOSUPPORT socket connection issue on Mac OS X

A frustrating problem cropped up this afternoon while trying to get a home-grown Ruby RabbitMQ client to talk to the broker on a MacBook.

The client is based on the EventMachine and AMQP gems, and although for once it worked perfectly on Windows -

(.... yes, frame that last sentence for posterity folks....)

- it was giving bizarre EAFNOSUPPORT socket errors on Mac.

It turns out that, for various obscure reasons, resolving "localhost" is not entirely straightforward on the Mac. There are two quick-and-easy ways round it:

  1. If you have IPv6 mappings for localhost in your /etc/hosts file, comment them out
  2. Replace "localhost" in your connection params with the explicit "127.0.0.1" instead


Sorted!