explicit-python-kafka


Nameexplicit-python-kafka JSON
Version 1.1.1 PyPI version JSON
download
home_pageNone
SummaryНабор компонентов для интеграции explicit с kafka
upload_time2024-10-02 11:20:34
maintainerNone
docs_urlNone
authorBARS Group
requires_pythonNone
licenseMIT
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/e8/44/4a37a8b3261bf56cdac31b1337128cc8381b13c59df3687fa64a251ddf7c/explicit_python_kafka-1.1.1.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.1",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c8c189a7421715402988b8ab5ea887c5d1cba3a635ea0969304824b6eb7c1c1d",
                "md5": "40ee65c88bca746be47d411d61108713",
                "sha256": "6f18e609edee5818c854791d69f0d00e95402847875bab5c415bc8791f252607"
            },
            "downloads": -1,
            "filename": "explicit_python_kafka-1.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "40ee65c88bca746be47d411d61108713",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 7841,
            "upload_time": "2024-10-02T11:20:33",
            "upload_time_iso_8601": "2024-10-02T11:20:33.061478Z",
            "url": "https://files.pythonhosted.org/packages/c8/c1/89a7421715402988b8ab5ea887c5d1cba3a635ea0969304824b6eb7c1c1d/explicit_python_kafka-1.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e8444a37a8b3261bf56cdac31b1337128cc8381b13c59df3687fa64a251ddf7c",
                "md5": "3a5b481d58ae403bd0f531ad28f18509",
                "sha256": "94c63ef3751a4f4b316249f56b827806cf74095fa932bf9c61f2456d3753e162"
            },
            "downloads": -1,
            "filename": "explicit_python_kafka-1.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "3a5b481d58ae403bd0f531ad28f18509",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 7811,
            "upload_time": "2024-10-02T11:20:34",
            "upload_time_iso_8601": "2024-10-02T11:20:34.637953Z",
            "url": "https://files.pythonhosted.org/packages/e8/44/4a37a8b3261bf56cdac31b1337128cc8381b13c59df3687fa64a251ddf7c/explicit_python_kafka-1.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-02 11:20:34",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "explicit-python-kafka"
}
        
Elapsed time: 0.45558s