librabbitmq

repository·master·Indexed 42 days ago

https://github.com/celery/librabbitmq

Python bindings for the rabbitmq-c C-library, providing a high-performance AMQP client. It serves as a core dependency for Kombu and Celery for messaging.

Tokens
1.4K
Snippets
11
Records
12
Agent score
3%

What's inside librabbitmq

  1. Install librabbitmq from source

    master

    To install from a downloaded source tarball, extract the archive, build the package, and run the setup script.

    $ tar xvfz librabbitmq-0.0.0.tar.gz
    $ cd librabbitmq-0.0.0
    $ python setup.py build
    # python setup.py install # as root
  2. Install the development version from git

    master

    To use the latest development version, clone the repository and use the provided Makefile to install or set up a development environment.

    $ git clone git://github.com/celery/librabbitmq.git
    $ cd librabbitmq
    $ make install        # or make develop
  3. Consume messages with basic_consume

    master

    To consume messages, use basic_consume on a channel, providing a queue name and a callback function. The callback function is invoked when a message is received. You must call connection.drain_events() in a loop to process the incoming messages.

    >>> 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()
  4. Poll for messages with basic_get

    master

    If you prefer polling over a continuous consumer, use basic_get to retrieve a single message from a queue. If a message is returned, you should process it and acknowledge it.

    >>> message = channel.basic_get(queue, ...)
    >>> if message:
    ...     dump_message(message)
    ...     print("Body:'%s' Properties:'%s' DeliveryInfo:'%s'" % (
    ...         message.body, message.properties, message.delivery_info))
  5. Basic usage of librabbitmq Stand-alone

    master

    To use librabbitmq directly without Kombu, import Connection and initialize it with connection parameters such as host, userid, password, and virtual_host. You can then create a channel to declare exchanges, queues, and bindings.

    >>> 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)
  6. Manage queue bindings and close connections

    master

    Use queue_unbind to remove a binding between a queue and an exchange, and use .close() on both the channel and the connection to clean up resources.

    >>> channel.queue_unbind(queue, ...)
    >>> channel.close()
    >>> connection.close()
  7. Reference of pip requirements files

    master

    The project provides several specialized requirements files for different environments and tasks:

    • requirements/default.txt: Default requirements for Python 2.7+.
    • requirements/test.txt: Requirements needed to run the full unittest suite.
    • requirements/test-ci.txt: Extra test requirements required by the CI suite (Tox).
    • requirements/doc.txt: Extra requirements required to build the Sphinx documentation.
    • requirements/pkgutils.txt: Extra requirements required to perform package distribution maintenance.