Friday, January 4, 2013

RabbitMQ Configuration via Rake Task


I recently wrapped a Ruby on Rails project in which we were leveraging RabbitMQ as the message broker.   We wanted a quick and easy solution to manage the configuration of the exchanges and queues for deployment.  Since the developers on the team had the occasional need to leverage RabbitMQ locally it made sense to combine those solutions into a rake task.

The task leverages the RabbitMQ command line interface (CLI) which gives you the ability to accomplish most anything.  The problem is that most of the team were not well versed in RabbitMQ and didn't need to be, so to make it simple I first created a 'rake rabbit:setup' task that would pull down the CLI script and place it in the proper path for execution of the remaining tasks.  This only needed to be executed once and they were good to go.

Configuration
To start, I wanted to make the configurations quite simple and familiar to the team so the rabbitmq.yml file was born.  The rabbitmq.yml file allows for configuration of exchanges, queues and bindings between them.  As you will see in the example gist below, you specify the user and password for RabbitMQ.  Exchanges can define all available types, identify an alternate exchange and whether the exchange is internal or not.  Queues allow for simple definition of just the name to including the expiration time and dead letter settings.  Bindings tell an exchange and queue about one another and their relationship.  You can also add a host configuration entry and modify the base command in the rake task if you are interested in configuring a remote RabbitMQ server.

Execution
To configure the system with the CLI is pretty straightforward, you can simply export the rabbit configuration to a JSON file using the 'rabbitmqadmin export rabbit.config' command, make your changes and import the configuration file using 'rabbitmqadmin import rabbit.config'.  The problem is that if you change an existing exchange or queue those changes are ignored.  To work around that problem, I added that ability to delete exchanges and queues so that a fresh configuration would allow for all configurations to be the latest and greatest. You are probably thinking, what about existing messages, if you delete a queue with messages in it you are going to lose data, what kind of solution is that?  Well, relax if you call the delete queues or delete all, which deletes queues and exchanges, it will only remove those queues that are empty and warn you that some queues have messages.  So you can then act on those queues with messages and repeat the delete action to ensure all is well.  If you are not worried about existing messages and data loss you can easily delete the queues containing messages by running 'rake rabbit:delete:queues_by_force'.    

In the long run, I am confident that the task can be improved upon, but it is a great starting point to incorporating a configuration based management of RabbitMQ.

To use this with your Rails project, you will want to download the gist  (https://gist.github.com/4233924) and place the "rabbit.rake" file in your lib/tasks directory.  The tasks expect a yml file, also part of the gist which should be placed in config/rabbitmq.yml.

Rake Tasks
A quick review of the tasks available and their usage.
rake rabbit:setup# Prepares the current system to be able to run the rabbit rake tasks.  It must be run before you can execute any of the other tasks.   
rake rabbit:configure# Configures Exchanges, Queues and Bindings based on config/rabbitmq.yml 
rake rabbit:delete:all                    
# Deletes all Exchanges and empty Queues within RabbitMQ 
rake rabbit:delete:exchanges              
# Deletes all Exchanges within RabbitMQ 
rake rabbit:delete:queues                
 # Deletes all empty Queues within RabbitMQ 
rake rabbit:delete:queues_by_force        
# Deletes all Queues (and messages) within RabbitMQ
Configuration
The rabbitmq.yml file allows for configuration of exchanges, queues and bindings between them.  As you will see below, you specify the user and password for RabbitMQ.  Exchanges can define all available types, identify an alternate exchange and whether the exchange is internal or not.  Queues allow for simple definition of just the name to including the expiration time and dead letter settings.  Bindings tell an exchange and queue about one another and their relationship.

The gist

Wednesday, August 8, 2012

Graphic Design on a budget

   Wow, it has been a while since I have written a blog post, but I wanted to share a quick note for those who are organizing events and may need graphics design work at a reasonable price.  In the past, the graphics for all the Devlink Technical Conference materials were designed by either myself or John Baker.  This year neither of us had much time to work on the t-shirt graphic for DEVLINK 2012 so what to do.  Well, recently I was introduced to a website called 99designs.com where you create a contest for designers to compete against one another to create you custom artwork.  I knew of someone else who had used the site to have a logo created for their company with great results.  Since the site offers a money back guarantee, everything is handled via PayPal, I figured it wouldn't hurt to setup a contest to see what kind of designs I could get.  I could always burn the midnight oil if the attempt was unsuccessful.
     So the way this site works, you can offer as much as you want for a winning design, but the starting price was $149, which is pretty cheap for a graphic artist to create a custom design.  The process was pretty straightforward:

  • Create some specifics about the desired design
  • Let them know what you don't want to see
  • Share any logo's that you might want incorporated
  • Setup the length of time the contest will run.
  • Start the contest and enjoy

I like the length of the contest because they do it in a few stages.  First, you have the open period which is several days, depending on your selection.  Once you get a flood of designs you can converse with the designers to request changes, rates designs and even create a poll so you can get others input.  When you are ready, you can pick finalists from the group and then you repeat the process of communication until you have the winner.  Once you select the winner they upload the files and transfer all ownership of the design to you and they get the money.

In the end, the design selected wasn't what I originally was thinking yet it fits great with the conference.  Below you can see the final graphic.  This design will decorate the back of every DEVLINK 2012 conference shirt and water bottles.  So if you are looking for some graphics work and don't have a huge budget, the 99designs.com website might be worth your time.

DEVLINK 2012 Conference Graphic