Набор компонентов для интеграции 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
File details
Details for the file explicit_python_kafka-1.1.2.tar.gz
.
File metadata
- Download URL: explicit_python_kafka-1.1.2.tar.gz
- Upload date:
- Size: 7.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 58ff4d756f0eac4d0746707c606e0f8fad95431e35cd73aa232a86a3536721c8 |
|
MD5 | 459b246fe2a0114e223651b2e8556bb8 |
|
BLAKE2b-256 | f7255b5a5f83ebe8f411d8f44c53be0fe9d768f3ccae557dc812f7918e41d51d |
File details
Details for the file explicit_python_kafka-1.1.2-py3-none-any.whl
.
File metadata
- Download URL: explicit_python_kafka-1.1.2-py3-none-any.whl
- Upload date:
- Size: 7.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 012ae7c1bf1c0ed3d05a23d02e787cd7ca58c4427f779ec1b47d71384a88abbc |
|
MD5 | f757c32ca0dd174a4e94b4d919c5fca0 |
|
BLAKE2b-256 | 303665dbddc064d4467eb322598ce27a4bdbba163fcedf37693845851e6fc42c |