Skip to main content

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.

Version Downloads License

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

avroconsumer-0.1.0.tar.gz (4.1 kB view hashes)

Uploaded Source

Built Distribution

avroconsumer-0.1.0-py2.py3-none-any.whl (5.0 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page