python绑定到librabbitmq-c
pylibrabbitmq的Python项目详细描述
Version: | 0.5.0 |
---|---|
Download: | http://pypi.python.org/pypi/pylibrabbitmq/ |
Code: | http://github.com/ask/pylibrabbitmq/ |
Keywords: | rabbitmq, amqp, messaging, librabbitmq, rabbitmq-c, python |
实验性的python绑定到rabbitmq c-librarylibrabbitmq。
您可能应该改用amqplib,但在需要时可以 如果需要额外的性能,请回到这里。
Installation
要安装,您需要编译librabbitmq:
$ mkdir -p /opt/Build/rabbit $ cd /opt/Build/rabbit $ hg clone http://hg.rabbitmq.com/rabbitmq-codegen/ $ hg clone http://hg.rabbitmq.com/rabbitmq-c/ $ cd rabbitmq-c $ autoreconf -i $ ./configure $ make $ make install
然后您可以安装此软件包:
$ cd pylibrabbitmq-x.x.x $ python setup.py install
Examples
>>> from pylibrabbitmq import Connection, Message>>> 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)
Produce
>>> m = Message(body, content_type=None, content_encoding=None, ... delivery_mode=1) >>> channel.basic_publish(m, exchange, routing_key, ...)
Consume
>>> def dump_message(message): ... print("Body:'%s', Proeprties:'%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文件 完整的许可证文本。