跳转到主要内容

一个简单的Django应用程序,用于启用通配符入口

项目描述

数据入口

这是一个简单的入口应用程序,将所有传入的消息存储在队列中,并按集合分类。

数据始终以消息的形式发布到特定的集合中,可以通过消费者从队列中处理。

用法

1. 添加应用程序

在已安装的应用程序中启用

INSTALLED_APPS = [
    ...,
    'ingress'
]

2. 创建和配置消费者

实现一个消费者来处理数据。注意:如果您(可能暂时)想导入数据但不消费它,可以不部署消费者而部署入口。

class MyConsumer(IngressConsumer):
    collection_name = 'foobar'

    def consume_message(self):
        ...

    # by default consume_batch() loops and calls consume_message(), but it can be 
    # overridden to have more control, for instance to bulk insert into the db.
    def consume_batch(self):
        ...

在settings.py中配置消费者。每个消费者都必须实现BaseConsumer并实现适当的方法(见上面)。在消费时,消费者会接收到与Consumer.collection_name对应的集合中的所有消息。

# A list of classpaths to implementations of ingress.consumer.IngressConsumer
# to handle the data in the queue.
INGRESS_CONSUMER_CLASSES = ['app.module.MyConsumer']

3. 身份验证和授权

至少配置身份验证类或权限类,或完全禁用身份验证

# A list of authentication classes used in the ingress view.
# See https://django-rest-framework.django.ac.cn/api-guide/authentication/
INGRESS_AUTHENTICATION_CLASSES = []

# A list of permission classes used in the ingress view.
# See https://django-rest-framework.django.ac.cn/api-guide/permissions/
INGRESS_PERMISSION_CLASSES = []

# If the queue is used without the endpoint, authentication checks can be 
# disabled by setting this flag to True. Defaults to False.
INGRESS_DISABLE_ALL_AUTH_PERMISSION_CHECKS = True

接受发布到非现有集合的数据?

默认情况下,发布到非现有集合的数据不会存储,并且对于此类请求将返回错误。

如果应将发布到非现有集合的数据存储,则修改设置

# Whether or not to accept data posted to a non-existing collection.
INGRESS_ACCEPT_NEW_COLLECTIONS = False

设置其他于UTF-8时的编码

默认情况下,入口使用UTF-8解码所有传入数据。如果需要在存储到数据库之前以不同方式解码数据,则配置设置

# Encoding that the data will be in when posted to the ingress
INGRESS_ENCODING = "utf-16"

项目详情


下载文件

下载适用于您平台文件的文件。如果您不确定选择哪一个,请了解有关安装包的更多信息。

源分布

datapunt-data-ingress-2.3.0.tar.gz (17.9 kB 查看哈希值)

上传 源代码

构建分布

datapunt_data_ingress-2.3.0-py3-none-any.whl (28.5 kB 查看哈希值)

上传 Python 3