summaryrefslogtreecommitdiff
path: root/README.rst
blob: d39f64ac01b15177c09dea2f5afd9cc157d85afa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
================================================================
 librabbitmq - Python AMQP Client using the rabbitmq-c library.
================================================================

:Version: 2.0.0
:Download: http://pypi.python.org/pypi/librabbitmq/
:Code: http://github.com/celery/librabbitmq/
:Keywords: rabbitmq, amqp, messaging, librabbitmq, rabbitmq-c, python,
           kombu, celery

.. contents::
    :local:

Python bindings to the RabbitMQ C-library `rabbitmq-c`_.
Supported by Kombu and Celery.

.. _`rabbitmq-c`: https://github.com/alanxz/rabbitmq-c

Installation
============

Install via pip::

    $ pip install librabbitmq

or, install via easy_install::

    $ easy_install librabbitmq

Downloading and installing from source
--------------------------------------

Download the latest version from
    http://pypi.python.org/pypi/librabbitmq/

Then install it by doing the following,::

    $ tar xvfz librabbitmq-0.0.0.tar.gz
    $ cd librabbitmq-0.0.0
    $ python setup.py build
    # python setup.py install # as root

Using the development version
-----------------------------

You can clone the repository by doing the following::

    $ git clone git://github.com/celery/librabbitmq.git

Then install it by doing the following::

    $ cd librabbitmq
    $ make install        # or make develop

Examples
========

Using with Kombu::

    >>> from kombu import Connection
    >>> x = Connection("librabbitmq://")


Stand-alone::

    >>> from librabbitmq import Connection

    >>> conn = Connection(host="localhost", userid="guest",
    ...                   password="guest", virtual_host="/")

    >>> channel = conn.channel()
    >>> channel.exchange_declare(exchange, type, ...)
    >>> channel.queue_declare(queue, ...)
    >>> channel.queue_bind(queue, exchange, routing_key)

Producing
---------

::

    >>> channel.basic_publish(body, exchange, routing_key, ...)

Consuming
---------

::

    >>> def dump_message(message):
    ...     print("Body:'%s', Properties:'%s', DeliveryInfo:'%s'" % (
    ...         message.body, message.properties, message.delivery_info))
    ...     message.ack()

    >>> channel.basic_consume(queue, ..., callback=dump_message)

    >>> while True:
    ...    connection.drain_events()

Poll
----

::

    >>> message = channel.basic_get(queue, ...)
    >>> if message:
    ...     dump_message(message)
    ...     print("Body:'%s' Properties:'%s' DeliveryInfo:'%s'" % (
    ...         message.body, message.properties, message.delivery_info))


Other
-----

::

    >>> channel.queue_unbind(queue, ...)
    >>> channel.close()
    >>> connection.close()

License
=======

This software is licensed under the ``Mozilla Public License``.
See the ``LICENSE-MPL-RabbitMQ`` file in the top distribution directory
for the full license text.

.. # vim: syntax=rst expandtab tabstop=4 shiftwidth=4 shiftround