Skip to main content

Клиент для взаимодействия со СМЭВ3 посредством Адаптера

Project description

Клиент для взаимодействия со СМЭВ3 посредством Адаптера

Подключение

settings:

INSTALLED_APPS = [
    'adapter_client'
]

services:

from adapter_client.adapters.smev.adapter import adapter
from adapter_client.adapters.smev.services.base import AbstractService
from adapter_client.core.domain.model import Message


class ROGDINFService(AbstractService):
    """
    Сервис обрабатывающий сообщения со сведениями о рождении.
    """
    message_type = 'urn://x-artefacts-zags-rogdinf/root/112-51/4.0.1'

    def process_message(self, message: Message):
		# сообщение на которое получен ответ
		reply_to = message.reply.to
        ...

class ApplicationRequestService(AbstractService):
    """
    Сервис обрабатывающий запросы на зачисление (в качестве поставщика).
    """
    message_type = (
        'http://epgu.gosuslugi.ru/concentrator/kindergarten/3.2.1'
    )
    def process_message(self, message: Message):
        # обрабатываем сообщение-запрос
        ...

        # отправляем ответ на запрос
        adapter.send(
            Message(
                # необходимо указать что сообщение является ответом
                reply_to=message,
                # остальные поля сообщения
                ...
            )
        )

apps:

from django.apps.config import AppConfig as AppConfigBase

class AppConfig(AppConfigBase):

    name = __package__

    def ready(self):
        self._init_adapter_client()
        self._register_services()

    def _init_adapter_client(self):
        from adapter_client.config import ProductConfig, set_config
        from tasks import BaseTask

        set_config(ProductConfig(async_task_base=BaseTask))
    
    def _register_services(self):
    from adapter_client.adapters.smev.adapter import adapter
    from .services import ApplicationRequestService, ROGDINFService
    
    adapter.register_service(ApplicationRequestService(), ROGDINFService())

Запуск тестов

$ tox

API

Передача сообщения

from adapter_client.adapters.smev.adapter import adapter
from adapter_client.core.domain.model import Message

message = Message(
    message_type='Foo',
    body='<foo>bar</foo>',
    attachments=['http://domain.com/attach1', 'http://domain.com/attach2'],
    test=True
)

adapter.send(message)

Дальнейшая обработка сообщений производится Celery в фоновом режиме.

Получение ответа на сообщение

Ответы на отправленные сообщения собираются периодической задачей и передаются зарегистрированным сервисам.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

adapter_client-1.0.2.tar.gz (28.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

adapter_client-1.0.2-py3-none-any.whl (35.1 kB view details)

Uploaded Python 3

File details

Details for the file adapter_client-1.0.2.tar.gz.

File metadata

  • Download URL: adapter_client-1.0.2.tar.gz
  • Upload date:
  • Size: 28.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.7

File hashes

Hashes for adapter_client-1.0.2.tar.gz
Algorithm Hash digest
SHA256 56b3c97b833d6cea8bb102d2d2957047ce7a2968d3361fab7caa545c76fc2513
MD5 4a02f2f982f2dea47a04ea443a4b2dd5
BLAKE2b-256 d0bc391b15411f2afa3a2158f15871df59fe90485520a89585dbcac26b35fe2d

See more details on using hashes here.

File details

Details for the file adapter_client-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: adapter_client-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 35.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.7

File hashes

Hashes for adapter_client-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 65c41890b5428dbb599ddd7fb8e4a5fe25c451042266bafc13842e95c12a7a7a
MD5 849590472531b8194fabff7391515ec7
BLAKE2b-256 f7ede24bc41c8475122bf9053833ad39a66e0862f5b086727c686f0f742b6d74

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page