Name | explicit-kafka JSON |
Version |
1.1.0
JSON |
| download |
home_page | None |
Summary | Набор компонентов для интеграции explicit с kafka |
upload_time | 2024-09-04 04:53:58 |
maintainer | None |
docs_url | None |
author | BARS Group |
requires_python | None |
license | MIT |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# Explicit-Kafka
## Набор компонентов для интеграции explicit с kafka.
Содержит реализацию адаптера обмена сообщениями через Kafka.
### Пример использования
Настройка адаптера
```python
# 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()
```
Отправка сообщений
```python
# persons/core/persons/services/handlers/events.py
def on_person_created(
event: 'PersonCreated',
messaging_adapter: 'AbstractMessagingAdapter'
):
messaging_adapter.publish('edu.persons.person', event.dump())
```
Подписка на сообщения
```python
# 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()
```
### Запуск тестов
```sh
$ tox
```
Raw data
{
"_id": null,
"home_page": null,
"name": "explicit-kafka",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": null,
"author": "BARS Group",
"author_email": "education_dev@bars-open.ru",
"download_url": "https://files.pythonhosted.org/packages/ec/1c/193c6b2562b880f07717da5ec7dfeae2faa2e943dee3da86085099a2949d/explicit_kafka-1.1.0.tar.gz",
"platform": null,
"description": "# Explicit-Kafka\n## \u041d\u0430\u0431\u043e\u0440 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432 \u0434\u043b\u044f \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u0438 explicit \u0441 kafka.\n\n\u0421\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0430\u0434\u0430\u043f\u0442\u0435\u0440\u0430 \u043e\u0431\u043c\u0435\u043d\u0430 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f\u043c\u0438 \u0447\u0435\u0440\u0435\u0437 Kafka.\n\n### \u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f\n\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u0430\u0434\u0430\u043f\u0442\u0435\u0440\u0430\n```python\n# persons/core/apps.py\nfrom django.apps.config import AppConfig as AppConfigBase\n\n\nclass AppConfig(AppConfigBase):\n\n name = __package__\n \n def _setup_adapter(self):\n from explicit.kafka.adapters.messaging import Adapter\n from explicit.kafka.adapters.messaging import PublishConfig\n from explicit.kafka.adapters.messaging import SubscribeConfig\n\n from persons import core\n \n # \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f \u0430\u0434\u0430\u043f\u0442\u0435\u0440\u0430\n adapter_base_config = {'bootstrap.servers': 'kafka:9092'}\n publish_config = PublishConfig(adapter_base_config)\n subscribe_config = SubscribeConfig(adapter_base_config | {'group.id': f'edu.persons'})\n \n adapter = Adapter(subscribe_config=subscribe_config, publish_config=publish_config)\n core.adapter = adapter\n\n def ready(self):\n self._setup_adapter()\n```\n\u041e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439\n```python\n# persons/core/persons/services/handlers/events.py\n\ndef on_person_created(\n event: 'PersonCreated',\n messaging_adapter: 'AbstractMessagingAdapter'\n):\n messaging_adapter.publish('edu.persons.person', event.dump())\n```\n\n\u041f\u043e\u0434\u043f\u0438\u0441\u043a\u0430 \u043d\u0430 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f\n```python\n# education/entrypoints/eventconsumer.py\n\ndef bootstrap():\n import json\n \n from education.core import adapter\n from education.core import bus\n from education.core.persons.domain.events import PersonCreated \n \n TOPIC_EVENTS = {\n 'edu.persons.person': PersonCreated,\n }\n \n for message in adapter.subscribe(*TOPIC_EVENTS):\n for message in adapter.subscribe(*TOPIC_EVENTS):\n event = TOPIC_EVENTS[message.topic()](\n **json.loads(message.value())\n )\n bus.handle(event)\n\nbootstrap()\n```\n\n### \u0417\u0430\u043f\u0443\u0441\u043a \u0442\u0435\u0441\u0442\u043e\u0432\n```sh\n$ tox\n```\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "\u041d\u0430\u0431\u043e\u0440 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432 \u0434\u043b\u044f \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u0438 explicit \u0441 kafka",
"version": "1.1.0",
"project_urls": null,
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "1e086c0cc041a551420fbebf82e99eea039961d2ec421807d54a1f930efc0e17",
"md5": "95c2a9bd73752738a07dddc8ee9773dc",
"sha256": "f0fe278ef80ff6358c1d25e7a27e046ec7f19347755cd8f183042ea73a368b98"
},
"downloads": -1,
"filename": "explicit_kafka-1.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "95c2a9bd73752738a07dddc8ee9773dc",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 7758,
"upload_time": "2024-09-04T04:53:56",
"upload_time_iso_8601": "2024-09-04T04:53:56.980769Z",
"url": "https://files.pythonhosted.org/packages/1e/08/6c0cc041a551420fbebf82e99eea039961d2ec421807d54a1f930efc0e17/explicit_kafka-1.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "ec1c193c6b2562b880f07717da5ec7dfeae2faa2e943dee3da86085099a2949d",
"md5": "b3831610ccd0ee75867d18728083fe73",
"sha256": "c865bbbda60d5f02400d9d3e9fcdb77e8ce9eac3eff1f8d0bfc4207152f8f0f4"
},
"downloads": -1,
"filename": "explicit_kafka-1.1.0.tar.gz",
"has_sig": false,
"md5_digest": "b3831610ccd0ee75867d18728083fe73",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 7840,
"upload_time": "2024-09-04T04:53:58",
"upload_time_iso_8601": "2024-09-04T04:53:58.506071Z",
"url": "https://files.pythonhosted.org/packages/ec/1c/193c6b2562b880f07717da5ec7dfeae2faa2e943dee3da86085099a2949d/explicit_kafka-1.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-09-04 04:53:58",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "explicit-kafka"
}