Sunday 29 November 2020

Async gRCP server with maximum_concurrent_rpcs limitation raises an exception

I tried to implement gRPC server with gRPC AsyncIO API. I used this example as a sample and tried to define maximum_concurrent_rpcs limitation on server as described in source code documentation in gRPC AsyncIO server source code. Here is my implementation:

import asyncio
from grpc.experimental import aio

import helloworld_pb2
import helloworld_pb2_grpc


class Greeter(helloworld_pb2_grpc.GreeterServicer):

    async def SayHello(self, request, context):
        return helloworld_pb2.HelloReply(message='Hello, %s!' % request.name)


async def serve():
    server = aio.server(maximum_concurrent_rpcs = 10)
    helloworld_pb2_grpc.add_GreeterServicer_to_server(Greeter(), server)
    listen_addr = '[::]:50051'
    server.add_insecure_port(listen_addr)
    logging.info("Starting server on %s", listen_addr)
    await server.start()
    await server.wait_for_termination()


if __name__ == '__main__':
    asyncio.run(serve())

But it raises the following exception:

AttributeError: 'Server' object has no attribute '_server'

My question is, how is it possible to define gRPC AsyncIO server with maximum_concurrent_rpcs limitation.

Note that helloworld_pb2 and helloworld_pb2_grpc are available in this repositroy



from Async gRCP server with maximum_concurrent_rpcs limitation raises an exception

No comments:

Post a Comment