Because there isn’t one distributed with pika
An easy to use pika consumer based on the example pika asynchronous consumer. It probably works with versions of python besides 3.6, but it hasn’t been tested.
Use
With this module installed, simply extend the pika_consumer.Consumer class and override its on_message method. The acknowledge_message method should be called in the overriden method:
from pika_consumer import Consumer
def consume_message(body):
# do stuff with the message body
class ExampleConsumer(Consumer):
def on_message(self, channel, basic_deliver, properties, body):
consume_message(body)
self.acknowledge_message(basic_deliver.delivery_tag)
Then set the consumer consuming:
amqp_url = 'amqp://user:name@rabbit_host:5672/%2F'
queue = 'your_queue'
routing_key = 'your_routing_key'
exchange = 'your_exchange'
consumer = ExampleConsumer(amqp_url, queue, routing_key, exchange)
consumer.consume()
Example
Running vagrant up will create a VM running rabbitmq and python 3.6 running an example consumer which will populate a file in the repo, example.log upon running
vagrant ssh -c '/usr/local/lib/pyenv/versions/3.6.0/bin/python /vagrant/bin/example_publisher.py'
Metadata
Release files for Pika-Consumer 0.0.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pika-consumer-0.0.5.tar.gz | 15.4 kB | Details |
Release files / pika-consumer-0.0.5.tar.gz
| Download URL | pika-consumer-0.0.5.tar.gz |
|---|---|
| Size | 15.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
09a62f66d9a6130eca940037bf8108cbf334f34e71d77ff6f4003de3bbd7f54c
|
|
BLAKE2b-256 checksum How to use checksums |
d58b1273ba801089ed800d3f66af4c310adebe21a0add058e9d7c1f5165d2001
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |