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.3.tar.gz (28.2 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.3-py3-none-any.whl (35.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: adapter_client-1.0.3.tar.gz
  • Upload date:
  • Size: 28.2 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.3.tar.gz
Algorithm Hash digest
SHA256 fcb9fe671b8aaba02fff96bea5d2750538d1925ffbe61a1bd4a5bfd93676113d
MD5 7cad2cc84bb8e6025d54aef460d044be
BLAKE2b-256 322428ce63c06864b8e0ca33c3a166a5aa0f08a3e8652e35ff192d11cf7eef9f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: adapter_client-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 35.9 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 61a492947ed1099a1434d1b36d9c0efa3bc33c77b317da0e624cadeca2714252
MD5 13aec7a7ef440490c9f787bff1d95955
BLAKE2b-256 642d1a305e88d88220beb8e9783889864f13ef2889cf28e8dc9e754a4d2cf304

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