예제 #1
0
def asyncapi_message_for_success_response(base_task_name: str,
                                          title: str = None,
                                          summary: str = None,
                                          payload_dataclass: object = None):
    return asyncapi.Message(name=success_task_name(base_task_name),
                            title=title,
                            summary=summary,
                            payload=payload_dataclass)
예제 #2
0
def asyncapi_message_for_failure_response(
        base_task_name: str,
        title: str = None,
        summary: str = None,
        payload_dataclass: type = SagaErrorPayload):
    return asyncapi.Message(name=failure_task_name(base_task_name),
                            title=title,
                            summary=summary,
                            payload=payload_dataclass)
예제 #3
0
def expected_spec(fake_jsonschema_asdataclass):
    message = asyncapi.Message(
        name='Fake Message',
        title='Faked',
        summary='Faked message',
        content_type='application/json',
        payload=fake_jsonschema_asdataclass.return_value,
    )
    return asyncapi.Specification(
        info=asyncapi.Info(
            title='Fake API',
            version='0.0.1',
            description='Faked API',
        ),
        servers={
            'development':
            asyncapi.Server(
                name='development',
                url='fake.fake',
                protocol=asyncapi.ProtocolType.KAFKA,
                description='Fake Server',
            )
        },
        channels={
            'fake':
            asyncapi.Channel(
                name='fake',
                description='Fake Channel',
                subscribe=asyncapi.Operation(
                    operation_id='fake_operation',
                    message=message,
                ),
                publish=asyncapi.Operation(message=message),
            )
        },
        components=asyncapi.Components(
            messages={'FakeMessage': message},
            schemas={
                'FakePayload': {
                    'type': 'object',
                    'properties': {
                        'faked': {
                            'type': 'integer'
                        }
                    },
                }
            },
        ),
    )
예제 #4
0
@dataclasses.dataclass
class UserUpdatePayload:
    id: str
    name: Optional[str] = None
    age: Optional[int] = None


dev_server = asyncapi.Server(
    url='localhost',
    protocol=asyncapi.ProtocolType.REDIS,
    description='Development Broker Server',
)
message = asyncapi.Message(
    name='userUpdate',
    title='User Update',
    summary='Inform about users updates',
    payload=UserUpdatePayload,
)
user_update_channel = asyncapi.Channel(
    description='Topic for user updates',
    subscribe=asyncapi.Operation(
        operation_id='receive_user_update',
        message=message,
    ),
    publish=asyncapi.Operation(message=message),
)

spec = asyncapi.Specification(
    info=asyncapi.Info(
        title='User API',
        version='1.0.0',
예제 #5
0
    name: str
    quantity: int


@dataclasses.dataclass
class Payload:
    order_id: int
    customer_id: int
    items: List[OrderItem]


@dataclasses.dataclass
class Response:
    ticket_id: int


message = asyncapi.Message(
    name=TASK_NAME,
    title='Create restaurant ticket',
    summary='This command creates ticket so restaurant knows order details. \n'
            'In real world, ticket may be created automatically or after restaurant manager approves it '
            '(confirm that they will be able to cook desired dishes)',
    payload=Payload,
)

success_response = asyncapi_message_for_success_response(
    TASK_NAME,
    title='Ticket ID is returned',
    payload_dataclass=Response
)
예제 #6
0
import dataclasses

import asyncapi
from saga_framework.asyncapi_utils import asyncapi_message_for_success_response

TASK_NAME = 'consumer_service.verify_consumer_details'


@dataclasses.dataclass
class Payload:
    consumer_id: int


message = asyncapi.Message(
    name=TASK_NAME,
    title='Verify consumer details',
    summary='This command makes consumer service verify consumer details.'
            'If consumer is correct, it returns nothing.'
            'If validation fails, it throws an exception',
    payload=Payload,
)

success_response = asyncapi_message_for_success_response(TASK_NAME)
import dataclasses

import asyncapi
from saga_framework.asyncapi_utils import asyncapi_message_for_success_response

TASK_NAME = 'restaurant_service.approve_ticket'


@dataclasses.dataclass
class Payload:
    ticket_id: int


message = asyncapi.Message(
    name=TASK_NAME,
    title='Approve restaurant ticket',
    summary='This command approves previously created restaurant ticket. \n'
    'Returns no response',
    payload=Payload,
)

success_response = asyncapi_message_for_success_response(TASK_NAME)
예제 #8
0
import dataclasses

import asyncapi
from saga_framework.asyncapi_utils import asyncapi_message_for_success_response

TASK_NAME = 'accounting_service.authorize_card'


@dataclasses.dataclass
class Payload:
    card_id: int
    amount: int


@dataclasses.dataclass
class Response:
    transaction_id: int


message = asyncapi.Message(
    name=TASK_NAME,
    title='Authorize previously saved card',
    summary='This command authorizes_money from previously saved card',
    payload=Payload,
)

success_response = asyncapi_message_for_success_response(
    TASK_NAME, title='Transaction ID is returned', payload_dataclass=Response)
예제 #9
0
@dataclass
class TemplateEvent:
    id: str
    payload: ExampleInput
    metadata: EventMetadata


dev_server = asyncapi.Server(
    url='localhost',
    protocol=asyncapi.ProtocolType.REDIS,
    description='Development Broker Server',
)
message = asyncapi.Message(
    name='templateEvent',
    title='Template Event',
    summary='Template Event description',
    payload=TemplateEvent,
)
user_update_channel = asyncapi.Channel(
    description='Topic for template events',
    subscribe=asyncapi.Operation(
        operation_id='receive_template_event',
        message=message,
    ),
    publish=asyncapi.Operation(message=message),
)

api = asyncapi.Specification(
    info=asyncapi.Info(
        title='User API',
        version='1.0.0',
예제 #10
0
import dataclasses

import asyncapi

TASK_NAME = 'restaurant_service.reject_ticket'


@dataclasses.dataclass
class Payload:
    ticket_id: int


message = asyncapi.Message(
    name=TASK_NAME,
    title='Reject restaurant ticket',
    summary='This compensation command rejects already created restaurant ticket. \n'
            'Returns no response',
    payload=Payload,
)