Name | explicit-python-kafka JSON |
Version |
1.1.2
JSON |
| download |
home_page | None |
Summary | Набор компонентов для интеграции explicit с kafka |
upload_time | 2024-11-20 14:24:33 |
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-python-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/f7/25/5b5a5f83ebe8f411d8f44c53be0fe9d768f3ccae557dc812f7918e41d51d/explicit_python_kafka-1.1.2.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.2",
"project_urls": null,
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "303665dbddc064d4467eb322598ce27a4bdbba163fcedf37693845851e6fc42c",
"md5": "f757c32ca0dd174a4e94b4d919c5fca0",
"sha256": "012ae7c1bf1c0ed3d05a23d02e787cd7ca58c4427f779ec1b47d71384a88abbc"
},
"downloads": -1,
"filename": "explicit_python_kafka-1.1.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "f757c32ca0dd174a4e94b4d919c5fca0",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 7841,
"upload_time": "2024-11-20T14:24:31",
"upload_time_iso_8601": "2024-11-20T14:24:31.561215Z",
"url": "https://files.pythonhosted.org/packages/30/36/65dbddc064d4467eb322598ce27a4bdbba163fcedf37693845851e6fc42c/explicit_python_kafka-1.1.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "f7255b5a5f83ebe8f411d8f44c53be0fe9d768f3ccae557dc812f7918e41d51d",
"md5": "459b246fe2a0114e223651b2e8556bb8",
"sha256": "58ff4d756f0eac4d0746707c606e0f8fad95431e35cd73aa232a86a3536721c8"
},
"downloads": -1,
"filename": "explicit_python_kafka-1.1.2.tar.gz",
"has_sig": false,
"md5_digest": "459b246fe2a0114e223651b2e8556bb8",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 7837,
"upload_time": "2024-11-20T14:24:33",
"upload_time_iso_8601": "2024-11-20T14:24:33.586449Z",
"url": "https://files.pythonhosted.org/packages/f7/25/5b5a5f83ebe8f411d8f44c53be0fe9d768f3ccae557dc812f7918e41d51d/explicit_python_kafka-1.1.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-20 14:24:33",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "explicit-python-kafka"
}