Setting Up Development RabbitMQ - messagebus/lapine GitHub Wiki

Debugging issues in development can be extremely confusing, as in many cases RabbitMQ will silently fail.

Here is an example rake file that can be added to a project to ensure that the development and test environments have vhosts registered, as well as a user that can connect to and configure exchanges in them.

namespace :lapine do
  USERNAME = 'my-user'
  PASSWORD = 'my-pass'
  VHOSTS = %w(/my.development /my.test)

  task :reset do
    sh "rabbitmqadmin declare user name=#{USERNAME} password=#{PASSWORD} tags=administrator"

    VHOSTS.each do |vhost|
      unless system("rabbitmqadmin list vhosts | grep -c #{vhost} > /dev/null")
        sh "rabbitmqadmin declare vhost name=#{vhost}"
      end
      sh "rabbitmqadmin declare permission vhost=#{vhost} user=#{USERNAME} configure='.*' write='.*' read='.*'"
      sh "rabbitmqadmin declare exchange name=wnl.topic type=topic --vhost=#{vhost} --username=#{USERNAME} --password=#{PASSWORD}"
    end
  end
end

Most of our projects define a rake reset task that sets up the development environment from scratch. Our lapine:reset task can be prepended to the reset chain as follows:

task :reset => 'lapine:reset'