Набор компонентов для интеграции explicit с kafka
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for explicit_python_kafka-1.1.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 94c63ef3751a4f4b316249f56b827806cf74095fa932bf9c61f2456d3753e162 |
|
MD5 | 3a5b481d58ae403bd0f531ad28f18509 |
|
BLAKE2b-256 | e8444a37a8b3261bf56cdac31b1337128cc8381b13c59df3687fa64a251ddf7c |
Close
Hashes for explicit_python_kafka-1.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6f18e609edee5818c854791d69f0d00e95402847875bab5c415bc8791f252607 |
|
MD5 | 40ee65c88bca746be47d411d61108713 |
|
BLAKE2b-256 | c8c189a7421715402988b8ab5ea887c5d1cba3a635ea0969304824b6eb7c1c1d |