Набор компонентов для интеграции 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
explicit-kafka-1.0.0.tar.gz
(6.2 kB
view hashes)
Built Distribution
Close
Hashes for explicit_kafka-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5b7bc2e7ede0f4e8e2e541ac006d579fdcf8ce779757a247802108aad458eda0 |
|
MD5 | ed62329415a2ce39cafe1bff23aebfac |
|
BLAKE2b-256 | 59f02f73fd19057409ab47f46de7d06a9ca2e9b049b2e0320e95506aafcf6c66 |