Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call gRPC from AIOHTTP? #3

Closed
brandomr opened this issue Dec 30, 2020 · 2 comments
Closed

Call gRPC from AIOHTTP? #3

brandomr opened this issue Dec 30, 2020 · 2 comments

Comments

@brandomr
Copy link

This is more of a question really--is it possible to call the gRPC command from within a web request?

For example, I'd like the webview to look like:

    async def get(self) -> web.Response:
        channel = grpc.insecure_channel('0.0.0.0:50051')
        hello_world_stub = HelloWorldServiceStub(channel)
        print("Reaching out to gRPC now...")
        name = "SOME NAME"
        request = HelloRequest()
        request.name = name
        response = hello_world_stub.Hello(request)
        print(response.message)
        return web.Response(text=response.message)

But this endpoint then just hangs. Any suggestions?

@wlwanpan
Copy link
Owner

wlwanpan commented Dec 30, 2020

Hey @brandomr the hanging issue is due to not using the proper grpc adapter for AIO:

    async def get(self) -> web.Response:
        channel = grpc.aio.insecure_channel('localhost:50051') # Note grpc.aio
        hello_world_stub = HelloWorldServiceStub(channel)
        print("Reaching out to gRPC now...")
        name = "SOME NAME"
        request = HelloRequest()
        request.name = name
        response = await hello_world_stub.Hello(request) # Dont forget to await
        return web.Response(text=response.message)

Hope that works for you now, feel free to reopen if not.

@brandomr
Copy link
Author

Thanks, this is helpful and generally speaking your post/repo got me on the right track. Much appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants