Skip to main content

Explicit-Kafka

Набор компонентов для интеграции explicit с kafka.

Содержит реализацию адаптера обмена сообщениями через Kafka.

Пример использования

Настройка адаптера

# persons/core/apps.py
from django.apps.config import AppConfig as AppConfigBase


class AppConfig(AppConfigBase):

    name = __package__
    
    def _setup_adapter(self):
        from explicit.kafka.adapters.messaging import Adapter
        from explicit.kafka.adapters.messaging import PublishConfig
        from explicit.kafka.adapters.messaging import SubscribeConfig

        from persons import core
        
        # конфигурация адаптера
        adapter_base_config = {'bootstrap.servers': 'kafka:9092'}
        publish_config = PublishConfig(adapter_base_config)
        subscribe_config = SubscribeConfig(adapter_base_config | {'group.id': f'edu.persons'})
    
        adapter = Adapter(subscribe_config=subscribe_config, publish_config=publish_config)
        core.adapter = adapter

    def ready(self):
        self._setup_adapter()

Отправка сообщений

# persons/core/persons/services/handlers/events.py

def on_person_created(
    event: 'PersonCreated',
    messaging_adapter: 'AbstractMessagingAdapter'
):
    messaging_adapter.publish('edu.persons.person', event.dump())

Подписка на сообщения

# education/entrypoints/eventconsumer.py

def bootstrap():
    import json
    
    from education.core import adapter
    from education.core import bus
    from education.core.persons.domain.events import PersonCreated 
    
    TOPIC_EVENTS = {
      'edu.persons.person': PersonCreated,
    }
    
    for message in adapter.subscribe(*TOPIC_EVENTS):
       for message in adapter.subscribe(*TOPIC_EVENTS):
          event = TOPIC_EVENTS[message.topic()](
              **json.loads(message.value())
          )
          bus.handle(event)

bootstrap()

Запуск тестов

Тесты запускаются через tox. В системе должен быть установлен uv.

Для корректного запуска тестов необходимы следующие значения переменных окружения в системе. Вместо <login> и <password> необходимо подставить данные от УЗ БАРС:

UV_INDEX="internal=http://<login>:<password>@nexus.py.bars.group/repository/pypi-all/simple"
UV_DEFAULT_INDEX="https://pypi.org/simple"
UV_INDEX_STRATEGY=unsafe-best-match
# Для docker 29+
TOX_DOCKER_GATEWAY=localhost

Чтобы не менять значения системных переменных, можно создать .env файл c переменными окружения и запускать команды через python-dotenv.

Установка tox с необходимыми зависимостями:

uv tool install tox --with tox-uv --with m3-tox-docker

Или с использованием python-dotenv:

dotenv run uv tool install tox --with tox-uv --with m3-tox-docker

Запуск тестов:

tox

Через python-dotenv:

dotenv run tox

Metadata

Release files for explicit-python-kafka 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for explicit-python-kafka 2.0.0
File Size Uploaded Provenance Actions
explicit_python_kafka-2.0.0.tar.gz 10.6 kB Without provenance Details for explicit_python_kafka-2.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for explicit-python-kafka 2.0.0
File Interpreter ABI Platform Actions
explicit_python_kafka-2.0.0-py3-none-any.whl Python 3 none any Details for explicit_python_kafka-2.0.0-py3-none-any.whl

Total release size: 20.7 kB

Release files / explicit_python_kafka-2.0.0.tar.gz

Download URL explicit_python_kafka-2.0.0.tar.gz
Size 10.6 kB
Tags Source
SHA-256 checksum
How to use checksums
337c12c22a624da97411236e15b0c545f0d2839bc1835abfbce6256f9dc00df0
BLAKE2b-256 checksum
How to use checksums
79a854dc53cf783d62ed7a14756f5b63e874ba5696c366f7e419310e2b3fc69d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.23

Release files / explicit_python_kafka-2.0.0-py3-none-any.whl

Download URL explicit_python_kafka-2.0.0-py3-none-any.whl
Size 10.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
baa6c288a83bca636efb7bc7b2116f567f884f3a7f34903126c867a666777025
BLAKE2b-256 checksum
How to use checksums
a16e3b0ef513b57fe4e3ca85eacffa9367fdab98f15a115a099ae001e66358b9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.23

Security for explicit-python-kafka 2.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page