使用rabbitmq-c库的amqp客户端。
librabbitmq的Python项目详细描述
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 |
python绑定到rabbitmq c-libraryrabbitmq-c。 由kombu和芹菜支持。
Installation
通过PIP安装:
$ pip install librabbitmq
或者,通过简易安装进行安装:
$ easy_install librabbitmq
Downloading and installing from source
然后按以下步骤安装:
$ 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
您可以通过执行以下操作克隆存储库:
$ git clone git://github.com/celery/librabbitmq.git
然后按以下步骤安装:
$ cd librabbitmq $ make install # or make develop
Examples
与kombu一起使用:
>>> from kombu import Connection >>> x = Connection("librabbitmq://")
独立:
>>> 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
此软件是根据Mozilla Public License授权的。 请参阅顶部分发目录中的LICENSE-MPL-RabbitMQ文件 完整的许可证文本。