def async_round_trip(functions: StatefulFunctions, to: InvocationBuilder) -> dict:
    handler = AsyncRequestReplyHandler(functions)

    in_bytes = to.SerializeToString()
    future = handler(in_bytes)
    out_bytes = asyncio.get_event_loop().run_until_complete(future)

    f = FromFunction()
    f.ParseFromString(out_bytes)
    return MessageToDict(f, preserving_proto_field_name=True)
Exemplo n.º 2
0
async def handle(request):
    handler = AsyncRequestReplyHandler(functions)
    request_data = await request.read()
    response_data = await handler(request_data)
    return web.Response(body=response_data,
                        content_type='application/octet-stream')
                        request_id: str,
                        status_code: int,
                        message=None) -> None:
    response = Response(request_id=request_id, status_code=status_code)
    if message:
        out = Any()
        out.Pack(message)
        response.message.CopyFrom(out)
    egress_message = kafka_egress_record(topic="responses",
                                         key=request_id,
                                         value=response)
    context.pack_and_send_egress("ycsb-example/kafka-egress", egress_message)


from aiohttp import web

handler = AsyncRequestReplyHandler(functions)


async def handle(request):
    req = await request.read()
    res = await handler(req)
    return web.Response(body=res, content_type="application/octet-stream")


app = web.Application()
app.add_routes([web.post('/statefun', handle)])

if __name__ == '__main__':
    web.run_app(app, port=80)