Simplified PostgreSQL client built upon Psycopg2
Project description
An opinionated Rejected consumer class that automatically decodes messages sent as Avro datum.
For applications that can share schema files, Avro datum provide small, contract based binary serialization format. Leveraging AMQP’s Type message property to convey the Avro schema file for decoding the datum, the DatumConsumer extends Rejected’s rejected.consumer.SmartConsumer class adding automated deserialization of AMQP messages serialized as Avro datums.
Installation
avroconsumer is available on the Python package index.
Usage
To use the DatumConsumer, first you need to set the schema_path configuration setting in the rejected configuration file. The following snippet demonstrates an example configuration:
Consumers:
apns_push:
consumer: app.Consumer
connections: [rabbit1]
qty: 1
queue: datum
qos_prefetch: 1
ack: True
max_errors: 5
config:
schema_path: /etc/avro-schemas/
If messages are published with a AMQP type message property of foo and a content-type property of application/vnd.apache.avro.datum, the DatumConsumer will use the Avro schema file /etc/avro-schemas/foo.avsc to deserialize messages
The following example code shows how implement the DatumConsumer.
import avroconsumer
class MyConsumer(avroconsumer.DatumConsumer):
def process(self):
LOGGER.debug('Decoded avro datum data: %r', self.body)
As with any instance of rejected.consumer.Consumer, the avroconsumer.DatumConsumer can automatically rejected messages based upon the type message property. Simply set the MESSAGE_TYPE attribute of your consumer and any messages received that do not match that message type will be rejected. The following example demonstrates setting the message type:
import avroconsumer
class MyConsumer(avroconsumer.DatumConsumer):
MESSAGE_TYPE = 'foo'
def process(self):
LOGGER.debug('Decoded avro datum data: %r', self.body)
Requirements
avro <https://pypi.python.org/pypi/avro>
rejected <https://pypi.python.org/pypi/rejected>
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for avroconsumer-0.1.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5aa51e5c84853f0c59cbec9625bd311b759a5d689ec8feb4fd0c0683e4e9f2c9 |
|
MD5 | 9346fec5b3bb5442929230f48836a275 |
|
BLAKE2b-256 | fe5d4548322ecaa66f255ad10e2a8185ff29f6548e60e8fdc33ab2f5f6119590 |