sprockets.mixins.avro-publi.../sprockets/mixins/avro_publisher/__init__.py

59 lines
1.5 KiB
Python
Raw Normal View History

"""The AvroPublishingMixin adds Apache Avro serialization to the
RabbitMQ publishing capabilities in sprockets.mixins.amqp
2015-09-24 18:29:18 +00:00
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
2015-09-24 18:29:18 +00:00
"""
import logging
LOGGER = logging.getLogger(__name__)
2015-09-24 18:29:18 +00:00
try:
from sprockets.mixins import amqp
2015-09-24 18:29:18 +00:00
from sprockets.mixins.avro_publisher.mixins import (PublishingMixin,
SchemaFetchError)
2015-09-24 18:29:18 +00:00
except ImportError as error:
class PublishingMixin(object):
def __init__(self, *args, **kwargs):
raise error
2015-09-24 18:29:18 +00:00
class SchemaFetchError(Exception):
def __init__(self, *args, **kwargs):
raise error
2015-09-24 18:29:18 +00:00
class amqp(object):
2015-09-24 18:29:18 +00:00
error = None
2015-09-24 18:29:18 +00:00
@classmethod
def install(cls, *args, **kwargs):
raise cls.error
2015-09-24 18:29:18 +00:00
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