Skip to main content

Easy RabbitMQ/ZeroMQ (AMQP) messaging queue.

Project description

Authors:

Ask Solem (askh@opera.com)

Version:
0.3.8

Simple RabbitMQ/ZeroMQ (AMQP) messaging queue with optional support for Django.

Note This software is not finished. And is likely to change drastically in the near future.

Introduction

carrot is a messaging queue framework with optional support for Django_, built on top of py-amqplib. Before you start playing with carrot, you should read the excellent article on RabbitMQ under python by Jason: Rabbits and warrens.

Installation

You can install carrot either via the Python Package Index (PyPI) or from source.

To install using pip,:

$ pip install carrot

To install using easy_install,:

$ easy_install carrot

If you have downloaded a source tarball you can install it by doing the following,:

$ python setup.py build
# python setup.py install # as root

Example

This is a carrot implementation of the example publisher and consumer described in the article Rabbits and warrens

>>> from carrot.messaging import Publisher, Consumer
>>> class PostOfficePublisher(Publisher):
...     exchange = "sorting_room"
...     routing_key = "jason"
>>> class PostOfficeConsumer(Consumer):
...     queue = "po_box"
...     exchange = "sorting_room"
...     routing_key = "jason"
...
...     def receive(self, message_data, message):
...         """This is the method that is called whenever we
...         receieve a message in this queue."""
...         print("Received: %s" % message_data)

By default every message is encoded using JSON, if you don’t want this you have to set the encoding attribute in the producer and the decoding attribute in the consumer to lambda x: x.

There are lots of other options for producers and consumers for which the only documentation right now is the source code (sorry!)

To start sending and receiving messages with these classes, you first have to configure the AMQP server for your django app. If you have a RabbitMQ server running on localhost you can add these settings to your settings.py,:

AMQP_SERVER = "localhost"
AMQP_PORT = 5678
AMQP_USER = "my_rabbitmq_user"
AMQP_PASSWORD = "my_rabbitmq_user_password"
AMQP_VHOST = "virtual_host_to_use"

First we have to set up the connection instance, and map it to the publishers and consumers:

>>> from carrot.connection import DjangoAMQPConnection
>>> po_publisher = PostOfficePublisher(
...                             connection=DjangoAMQPConnection())
>>> po_consumer = PostOfficeConsumer(
...                             connection=DjangoAMQPConnection())

Then, finally, we can send and receive some messages:

>>> po_publisher.send({"My message": ["foo", "bar", "baz"]})
>>> po_publisher.close()
>>> po_consumer.process_next()
Received: {"My message": ["foo", "bar", "baz"]}

License

This software is licensed under the New BSD License. See the LICENSE file in the top distribution directory for the full license text.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

carrot-0.3.8.tar.gz (11.6 kB view details)

Uploaded Source

File details

Details for the file carrot-0.3.8.tar.gz.

File metadata

  • Download URL: carrot-0.3.8.tar.gz
  • Upload date:
  • Size: 11.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for carrot-0.3.8.tar.gz
Algorithm Hash digest
SHA256 36792b4937891f86f99fc52f6c7da925ad750472a941d21d4c1f5a8a812369ab
MD5 acf871ed9016fd659cf5751a87fa06f3
BLAKE2b-256 a758a4f81bd51ab710220087485839d0daeedef2e05736a62b6fe74cca504208

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page