Thursday, February 20, 2014

Install RabbitMQ Management Console in Travis CI.

If you are writing integration tests and need a local RabbitMQ instance to test against, you can actually spin up an instance in Travis CI (this is built into the platform).  One thing that does not come with Travis's RabbitMQ instance is the RabbitMQ Management Console.  The RabbitMQ Management Console is the friendly web UI for RabbitMQ, but it also provides RESTful access for configuring the server.

Adding the RabbitMQ Management Console is easy.  Simply add some install tasks:

services:
  - rabbitmq
install:
    - sudo rabbitmq-plugins enable rabbitmq_management
    - sudo rabbitmq-plugins enable rabbitmq_federation
    - sudo rabbitmq-plugins enable rabbitmq_federation_management
    - sudo service rabbitmq-server restart

The services property instructs Travis CI to start RabbitMQ.  I don't know if this is necessary because I'm uncertain if it instructs Travis CI to use a specific VM, or if it simply starts the RabbitMQ service.  My guess is that it is unnecessary, but since it does add much overhead (i.e. time) to the testing, I've left it in the configuration.

The install command allows us to execute command line tasks on a CentOS box (the build machine).  The Travis CI guys have graciously given us access to RabbitMQ's sbin folder, so we can easily add new plugins.  Keep in mind these tasks have to be ran with sudo.  If you do not, the build will fail do to permissions issues.

Finally, for the purposes of my tests, I need two RabbitMQ instances alive so I can perform federation.  You can easily launch a second RabbitMQ instance with the following command in Travis CI:

before_script:
    - sudo RABBITMQ_NODE_PORT=5673 RABBITMQ_SERVER_START_ARGS="-rabbitmq_management listener [{port,15673}]" RABBITMQ_NODENAME=hare rabbitmq-server -detached

You will need to ensure that the second RabbitMQ node's name does not conflict with the current one.  In the command about, you will notice I specified:  RABBITMQ_NODENAME=hare.  We need to make sure the local Travis CI build box responds to hare on the network.  You can add /etc/hosts aliases in Travis CI like this:

addons:
  hosts:
    - rabbit
    - hare

And that's it!  You should have two RabbitMQ server instances, both with their own Management Console instances running in Travis CI.

For the complete .travis.yml head over to my open source Java bindings and utilities for RabbitMQ called Rabbid Management:  https://github.com/Berico-Technologies/RabbidManagement/blob/master/.travis.yml   

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.