Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deploy gRPC server/client to heroku?

Tags:

I deployed my python gRPC server to Heroku and was wondering how I could test it with a local Python client.

server.py

def serve():
    server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
    icp_pb2_grpc.add_MyServicer_to_server(MyServicer(), server)

    server_port = os.environ.get('PORT', 50051) 
    server.add_insecure_port('[::]:'+ str(server_port))
    server.start()
    print("==== SERVER RUNNING =====")
    try:
        while True:
            time.sleep(_ONE_DAY_IN_SECONDS)
    except KeyboardInterrupt:
        server.stop(0)

if __name__ == '__main__':
    serve()

client.py

def run():
    # Is the channel url correct?
    channel = grpc.insecure_channel('https://www.HEROKUURL.com:50051')
    stub = my_grpc.MyStub(channel)
    file = _get_file_content()
    response = stub.Predict(icp_pb2.MyRequest(file_content=file))
    print("received: " + response.results)

I am using the client from my computer and am not receiving any response from the server. I am able to successfully communicate with the server if it is launched locally. What am I doing wrong?

like image 925
4d11 Avatar asked Dec 06 '17 19:12

4d11


People also ask

What is gRPC used for?

gRPC is a robust open-source RPC (Remote Procedure Call) framework used to build scalable and fast APIs. It allows the client and server applications to communicate transparently and develop connected systems. Many leading tech firms have adopted gRPC, such as Google, Netflix, Square, IBM, Cisco, & Dropbox.


1 Answers

Heroku does not support HTTP 2. On the other hand, GRPC uses a http/2 based transport. I think that's why you can connect it locally but not from Heroku.

like image 198
Sumsuddin Shojib Avatar answered Sep 19 '22 13:09

Sumsuddin Shojib