2017-04-13 21:13:22 +00:00
|
|
|
"""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``
|
|
|
|
|
2017-04-13 21:13:22 +00:00
|
|
|
Take note also of the required configurations in sprockets.mixins.amqp
|
2015-09-24 18:29:18 +00:00
|
|
|
"""
|
|
|
|
import logging
|
|
|
|
|
2017-04-13 21:13:22 +00:00
|
|
|
LOGGER = logging.getLogger(__name__)
|
2015-09-24 18:29:18 +00:00
|
|
|
|
2017-04-13 21:13:22 +00:00
|
|
|
try:
|
|
|
|
from sprockets.mixins import amqp
|
2015-09-24 18:29:18 +00:00
|
|
|
|
2017-04-13 21:13:22 +00:00
|
|
|
from sprockets.mixins.avro_publisher.mixins import (PublishingMixin,
|
|
|
|
SchemaFetchError)
|
2015-09-24 18:29:18 +00:00
|
|
|
|
2017-04-13 21:13:22 +00:00
|
|
|
except ImportError as error:
|
|
|
|
class PublishingMixin(object):
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
raise error
|
2015-09-24 18:29:18 +00:00
|
|
|
|
2017-04-13 21:13:22 +00:00
|
|
|
class SchemaFetchError(Exception):
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
raise error
|
2015-09-24 18:29:18 +00:00
|
|
|
|
2017-04-13 21:13:22 +00:00
|
|
|
class amqp(object):
|
2015-09-24 18:29:18 +00:00
|
|
|
|
2017-04-13 21:13:22 +00:00
|
|
|
error = None
|
2015-09-24 18:29:18 +00:00
|
|
|
|
2017-04-13 21:13:22 +00:00
|
|
|
@classmethod
|
|
|
|
def install(cls, *args, **kwargs):
|
|
|
|
raise cls.error
|
2015-09-24 18:29:18 +00:00
|
|
|
|
2017-04-13 21:13:22 +00:00
|
|
|
amqp.error = error
|
|
|
|
|
|
|
|
version_info = (2, 0, 0)
|
|
|
|
__version__ = '.'.join(str(v) for v in version_info)
|
2016-03-15 17:53:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
def install(application, **kwargs):
|
2017-04-13 21:13:22 +00:00
|
|
|
"""Call this to install avro publishing for the Tornado application.
|
|
|
|
|
|
|
|
:rtype: bool
|
|
|
|
|
|
|
|
"""
|
2016-03-15 17:53:46 +00:00
|
|
|
amqp.install(application, **kwargs)
|
|
|
|
|
|
|
|
if 'avro_schema_uri_format' not in application.settings:
|
|
|
|
LOGGER.warning('avro_schema_uri_format is not set, using default')
|
|
|
|
|
2017-04-13 21:13:22 +00:00
|
|
|
setattr(application, 'avro_schemas', {})
|
|
|
|
|
2016-03-15 17:53:46 +00:00
|
|
|
return True
|