mirror of
https://github.com/sprockets/sprockets.mixins.avro-publisher.git
synced 2024-11-25 19:29:54 +00:00
aec6974bc7
Move mixin to its own file Add helper method for Avro publishing Update setup.py and requires files to current standard Replace avro with fastavro Update MANIFEST.in with new requires files Add setup.cfg Add docs dir with index and history files Add unit tests Add unit tests to Travis CI config Add Python 2.7, pypy, and 3.5.1 to Travis CI config h/t to @gmr for the new internals
58 lines
1.5 KiB
Python
58 lines
1.5 KiB
Python
"""The AvroPublishingMixin adds Apache Avro serialization to the
|
|
RabbitMQ publishing capabilities in sprockets.mixins.amqp
|
|
|
|
To configure the URL format for the avro schema, add a
|
|
Tornado application setting called ``avro_schema_uri_format``. The format
|
|
should be similar to the following:
|
|
|
|
``http://my-schema-repository/avro/%(name)s.avsc``
|
|
|
|
Take note also of the required configurations in sprockets.mixins.amqp
|
|
"""
|
|
import logging
|
|
|
|
LOGGER = logging.getLogger(__name__)
|
|
|
|
try:
|
|
from sprockets.mixins import amqp
|
|
|
|
from sprockets.mixins.avro_publisher.mixins import (PublishingMixin,
|
|
SchemaFetchError)
|
|
|
|
except ImportError as error:
|
|
class PublishingMixin(object):
|
|
def __init__(self, *args, **kwargs):
|
|
raise error
|
|
|
|
class SchemaFetchError(Exception):
|
|
def __init__(self, *args, **kwargs):
|
|
raise error
|
|
|
|
class amqp(object):
|
|
|
|
error = None
|
|
|
|
@classmethod
|
|
def install(cls, *args, **kwargs):
|
|
raise cls.error
|
|
|
|
amqp.error = error
|
|
|
|
version_info = (2, 0, 0)
|
|
__version__ = '.'.join(str(v) for v in version_info)
|
|
|
|
|
|
def install(application, **kwargs):
|
|
"""Call this to install avro publishing for the Tornado application.
|
|
|
|
:rtype: bool
|
|
|
|
"""
|
|
amqp.install(application, **kwargs)
|
|
|
|
if 'avro_schema_uri_format' not in application.settings:
|
|
LOGGER.warning('avro_schema_uri_format is not set, using default')
|
|
|
|
setattr(application, 'avro_schemas', {})
|
|
|
|
return True
|