Diff for "RabbitMQ"

Not logged in - Log In / Register

Differences between revisions 2 and 3
Revision 2 as of 2011-09-19 14:31:18
Size: 2330
Comment:
Revision 3 as of 2011-09-19 14:56:06
Size: 2471
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
= RabbitMQ in Launchpad = #format rst

=====================
RabbitMQ in Launchpad
=====================
Line 7: Line 11:
== Crash course in RabbitMQ == Crash course in RabbitMQ
========================
Line 18: Line 23:
See this producer example: See this producer example::
Line 20: Line 25:
{{{
from amqplib import client_0_8 as amqp

conn = amqp.Connection(
    host='localhost:5672',
    userid='guest',
password='guest',
    virtual_host='/', # "/" is the default vhost.
    insist=False)
ch = conn.channel()
ch.exchange_declare(
    "XXX.notifications-exchange",
    "direct",
durable=False, # Whether the exchange persists or not.
    auto_delete=False)
ch.queue_declare("XXX.notifications-queue.foo")
ch.queue_bind(
    queue='XXX.notifications-queue.foo',
    exchange='XXX.notifications-exchange',
    routing_key="XXX.notifications-queue.foo")
msg = amqp.Message('{"boo": 1}')
ch.basic_publish(
    exchange="XXX.notifications-exchange",
    routing_key="XXX.notifications-queue.foo",
    msg=msg)
}}}
 from amqplib import client_0_8 as amqp
   conn = amqp.Connection(
  host='localhost:5672',
     userid='guest',
 
password='guest',
     virtual_host='/', # "/" is the default vhost.
     insist=False)
 ch = conn.channel()
 ch.exchange_declare(
     "XXX.notifications-exchange",
     "direct",
 
durable=False, # Whether the exchange persists or not.
     auto_delete=False)
 ch.queue_declare("XXX.notifications-queue.foo")
 ch.queue_bind(
     queue='XXX.notifications-queue.foo',
     exchange='XXX.notifications-exchange',
     routing_key="XXX.notifications-queue.foo")
 msg = amqp.Message('{"boo": 1}')
 ch.basic_publish(
     exchange="XXX.notifications-exchange",
     routing_key="XXX.notifications-queue.foo",
     msg=msg)
Line 48: Line 51:
== Long polling == Long polling
============
Line 50: Line 54:
See [[https://launchpad.net/txlongpoll|lp:txlongpoll]] for a project that describes a so-called long-polling server. It is Twisted-based and maps HTTP requests to consumption of messages on Rabbit queues. See `lp:txlongpoll`_ for a project that describes a so-called long-polling server. It is Twisted-based and maps HTTP requests to consumption of messages on Rabbit queues.

.. _lp:txlongpoll: https://launchpad.net/txlongpoll
Line 54: Line 60:
=== Long poll request format === Long poll request format
------------------------
Line 58: Line 65:
=== Workflow === Workflow
--------
Rendering of reStructured text is not possible, please install Docutils.

=====================
RabbitMQ in Launchpad
=====================

This page describes how we use RabbitMQ in Launchpad and some of its deployment nuances.

This page is also currently WIP.

Crash course in RabbitMQ
========================

Each RabbitMQ instance has one or more "virtual hosts" or vhosts. These are a convenient way to manage separate instances of rabbit via the same server instance - it could also be achieved with separate server instances, but you must set up at least one vhost on the instance.

RabbitMQ has queues, which have a producer and one or more consumers. The producer needs to set up:
 * an "exchange"
 * a "routing key"
 * a "queue"

It then needs to bind the queue to zero or more pairs of exchange and routing key.  When sending a message, it sends to the exchange and routing key combination, and the message is then available to consumers on all the queues that are bound to those.

See this producer example::

 from amqplib import client_0_8 as amqp
 
 conn = amqp.Connection(
     host='localhost:5672',
     userid='guest',
     password='guest',
     virtual_host='/',  # "/" is the default vhost.
     insist=False)
 ch = conn.channel()
 ch.exchange_declare(
     "XXX.notifications-exchange",
     "direct",
     durable=False,  # Whether the exchange persists or not.
     auto_delete=False)
 ch.queue_declare("XXX.notifications-queue.foo")
 ch.queue_bind(
     queue='XXX.notifications-queue.foo',
     exchange='XXX.notifications-exchange',
     routing_key="XXX.notifications-queue.foo")
 msg = amqp.Message('{"boo": 1}')
 ch.basic_publish(
     exchange="XXX.notifications-exchange",
     routing_key="XXX.notifications-queue.foo",
     msg=msg)


Long polling
============

See `lp:txlongpoll`_ for a project that describes a so-called long-polling server. It is Twisted-based and maps HTTP requests to consumption of messages on Rabbit queues.

.. _lp:txlongpoll: https://launchpad.net/txlongpoll

This means we can have Javascript in the browser doing XHR to the long poll server and block on long-running jobs until the job emits a message saying it's done. There is currently work in progress to make merge proposal diffs appear as soon as the job completes so that the end user doesn't have to refresh the MP page.

Long poll request format
------------------------

XXX (detail the URL; uuid, sequence etc)

Workflow
--------

XXX

RabbitMQ (last edited 2011-09-30 14:08:47 by julian-edwards)