Jesse's Software Engineering Blog
Ubuntu RabbitMQ Install
Often times when developing robust web applications the need arises to be able to asynchronously process information. Large tasks, such as report aggregation, that would cause a web front end to stall can be done asynchronously on a set schedule, or as a reaction to an event, allowing for clients to just consume data and not worry about formatting or processing it.
While there are numerous ways of doing this, a message queue is a very common approach. Messages, or queued tasks, are sent over a network to be stored for future processing. RabbitMQ is a messaging broker, giving an application a common platform (server) to send and receive messages. The RabbitMQ server offers a safe place for messages to live and has numerous configuration options for defining message communication protocol, advanced cluster configurations, user management, monitoring GUI, and much more.
RabbitMQ has an Ubuntu repo but requires erlang which it does not always install. The following steps will install the RabbitMQ server on Ubuntu 14.04.
sudo apt-get update # install erlang sudo apt-get install erlang -y sudo apt-get install erlang-nox -y # get deb package echo deb http://www.rabbitmq.com/debian/ testing main | sudo tee /etc/apt/sources.list # add key wget http://www.rabbitmq.com/rabbitmq-signing-key-public.asc sudo apt-key add rabbitmq-signing-key-public.asc # install server sudo apt-get update sudo apt-get install rabbitmq-server -y
Start the server and verify it is running:
sudo service rabbitmq-server start sudo service rabbitmq-server status
Next install the management GUI:
sudo rabbitmq-plugins enable rabbitmq_management
By default the management GUI can be accessed via port 15672, using guest/guest as the user/pwd. NOTE: RabbitMQ does not allow remote login using the guest user.
Add Management User
If RabbitMQ was installed on a remote server, or Vagrant, the guest credentials will not work as guest can only connect over the loopback interface (localhost). This can be changed view the loopback_users config, or a new user can be created using the rabbitmqctl command line tool.
To create a new user
sudo rabbitmqctl add_user admin p@ssw0rd! sudo rabbitmqctl set_user_tags admin administrator sudo rabbitmqctl set_permissions -p / admin ".*" ".*" ".*" sudo rabbitmqctl delete_user guest sudo service rabbitmq-server restart
For more information on the various tags
For more information on the permissions
The web GUI should now be accessible to the new user:
When the RabbitMQ management GUI is installed remotely, the server will likely need to be updated to allow traffic through port 15672. This can be done by adding the following rule to the iptables
# add rule, restart service sudo iptables -A INPUT -p tcp --dport 15672 -m state --state NEW,ESTABLISHED -j ACCEPT sudo service ufw reload # verify port is listening netstat -tulpn tcp 0 0 0.0.0.0:15672 0.0.0.0:* LISTEN -
When using a managed service, such as an AWS EC2, a security group entry should be created for that instance:
Custom TCP Rule TCP 15672 0.0.0.0/0
The ability to run asynchronous processes is essential to large scale web development projects. RabbitMQ is extremely robust and flexible for setting up a message broker system for storing and delivering messages. There are also numerous API wrappers written in various different languages to allow RabbitMQ to easily integrate into different code bases. Now that the RabbitMQ server has been installed the next steps would be to install clients and set up the queues.