This class implements an asynchronous RabbitMQ consumer. It is based on the pika example with modifications for general use. For instance, this modified class can be used to insert the messages in a database, or otherwise process them.
Pika is a pure-Python implementation of the AMQP 0-9-1 protocol including RabbitMQ's extensions.
-
Accept a callback for processing messages. The original writes messages to a log file.
-
Handle and logs error in connecting to the publisher.
-
Log the number of messages read and the number of messages for which processing failed.
-
Add class member data fields to select
- the name of the queue.
- whether to acknowledge receipt.
- closing the connection after reading a given number of messages.
- aconsumer.py — The consumer class.
- consumer_app.py — Example application using the consumer class.
All changes to the original example of an asynchronous consumer are marked with a comment and two
exclamation points !!
.