| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 | .. _broker-rabbitmq:================ Using RabbitMQ================.. contents::    :local:Installation & Configuration============================RabbitMQ is the default broker so it does not require any additionaldependencies or initial configuration, other than the URL location ofthe broker instance you want to use::    >>> BROKER_URL = 'amqp://guest:guest@localhost:5672//'For a description of broker URLs and a full list of thevarious broker configuration options available to Celery,see :ref:`conf-broker-settings`... _installing-rabbitmq:Installing the RabbitMQ Server==============================See `Installing RabbitMQ`_ over at RabbitMQ's website. For Mac OS Xsee `Installing RabbitMQ on OS X`_... _`Installing RabbitMQ`: http://www.rabbitmq.com/install.html.. note::    If you're getting `nodedown` errors after installing and using    :program:`rabbitmqctl` then this blog post can help you identify    the source of the problem:        http://somic.org/2009/02/19/on-rabbitmqctl-and-badrpcnodedown/.. _rabbitmq-configuration:Setting up RabbitMQ-------------------To use celery we need to create a RabbitMQ user, a virtual host andallow that user access to that virtual host:.. code-block:: bash    $ rabbitmqctl add_user myuser mypassword.. code-block:: bash    $ rabbitmqctl add_vhost myvhost.. code-block:: bash    $ rabbitmqctl set_permissions -p myvhost myuser ".*" ".*" ".*"See the RabbitMQ `Admin Guide`_ for more information about `access control`_... _`Admin Guide`: http://www.rabbitmq.com/admin-guide.html.. _`access control`: http://www.rabbitmq.com/admin-guide.html#access-control.. _rabbitmq-osx-installation:Installing RabbitMQ on OS X---------------------------The easiest way to install RabbitMQ on Snow Leopard is using `Homebrew`_; the newand shiny package management system for OS X.In this example we'll install Homebrew into :file:`/lol`, but you canchoose whichever destination, even in your home directory if you want, as one ofthe strengths of Homebrew is that it's relocatable.Homebrew is actually a `git`_ repository, so to install Homebrew, you first need toinstall git. Download and install from the disk image athttp://code.google.com/p/git-osx-installer/downloads/list?can=3When git is installed you can finally clone the repository, storing it at the:file:`/lol` location:.. code-block:: bash    $ git clone git://github.com/mxcl/homebrew /lolBrew comes with a simple utility called :program:`brew`, used to install, remove andquery packages. To use it you first have to add it to :envvar:`PATH`, byadding the following line to the end of your :file:`~/.profile`:.. code-block:: bash    export PATH="/lol/bin:/lol/sbin:$PATH"Save your profile and reload it:.. code-block:: bash    $ source ~/.profileFinally, we can install rabbitmq using :program:`brew`:.. code-block:: bash    $ brew install rabbitmq.. _`Homebrew`: http://github.com/mxcl/homebrew/.. _`git`: http://git-scm.org.. _rabbitmq-osx-system-hostname:Configuring the system host name~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~If you're using a DHCP server that is giving you a random host name, you needto permanently configure the host name. This is because RabbitMQ uses the host nameto communicate with nodes.Use the :program:`scutil` command to permanently set your host name:.. code-block:: bash    $ sudo scutil --set HostName myhost.localThen add that host name to :file:`/etc/hosts` so it's possible to resolve itback into an IP address::    127.0.0.1       localhost myhost myhost.localIf you start the rabbitmq server, your rabbit node should now be `rabbit@myhost`,as verified by :program:`rabbitmqctl`:.. code-block:: bash    $ sudo rabbitmqctl status    Status of node rabbit@myhost ...    [{running_applications,[{rabbit,"RabbitMQ","1.7.1"},                        {mnesia,"MNESIA  CXC 138 12","4.4.12"},                        {os_mon,"CPO  CXC 138 46","2.2.4"},                        {sasl,"SASL  CXC 138 11","2.1.8"},                        {stdlib,"ERTS  CXC 138 10","1.16.4"},                        {kernel,"ERTS  CXC 138 10","2.13.4"}]},    {nodes,[rabbit@myhost]},    {running_nodes,[rabbit@myhost]}]    ...done.This is especially important if your DHCP server gives you a host namestarting with an IP address, (e.g. `23.10.112.31.comcast.net`), becausethen RabbitMQ will try to use `rabbit@23`, which is an illegal host name... _rabbitmq-osx-start-stop:Starting/Stopping the RabbitMQ server~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~To start the server:.. code-block:: bash    $ sudo rabbitmq-serveryou can also run it in the background by adding the :option:`-detached` option(note: only one dash):.. code-block:: bash    $ sudo rabbitmq-server -detachedNever use :program:`kill` to stop the RabbitMQ server, but rather use the:program:`rabbitmqctl` command:.. code-block:: bash    $ sudo rabbitmqctl stopWhen the server is running, you can continue reading `Setting up RabbitMQ`_.
 |