예제 #1
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'
                        }
                    },
                }
            },
        ),
    )
예제 #2
0
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',
        description='API to manage users',
    ),
    servers={'development': dev_server},
    channels={'user/update': user_update_channel},
    components=asyncapi.Components(messages={'UserUpdate': message}),
)
예제 #3
0
    create_ticket_message, reject_ticket_message, approve_ticket_message

"""
IMPORTANT!
We do NOT document error responses such as `restaurant_service.create_ticket.response.failure`
We assume that they have standard format (see SagaErrorPayload dataclass) 
"""
channels = dict([
    message_to_channel(create_ticket_message.message,
                       create_ticket_message.success_response),
    message_to_channel(reject_ticket_message.message),  # compensation step has no resppnse
    message_to_channel(approve_ticket_message.message,
                       approve_ticket_message.success_response),
])

spec = asyncapi.Specification(
    info=asyncapi.Info(
        title='Restaurant service', version='1.0.0',
        description=f'Takes command messages from "{restaurant_service_messaging.COMMANDS_QUEUE}" queue',
    ),
    channels=channels,
    components=asyncapi_components_from_asyncapi_channels(channels.values()),
    servers=fake_asyncapi_servers,
)

if __name__ == '__main__':
    import yaml
    from asyncapi.docs import spec_asjson

    print(yaml.dump(spec_asjson(spec)))
예제 #4
0
from accounting_service.app_common.messaging import accounting_service_messaging
from accounting_service.app_common.messaging.accounting_service_messaging import \
    authorize_card_message

"""
IMPORTANT!
We do NOT document error responses such as `restaurant_service.create_ticket.response.failure`
We assume that they have standard format (see SagaErrorPayload dataclass) 
"""
channels = dict([
    message_to_channel(authorize_card_message.message,
                       authorize_card_message.success_response)
])

spec = asyncapi.Specification(
    info=asyncapi.Info(
        title='Consumer service', version='1.0.0',
        description=f'Takes command messages from "{accounting_service_messaging.COMMANDS_QUEUE}" queue',
    ),
    channels=channels,
    components=asyncapi_components_from_asyncapi_channels(channels.values()),
    servers=fake_asyncapi_servers,
)

if __name__ == '__main__':
    import yaml
    from asyncapi.docs import spec_asjson

    print(yaml.dump(spec_asjson(spec)))
예제 #5
0
    # authorize card step
    message_to_channel_publish_first(authorize_card_message.message,
                                     authorize_card_message.success_response),

    # approve restaurant ticket step
    message_to_channel_publish_first(approve_ticket_message.message,
                                     approve_ticket_message.success_response),
])

spec = asyncapi.Specification(
    info=asyncapi.Info(
        title='Order service',
        version='1.0.0',
        description=f'Orchestrates CreateOrder saga. \n'
        f' Publishes command messages to '
        f'"{consumer_service_messaging.COMMANDS_QUEUE}", '
        f'"{consumer_service_messaging.COMMANDS_QUEUE}", '
        f'"{accounting_service_messaging.COMMANDS_QUEUE}" '
        f' queues',
    ),
    channels=channels,
    # all messages met in specification
    components=asyncapi_components_from_asyncapi_channels(channels.values()),
    servers=fake_asyncapi_servers,
)

if __name__ == '__main__':
    import yaml
    from asyncapi.docs import spec_asjson

    print(yaml.dump(spec_asjson(spec)))