sprockets.mixins.avro-publisher

AMQP Publishing Mixin for publishing a message as an Avro datum.

Version Downloads

Installation

sprockets.mixins.avro-publisher is available on the Python Package Index and can be installed via pip or easy_install:

pip install sprockets.mixins.avro-publisher

Requirements

  • sprockets.mixins.amqp>=2.0.0
  • fastavro>=0.10.1,<1.0.0
  • tornado>=4.2.0,<5.0.0

Example

This examples demonstrates the most basic usage of sprockets.mixins.avro-publisher

export AMQP_URL="amqp://user:password@rabbitmq_host:5672/%2f"
python my-example-app.py
from tornado import gen
from tornado import web
from sprockets.mixins import avro_publisher

def make_app(**settings):
    settings = {'avro_schema_uri_format': 'http://my-schema-repository/%(name)s.avsc'}
    application = web.Application(
        [
            web.url(r'/', RequestHandler),
        ], **settings)

    avro_publisher.install(application)
    return application

class RequestHandler(avro_publisher.PublishingMixin, web.RequestHandler):

    @gen.coroutine
    def get(self, *args, **kwargs):
        body = {'request': self.request.path, 'args': args, 'kwargs': kwargs}
        yield self.avro_amqp_publish(
            'exchange',
            'routing.key',
            'avro-schema-name'
            body)

if __name__ == "__main__":
    application = make_app()
    application.listen(8888)
    logging.basicConfig(level=logging.INFO)
    ioloop.IOLoop.current().start()

Source

sprockets.mixins.avro-publisher source is available on Github at https://github.com/sprockets/sprockets.mixins.avro-publisher

License

sprockets.mixins.avro-publisher is released under the 3-Clause BSD license.

Issues

Please report any issues to the Github project at https://github.com/sprockets/sprockets.mixins.avro-publisher/issues

Version History

2.0.0 Apr 26, 2017

  • Move Mixin to separate file
  • Replace code with latest internal version
  • Rename AvroPublishingMixin to PublishingMixin
  • Update setup.py and requires files to current standard
  • Replace avro library with fastavro library
  • Add avro_amqp_publish helper method
  • Add retry when schema cannot be fetched
    • Delay before retrying is configurable via application.settings:
      • avro_schema_fetch_retry_delay (default 0.5 seconds)
  • Separate HTTP client from common app-based pool to help avoid excessive locking on high load
  • Add unit tests
    • Test execution requires a running AMQP server, see tests.py

`0.1.0`_ Sept 24, 2015

  • Initial implementation